diff --git a/core/lib/Thelia/Tests/Command/CacheClearTest.php b/core/lib/Thelia/Tests/Command/CacheClearTest.php new file mode 100644 index 000000000..019414b02 --- /dev/null +++ b/core/lib/Thelia/Tests/Command/CacheClearTest.php @@ -0,0 +1,107 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Tests\Command; + +use Symfony\Component\Console\Tester\CommandTester; +use Thelia\Core\Application; +use Thelia\Command\CacheClear; + +use Symfony\Component\Filesystem\Filesystem; + +class CacheClearTest extends \PHPUnit_Framework_TestCase +{ + + public $cache_dir; + + public function setUp() + { + $this->cache_dir = THELIA_ROOT . "cache/test"; + + $fs = new Filesystem(); + + $fs->mkdir($this->cache_dir); + } + + public function testCacheClear() + { + $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() + { + $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" + )); + } + + public function getKernel() + { + $kernel = $this->getMock("Symfony\Component\HttpKernel\KernelInterface"); + + return $kernel; + } + + public function getContainer() + { + $container = new \Symfony\Component\DependencyInjection\ContainerBuilder(); + + $container->setParameter("kernel.cache_dir", $this->cache_dir); + + return $container; + } + +} \ No newline at end of file