From f6aa0ed7da1b067cf0fc093ae6663a48ac621ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81ro=CC=82me=20Billiras?= Date: Tue, 10 Jun 2014 10:33:47 +0200 Subject: [PATCH 1/5] Add refresh command --- .../Thelia/Command/ModuleRefreshCommand.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 core/lib/Thelia/Command/ModuleRefreshCommand.php diff --git a/core/lib/Thelia/Command/ModuleRefreshCommand.php b/core/lib/Thelia/Command/ModuleRefreshCommand.php new file mode 100644 index 000000000..ea71acec4 --- /dev/null +++ b/core/lib/Thelia/Command/ModuleRefreshCommand.php @@ -0,0 +1,57 @@ + + * + * Date: 2014-06-06 + * Time: 17:00 + */ +class ModuleRefreshCommand extends ContainerAwareCommand +{ + protected function configure() + { + $this + ->setName('module:refresh') + ->setDescription('Refresh modules list'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + try { + $moduleManagement = new ModuleManagement; + $moduleManagement->updateModules(); + } catch (\Exception $e) { + throw new \RuntimeException(sprintf('Refresh modules list fail with Exception : [%d] %s', $e->getCode(), $e->getMessage())); + } + + if (method_exists($output, 'renderBlock')) { + $output->renderBlock([ + '', + 'Modules list successfully refreshed', + '' + ], + 'bg=green;fg=black' + ); + } + } +} From 76b08ddca961b3d93ea6f433d32613547786b586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81ro=CC=82me=20Billiras?= Date: Tue, 10 Jun 2014 10:34:19 +0200 Subject: [PATCH 2/5] Register refresh command to Thelia core --- core/lib/Thelia/Config/Resources/command.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lib/Thelia/Config/Resources/command.xml b/core/lib/Thelia/Config/Resources/command.xml index 8b61f40e7..313904c40 100644 --- a/core/lib/Thelia/Config/Resources/command.xml +++ b/core/lib/Thelia/Config/Resources/command.xml @@ -11,6 +11,7 @@ + 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 3/5] 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; + } +} From bead28f5d254e0af6b35bb84d837d91a24bfe762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81ro=CC=82me=20Billiras?= Date: Tue, 10 Jun 2014 11:13:06 +0200 Subject: [PATCH 4/5] Update test to consider only standards modules --- .../Tests/Command/ModuleRefreshCommandTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php b/core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php index 95a5f5b37..87ac0f292 100644 --- a/core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php +++ b/core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php @@ -42,7 +42,7 @@ class ModuleRefreshCommandTest extends PHPUnit_Framework_TestCase $moduleManagement = new ModuleManagement; $moduleManagement->updateModules(); - $module = ModuleQuery::create()->orderByPosition(Criteria::DESC)->findOne(); + $module = ModuleQuery::create()->filterByType(1)->orderByPosition(Criteria::DESC)->findOne(); if ($module !== null) { $module->delete(); @@ -61,11 +61,11 @@ class ModuleRefreshCommandTest extends PHPUnit_Framework_TestCase ]); $expected = $module; - $actual = ModuleQuery::create()->orderByPosition(Criteria::DESC)->findOne(); + $actual = ModuleQuery::create()->filterByType(1)->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'); + $this->assertEquals($expected->getCode(), $actual->getCode(), 'Last standard module code must be same after deleting this one and calling module:refresh'); + $this->assertEquals($expected->getType(), $actual->getType(), 'Last standard module type must be same after deleting this one and calling module:refresh'); + $this->assertEquals($expected->getFullNamespace(), $actual->getFullNamespace(), 'Last standard module namespace must be same after deleting this one and calling module:refresh'); // Restore activation status $actual @@ -74,7 +74,7 @@ class ModuleRefreshCommandTest extends PHPUnit_Framework_TestCase } else { $this->markTestIncomplete( - 'This test cannot be complete without at least one module' + 'This test cannot be complete without at least one standard module module.' ); } } From 5c8584c398e19f44e99817e543ad7a821f61798d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81ro=CC=82me=20Billiras?= Date: Tue, 10 Jun 2014 11:43:06 +0200 Subject: [PATCH 5/5] Code review following pull request comments --- CHANGELOG.md | 3 ++- core/lib/Thelia/Command/ModuleRefreshCommand.php | 3 --- core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f06f77c0..0d99d6fc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,8 @@ - class event : Thelia\Core\Event\SessionEvent - example : Thelia\Core\EventListener\SessionListener - Creation of Thelia\Core\TheliakernelEvents class for referencing kernel event - +- Add new command line that refresh modules list `Thelia module:refresh` + #2.0.1 - possibility to apply a permanent discount on a customer diff --git a/core/lib/Thelia/Command/ModuleRefreshCommand.php b/core/lib/Thelia/Command/ModuleRefreshCommand.php index ea71acec4..318542939 100644 --- a/core/lib/Thelia/Command/ModuleRefreshCommand.php +++ b/core/lib/Thelia/Command/ModuleRefreshCommand.php @@ -22,9 +22,6 @@ use Thelia\Module\ModuleManagement; * * @package Thelia\Command * @author Jérôme Billiras - * - * Date: 2014-06-06 - * Time: 17:00 */ class ModuleRefreshCommand extends ContainerAwareCommand { diff --git a/core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php b/core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php index 87ac0f292..15fd15a38 100644 --- a/core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php +++ b/core/lib/Thelia/Tests/Command/ModuleRefreshCommandTest.php @@ -74,7 +74,7 @@ class ModuleRefreshCommandTest extends PHPUnit_Framework_TestCase } else { $this->markTestIncomplete( - 'This test cannot be complete without at least one standard module module.' + 'This test cannot be complete without at least one standard module.' ); } }