|
@@ -42,17 +42,17 @@ class StoreTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
|
public function testReadsAnEmptyArrayWithReadWhenNothingCachedAtKey()
|
|
|
{
|
|
|
- $this->assertEmpty($this->store->getMetadata('/nothing'));
|
|
|
+ $this->assertEmpty($this->getStoreMetadata('/nothing'));
|
|
|
}
|
|
|
|
|
|
public function testRemovesEntriesForKeyWithPurge()
|
|
|
{
|
|
|
$request = Request::create('/foo');
|
|
|
$this->store->write($request, new Response('foo'));
|
|
|
- $this->assertNotEmpty($this->store->getMetadata($this->store->getCacheKey($request)));
|
|
|
+ $this->assertNotEmpty($this->getStoreMetadata($request));
|
|
|
|
|
|
$this->assertTrue($this->store->purge('/foo'));
|
|
|
- $this->assertEmpty($this->store->getMetadata($this->store->getCacheKey($request)));
|
|
|
+ $this->assertEmpty($this->getStoreMetadata($request));
|
|
|
|
|
|
$this->assertFalse($this->store->purge('/bar'));
|
|
|
}
|
|
@@ -61,13 +61,13 @@ class StoreTest extends \PHPUnit_Framework_TestCase
|
|
|
{
|
|
|
$cacheKey = $this->storeSimpleEntry();
|
|
|
|
|
|
- $this->assertNotEmpty($this->store->getMetadata($cacheKey));
|
|
|
+ $this->assertNotEmpty($this->getStoreMetadata($cacheKey));
|
|
|
}
|
|
|
|
|
|
public function testSetsTheXContentDigestResponseHeaderBeforeStoring()
|
|
|
{
|
|
|
$cacheKey = $this->storeSimpleEntry();
|
|
|
- $entries = $this->store->getMetadata($cacheKey);
|
|
|
+ $entries = $this->getStoreMetadata($cacheKey);
|
|
|
list ($req, $res) = $entries[0];
|
|
|
|
|
|
$this->assertEquals('ena94a8fe5ccb19ba61c4c0873d391e987982fbbd3', $res['x-content-digest'][0]);
|
|
@@ -103,7 +103,7 @@ class StoreTest extends \PHPUnit_Framework_TestCase
|
|
|
{
|
|
|
$this->storeSimpleEntry();
|
|
|
$this->assertNotNull($this->response->headers->get('X-Content-Digest'));
|
|
|
- $path = $this->store->getPath($this->response->headers->get('X-Content-Digest'));
|
|
|
+ $path = $this->getStorePath($this->response->headers->get('X-Content-Digest'));
|
|
|
@unlink($path);
|
|
|
$this->assertNull($this->store->lookup($this->request));
|
|
|
}
|
|
@@ -113,14 +113,14 @@ class StoreTest extends \PHPUnit_Framework_TestCase
|
|
|
$this->storeSimpleEntry();
|
|
|
$response = $this->store->lookup($this->request);
|
|
|
|
|
|
- $this->assertEquals($response->headers->all(), array_merge(array('content-length' => 4, 'x-body-file' => array($this->store->getPath($response->headers->get('X-Content-Digest')))), $this->response->headers->all()));
|
|
|
+ $this->assertEquals($response->headers->all(), array_merge(array('content-length' => 4, 'x-body-file' => array($this->getStorePath($response->headers->get('X-Content-Digest')))), $this->response->headers->all()));
|
|
|
}
|
|
|
|
|
|
public function testRestoresResponseContentFromEntityStoreWithLookup()
|
|
|
{
|
|
|
$this->storeSimpleEntry();
|
|
|
$response = $this->store->lookup($this->request);
|
|
|
- $this->assertEquals($this->store->getPath('en'.sha1('test')), $response->getContent());
|
|
|
+ $this->assertEquals($this->getStorePath('en'.sha1('test')), $response->getContent());
|
|
|
}
|
|
|
|
|
|
public function testInvalidatesMetaAndEntityStoreEntriesWithInvalidate()
|
|
@@ -163,11 +163,11 @@ class StoreTest extends \PHPUnit_Framework_TestCase
|
|
|
$res3 = new Response('test 3', 200, array('Vary' => 'Foo Bar'));
|
|
|
$this->store->write($req3, $res3);
|
|
|
|
|
|
- $this->assertEquals($this->store->getPath('en'.sha1('test 3')), $this->store->lookup($req3)->getContent());
|
|
|
- $this->assertEquals($this->store->getPath('en'.sha1('test 2')), $this->store->lookup($req2)->getContent());
|
|
|
- $this->assertEquals($this->store->getPath('en'.sha1('test 1')), $this->store->lookup($req1)->getContent());
|
|
|
+ $this->assertEquals($this->getStorePath('en'.sha1('test 3')), $this->store->lookup($req3)->getContent());
|
|
|
+ $this->assertEquals($this->getStorePath('en'.sha1('test 2')), $this->store->lookup($req2)->getContent());
|
|
|
+ $this->assertEquals($this->getStorePath('en'.sha1('test 1')), $this->store->lookup($req1)->getContent());
|
|
|
|
|
|
- $this->assertEquals(3, count($this->store->getMetadata($key)));
|
|
|
+ $this->assertEquals(3, count($this->getStoreMetadata($key)));
|
|
|
}
|
|
|
|
|
|
public function testOverwritesNonVaryingResponseWithStore()
|
|
@@ -175,19 +175,19 @@ class StoreTest extends \PHPUnit_Framework_TestCase
|
|
|
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
|
|
|
$res1 = new Response('test 1', 200, array('Vary' => 'Foo Bar'));
|
|
|
$key = $this->store->write($req1, $res1);
|
|
|
- $this->assertEquals($this->store->getPath('en'.sha1('test 1')), $this->store->lookup($req1)->getContent());
|
|
|
+ $this->assertEquals($this->getStorePath('en'.sha1('test 1')), $this->store->lookup($req1)->getContent());
|
|
|
|
|
|
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam'));
|
|
|
$res2 = new Response('test 2', 200, array('Vary' => 'Foo Bar'));
|
|
|
$this->store->write($req2, $res2);
|
|
|
- $this->assertEquals($this->store->getPath('en'.sha1('test 2')), $this->store->lookup($req2)->getContent());
|
|
|
+ $this->assertEquals($this->getStorePath('en'.sha1('test 2')), $this->store->lookup($req2)->getContent());
|
|
|
|
|
|
$req3 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
|
|
|
$res3 = new Response('test 3', 200, array('Vary' => 'Foo Bar'));
|
|
|
$key = $this->store->write($req3, $res3);
|
|
|
- $this->assertEquals($this->store->getPath('en'.sha1('test 3')), $this->store->lookup($req3)->getContent());
|
|
|
+ $this->assertEquals($this->getStorePath('en'.sha1('test 3')), $this->store->lookup($req3)->getContent());
|
|
|
|
|
|
- $this->assertEquals(2, count($this->store->getMetadata($key)));
|
|
|
+ $this->assertEquals(2, count($this->getStoreMetadata($key)));
|
|
|
}
|
|
|
|
|
|
protected function storeSimpleEntry($path = null, $headers = array())
|
|
@@ -201,4 +201,28 @@ class StoreTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
|
return $this->store->write($this->request, $this->response);
|
|
|
}
|
|
|
+
|
|
|
+ protected function getStoreMetadata($key)
|
|
|
+ {
|
|
|
+ $r = new \ReflectionObject($this->store);
|
|
|
+ $m = $r->getMethod('getMetadata');
|
|
|
+ $m->setAccessible(true);
|
|
|
+
|
|
|
+ if ($key instanceof Request) {
|
|
|
+ $m1 = $r->getMethod('getCacheKey');
|
|
|
+ $m1->setAccessible(true);
|
|
|
+ $key = $m1->invoke($this->store, $key);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $m->invoke($this->store, $key);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getStorePath($key)
|
|
|
+ {
|
|
|
+ $r = new \ReflectionObject($this->store);
|
|
|
+ $m = $r->getMethod('getPath');
|
|
|
+ $m->setAccessible(true);
|
|
|
+
|
|
|
+ return $m->invoke($this->store, $key);
|
|
|
+ }
|
|
|
}
|