From 03812398815d2c37472c74571e9e279fc743fdb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81ro=CC=82me=20Billiras?= Date: Tue, 10 Jun 2014 10:37:48 +0200 Subject: [PATCH] Add refresh command tests --- .../Command/ModuleRefreshCommandTest.php | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php diff --git a/core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php b/core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php new file mode 100644 index 000000000..95a5f5b37 --- /dev/null +++ b/core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php @@ -0,0 +1,105 @@ + + * + * Date: 2014-06-06 + * Time: 17:29 + */ +class ModuleRefreshCommandTest extends PHPUnit_Framework_TestCase +{ + /** + * Test ModuleRefreshCommand + */ + public function testModuleRefreshCommand() + { + $moduleManagement = new ModuleManagement; + $moduleManagement->updateModules(); + + $module = ModuleQuery::create()->orderByPosition(Criteria::DESC)->findOne(); + + if ($module !== null) { + $module->delete(); + + $application = new Application($this->getKernel()); + + $moduleRefresh = new ModuleRefreshCommand; + $moduleRefresh->setContainer($this->getContainer()); + + $application->add($moduleRefresh); + + $command = $application->find('module:refresh'); + $commandTester = new CommandTester($command); + $commandTester->execute([ + 'command' => $command->getName() + ]); + + $expected = $module; + $actual = ModuleQuery::create()->orderByPosition(Criteria::DESC)->findOne(); + + $this->assertEquals($expected->getCode(), $actual->getCode(), 'Last module code must be same after deleting this one and calling module:refresh'); + $this->assertEquals($expected->getType(), $actual->getType(), 'Last module type must be same after deleting this one and calling module:refresh'); + $this->assertEquals($expected->getFullNamespace(), $actual->getFullNamespace(), 'Last module namespace must be same after deleting this one and calling module:refresh'); + + // Restore activation status + $actual + ->setActivate($expected->getActivate()) + ->save(); + + } else { + $this->markTestIncomplete( + 'This test cannot be complete without at least one module' + ); + } + } + + /** + * Get HttpKernel mock + * + * @return Kernel Not really a Kernel but the mocked one + */ + public function getKernel() + { + $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface'); + + return $kernel; + } + + /** + * Get new ContainerBuilder + * + * @return ContainerBuilder + */ + public function getContainer() + { + $container = new ContainerBuilder; + + return $container; + } +}