X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fseekat;a=blobdiff_plain;f=tests%2FCacheTest.php;fp=tests%2FCacheTest.php;h=62632b433ec1c335c69e338c8cbbceff75da1223;hp=ddf7f545c59340c26363ec915fbcfe05208b0a1c;hb=654d736df2c46ec2520f73e9089d06a44f2b9c50;hpb=2121556150be871684b5046af7cf250b8219128d diff --git a/tests/CacheTest.php b/tests/CacheTest.php index ddf7f54..62632b4 100644 --- a/tests/CacheTest.php +++ b/tests/CacheTest.php @@ -5,30 +5,22 @@ class CacheTest extends BaseTest use ConsumePromise; use AssertSuccess; - /** - * @var seekat\API\Call\Cache\Service - */ - private $cache; - - function setUp() : void { - $this->cache = new seekat\API\Call\Cache\Service\Hollow; - } - /** * @group testdox * @dataProvider provideAPI */ function testCachesSuccessiveCalls($api) { - $m6w6 = $this->assertSuccess($api->users->m6w6, null, null, $this->cache); - $data = $this->cache->getStorage(); - $m6w6_ = $this->assertSuccess($api->users->m6w6, null, null, $this->cache); + $api->getCache()->clear(); + $m6w6 = $this->assertSuccess($api->users->m6w6); + $data = $api->getCache()->getStorage(); + $m6w6_ = $this->assertSuccess($api->users->m6w6); $this->assertEquals("m6w6", $m6w6->login); $this->assertEquals("m6w6", $m6w6_->login); $this->assertIsArray($data); $this->assertCount(1, $data); - $this->assertEquals($data, $this->cache->getStorage()); + $this->assertEquals($data, $api->getCache()->getStorage()); } /** @@ -36,6 +28,25 @@ class CacheTest extends BaseTest * @dataProvider provideAPI */ function testRefreshesStaleCacheEntries($api) { - $this->markTestIncomplete("TODO"); + $api->getCache()->clear(); + $m6w6 = $this->assertSuccess($api->users->m6w6); + + $data = $api->getCache()->getStorage(); + /* @var \http\Header $resp */ + $resp = current($data); + $resp->setHeader("X-Cache-Time", null); + $resp->setHeader("Cache-Control", null); + $resp->setHeader("Expires", 0); + + $m6w6_ = $this->assertSuccess($api->users->m6w6); + + $this->assertEquals("m6w6", $m6w6->login); + $this->assertEquals("m6w6", $m6w6_->login); + + $this->assertIsArray($data); + $this->assertCount(1, $data); + $this->assertEquals($data, $api->getCache()->getStorage()); + + $this->assertIsNumeric($resp->getHeader("X-Cache-Time")); } }