From 6baac9e36c96525e1843798315f8ad4ad082feaa Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 11 Jul 2013 11:11:16 +0200 Subject: [PATCH] create test for module:generate command --- .../Thelia/Command/ModuleGenerateCommand.php | 7 +- .../Thelia/Tests/Command/BaseCommandTest.php | 20 ++++ .../Command/ModuleGenerateCommandTest.php | 108 ++++++++++++++++++ 3 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 core/lib/Thelia/Tests/Command/BaseCommandTest.php create mode 100644 core/lib/Thelia/Tests/Command/ModuleGenerateCommandTest.php diff --git a/core/lib/Thelia/Command/ModuleGenerateCommand.php b/core/lib/Thelia/Command/ModuleGenerateCommand.php index 5d54cf55e..4a31a74ab 100644 --- a/core/lib/Thelia/Command/ModuleGenerateCommand.php +++ b/core/lib/Thelia/Command/ModuleGenerateCommand.php @@ -4,7 +4,7 @@ /* Thelia */ /* */ /* Copyright (c) OpenStudio */ -/* email : info@thelia.net */ +/* email : info@thelia.net */ /* web : http://www.thelia.net */ /* */ /* This program is free software; you can redistribute it and/or modify */ @@ -17,7 +17,7 @@ /* GNU General Public License for more details. */ /* */ /* You should have received a copy of the GNU General Public License */ -/* along with this program. If not, see . */ +/* along with this program. If not, see . */ /* */ /*************************************************************************************/ namespace Thelia\Command; @@ -109,6 +109,9 @@ class ModuleGenerateCommand extends ContainerAwareCommand { private function formatModuleName($name) { + if (in_array(strtolower($name), $this->reservedKeyWords)) { + throw new \RuntimeException(sprintf("%s module name is a reserved keyword", $name)); + } return ucfirst($name); } } \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Command/BaseCommandTest.php b/core/lib/Thelia/Tests/Command/BaseCommandTest.php new file mode 100644 index 000000000..ca9d0a632 --- /dev/null +++ b/core/lib/Thelia/Tests/Command/BaseCommandTest.php @@ -0,0 +1,20 @@ +getMock("Symfony\Component\HttpKernel\KernelInterface"); + + return $kernel; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Command/ModuleGenerateCommandTest.php b/core/lib/Thelia/Tests/Command/ModuleGenerateCommandTest.php new file mode 100644 index 000000000..dcbc98fff --- /dev/null +++ b/core/lib/Thelia/Tests/Command/ModuleGenerateCommandTest.php @@ -0,0 +1,108 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Tests\Command; + + +use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\Filesystem\Filesystem; +use Thelia\Core\Application; +use Thelia\Command\ModuleGenerateCommand; + +class ModuleGenerateCommandTest extends BaseCommandTest { + + protected $command; + protected $commandTester; + + public static function clearTest() + { + $fs = new Filesystem(); + + if ($fs->exists(THELIA_MODULE_DIR . "Test")) { + $fs->remove(THELIA_MODULE_DIR . "Test"); + } + } + + public static function setUpBeforeClass() + { + self::clearTest(); + } + + public static function tearDownAfterClass() + { + self::clearTest(); + } + + public function setUp() + { + $application = new Application($this->getKernel()); + + $moduleGenerator = new ModuleGenerateCommand(); + + $application->add($moduleGenerator); + + $this->command = $application->find("module:generate"); + $this->commandTester = new CommandTester($this->command); + + } + + public function testGenerateModule() + { + $tester = $this->commandTester; + + $tester->execute(array( + "command" => $this->command->getName(), + "name" => "test" + )); + + $fs = new Filesystem(); + + $this->assertTrue($fs->exists(THELIA_MODULE_DIR . "Test")); + } + + /** + * @depends testGenerateModule + * @expectedException \RuntimeException + */ + public function testGenerateDuplicateModule() + { + $tester = $this->commandTester; + + $tester->execute(array( + "command" => $this->command->getName(), + "name" => "test" + )); + } + + /** + * @expectedException \RuntimeException + */ + public function testGenerateWithReservedKeyWord() + { + $tester = $this->commandTester; + + $tester->execute(array( + "command" => $this->command->getName(), + "name" => "thelia" + )); + } +} \ No newline at end of file