Store transformed images in the cache
public storeInCache ( Imbo\EventManager\EventInterface $event ) | ||
$event | Imbo\EventManager\EventInterface | The current event |
/** * @covers Imbo\EventListener\ImageTransformationCache::storeInCache * @covers Imbo\EventListener\ImageTransformationCache::getCacheDir * @covers Imbo\EventListener\ImageTransformationCache::getCacheKey * @covers Imbo\EventListener\ImageTransformationCache::getCacheFilePath */ public function testStoresImageInCache() { $image = $this->getMock('Imbo\\Model\\Image'); $this->response->expects($this->once())->method('getModel')->will($this->returnValue($this->getMock('Imbo\\Model\\Image'))); $this->requestHeaders->expects($this->once())->method('get')->with('Accept', '*/*')->will($this->returnValue('*/*')); $cacheFile = 'vfs://cacheDir/p/u/b/publicKey/7/b/f/7bf2e67f09de203da740a86cd37bbe8d/5/a/a/5aa83f9df03e31b07c97299b927c6fd7'; $this->assertFalse(is_file($cacheFile)); $this->listener->storeInCache($this->event); $this->assertTrue(is_file($cacheFile)); $data = unserialize(file_get_contents($cacheFile)); $this->assertEquals($image, $data['image']); $this->assertEquals($this->responseHeaders, $data['headers']); }
/** * @covers Imbo\EventListener\ImageTransformationCache::storeInCache * @covers Imbo\EventListener\ImageTransformationCache::getCacheDir * @covers Imbo\EventListener\ImageTransformationCache::getCacheKey * @covers Imbo\EventListener\ImageTransformationCache::getCacheFilePath */ public function testDoesNotStoreIfCachedVersionAlreadyExists() { // Reusing the same logic as this test $this->testChangesTheImageInstanceOnCacheHit(); $this->response->expects($this->once())->method('getModel')->will($this->returnValue($this->getMock('Imbo\\Model\\Image'))); // Overwrite cached file $dir = 'vfs://cacheDir/u/s/e/user/7/b/f/7bf2e67f09de203da740a86cd37bbe8d/b/c/6'; $file = 'bc6ffe312a5741a5705afe8639c08835'; $fullPath = $dir . '/' . $file; file_put_contents($fullPath, 'foobar'); // Since we hit a cached version earlier, we shouldn't overwrite the cached file $this->listener->storeInCache($this->event); $this->assertEquals('foobar', file_get_contents($fullPath)); }