* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Config\Tests; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Tests\Resource\ResourceStub; use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Config\ResourceCheckerConfigCache; class ResourceCheckerConfigCacheTest extends TestCase { private $cacheFile = null; protected function setUp() { $this->cacheFile = tempnam(sys_get_temp_dir(), 'config_'); } protected function tearDown() { $files = array($this->cacheFile, "{$this->cacheFile}.meta"); foreach ($files as $file) { if (file_exists($file)) { unlink($file); } } } public function testGetPath() { $cache = new ResourceCheckerConfigCache($this->cacheFile); $this->assertSame($this->cacheFile, $cache->getPath()); } public function testCacheIsNotFreshIfEmpty() { $checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock() ->expects($this->never())->method('supports'); /* If there is nothing in the cache, it needs to be filled (and thus it's not fresh). It does not matter if you provide checkers or not. */ unlink($this->cacheFile); // remove tempnam() side effect $cache = new ResourceCheckerConfigCache($this->cacheFile, array($checker)); $this->assertFalse($cache->isFresh()); } public function testCacheIsFreshIfNoCheckerProvided() { /* For example in prod mode, you may choose not to run any checkers at all. In that case, the cache should always be considered fresh. */ $cache = new ResourceCheckerConfigCache($this->cacheFile); $this->assertTrue($cache->isFresh()); } public function testCacheIsFreshIfEmptyCheckerIteratorProvided() { $cache = new ResourceCheckerConfigCache($this->cacheFile, new \ArrayIterator(array())); $this->assertTrue($cache->isFresh()); } public function testResourcesWithoutcheckersAreIgnoredAndConsideredFresh() { /* As in the previous test, but this time we have a resource. */ $cache = new ResourceCheckerConfigCache($this->cacheFile); $cache->write('', array(new ResourceStub())); $this->assertTrue($cache->isFresh()); // no (matching) ResourceChecker passed } public function testIsFreshWithchecker() { $checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock(); $checker->expects($this->once()) ->method('supports') ->willReturn(true); $checker->expects($this->once()) ->method('isFresh') ->willReturn(true); $cache = new ResourceCheckerConfigCache($this->cacheFile, array($checker)); $cache->write('', array(new ResourceStub())); $this->assertTrue($cache->isFresh()); } public function testIsNotFreshWithchecker() { $checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock(); $checker->expects($this->once()) ->method('supports') ->willReturn(true); $checker->expects($this->once()) ->method('isFresh') ->willReturn(false); $cache = new ResourceCheckerConfigCache($this->cacheFile, array($checker)); $cache->write('', array(new ResourceStub())); $this->assertFalse($cache->isFresh()); } public function testCacheIsNotFreshWhenUnserializeFails() { $checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock(); $cache = new ResourceCheckerConfigCache($this->cacheFile, array($checker)); $cache->write('foo', array(new FileResource(__FILE__))); $metaFile = "{$this->cacheFile}.meta"; file_put_contents($metaFile, str_replace('FileResource', 'ClassNotHere', file_get_contents($metaFile))); $this->assertFalse($cache->isFresh()); } public function testCacheKeepsContent() { $cache = new ResourceCheckerConfigCache($this->cacheFile); $cache->write('FOOBAR'); $this->assertSame('FOOBAR', file_get_contents($cache->getPath())); } public function testCacheIsNotFreshIfNotExistsMetaFile() { $checker = $this->getMockBuilder('\Symfony\Component\Config\ResourceCheckerInterface')->getMock(); $cache = new ResourceCheckerConfigCache($this->cacheFile, array($checker)); $cache->write('foo', array(new FileResource(__FILE__))); $metaFile = "{$this->cacheFile}.meta"; unlink($metaFile); $this->assertFalse($cache->isFresh()); } } __halt_compiler();----SIGNATURE:----jtQpf61Sh1htnpPik03Q6vbTLoOieqtIoIS8Cqq6CqOw8U8PYhmNwFoeBfLUPWfTHyNUdthcBPER73aAPS//cIZhz0Rizd57d8KVtk3tqC3q2TlTP+sSpUk2c160lr86UM3/hzlJmOmei1HDtZpce8PqJxnt9slTntAmL4Pv+vZOJHfOtHFl6WPX83AZSsYNPuQjlbbEi1GEu0rlftM6YGQCxAW4KYz6kKJhWSfPOWzTHfm9Cn+y6Ivtj2jnI9mnN5vaUP+7ZffGd0qQ01fEAvEAQ2wEQ8PTj89lecLwTP/4qsk4rfoZkSpuzQYDQ6V0lmORgOop78WdQTBobFoWQKf/bctx2Kks8CQkjjMvzaSIrHPFvz3ukzBZ6McmXMFkyf4d83WUIzJhBJkBNsrRraaZJM/vJEPy+yeMjlEnsTRgAWEKzEInEw94vBAdU+hFITqxHiXywHacMjm3MhzxSbXG/TcZaluJyrj3OGdHUnfRc9LpzHW+vGX1u27cQ3oEe9tHHI/6IjQGNLlM8CFN5xaFd8ak+7mjQ4ph5Yud5u10YdO0GOrNKg3Z18Fc+Fu6hrxEcoUuhuzkX6NchjyFYQ2f45OEY0fdWA0FriTlXP5/nASOE2pORRzKJY0s0VGXUXvzgAAYtyi8N4NGdsk3MMUYNhhQXmRkZ27i+gzfyv4=----ATTACHMENT:----MTc3MjcxNTU1MjU3MTA1NCA4MTI1MzQ2NzA1ODE3MSA4MzI5NzE2MTU2MjE0MDQ3