*/ class CacheClearTest extends ContainerAwareTestCase { public $cache_dir; public function setUp() { $this->cache_dir = THELIA_CACHE_DIR . 'test_cache'; $fs = new Filesystem(); $fs->mkdir($this->cache_dir); $fs->mkdir(THELIA_WEB_DIR . "/assets"); } public function testCacheClear() { // Fails on windows - do not execute this test on windows if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { $application = new Application($this->getKernel()); $cacheClear = new CacheClear(); $cacheClear->setContainer($this->getContainer()); $application->add($cacheClear); $command = $application->find("cache:clear"); $commandTester = new CommandTester($command); $commandTester->execute(array( "command" => $command->getName(), "--env" => "test" )); $fs = new Filesystem(); $this->assertFalse($fs->exists($this->cache_dir)); } } /** * @expectedException \RuntimeException */ public function testCacheClearWithoutWritePermission() { // Fails on windows - mock this test on windows if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { $fs = new Filesystem(); $fs->chmod($this->cache_dir, 0100); $application = new Application($this->getKernel()); $cacheClear = new CacheClear(); $cacheClear->setContainer($this->getContainer()); $application->add($cacheClear); $command = $application->find("cache:clear"); $commandTester = new CommandTester($command); $commandTester->execute(array( "command" => $command->getName(), "--env" => "test" )); } else { throw new \RuntimeException(""); } } /** * Use this method to build the container with the services that you need. * @param ContainerBuilder $container */ protected function buildContainer(ContainerBuilder $container) { $eventDispatcher = new EventDispatcher(); $eventDispatcher->addSubscriber(new Cache(new ArrayAdapter())); $container->set("event_dispatcher", $eventDispatcher); $container->setParameter("kernel.cache_dir", $this->cache_dir); } }