/** * @depends testDefaultBehavior */ public function testResolveWithBasePath() { $this->cacheManager->expects($this->atLeastOnce())->method('generateUrl')->will($this->returnValue(str_replace('/', DIRECTORY_SEPARATOR, '/sandbox/app_dev.php/media/cache/thumbnail/cats.jpeg'))); $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request'); $request->expects($this->atLeastOnce())->method('getBaseUrl')->will($this->returnValue(str_replace('/', DIRECTORY_SEPARATOR, '/sandbox/app_dev.php'))); // Resolve the requested image for the given filter. $targetPath = $this->resolver->resolve($request, 'cats.jpeg', 'thumbnail'); // The realpath() is important for filesystems that are virtual in some way (encrypted, different mount options, ..) $this->assertEquals(str_replace('/', DIRECTORY_SEPARATOR, realpath($this->cacheDir) . '/thumbnail/cats.jpeg'), $targetPath, '->resolve() correctly converts the requested file into target path within webRoot.'); $this->assertFalse(file_exists($targetPath), '->resolve() does not create the file within the target path.'); // Store the cached version of that image. $content = file_get_contents($this->dataRoot . '/cats.jpeg'); $response = new Response($content); $this->resolver->store($response, $targetPath, 'thumbnail'); $this->assertEquals(201, $response->getStatusCode(), '->store() alters the HTTP response code to "201 - Created".'); $this->assertTrue(file_exists($targetPath), '->store() creates the cached image file to be served.'); $this->assertEquals($content, file_get_contents($targetPath), '->store() writes the content of the original Response into the cache file.'); // Remove the cached image. $this->assertTrue($this->resolver->remove($targetPath, 'thumbnail'), '->remove() reports removal of cached image file correctly.'); $this->assertFalse(file_exists($targetPath), '->remove() actually removes the cached file from the filesystem.'); }
public function testRemoveCacheForSomeFiltersOnRemove() { $filesystemMock = $this->createFilesystemMock(); $filesystemMock->expects($this->once())->method('remove')->with(array('/aWebRoot/aCachePrefix/aFilterOne', '/aWebRoot/aCachePrefix/aFilterTwo')); $resolver = new WebPathResolver($filesystemMock, new RequestContext(), '/aWebRoot', 'aCachePrefix'); $resolver->remove(array(), array('aFilterOne', 'aFilterTwo')); }