From d59c0e1d112049e9a058780c6d7215554c6a4151 Mon Sep 17 00:00:00 2001 From: Sam Schmidt Date: Tue, 5 May 2015 09:51:22 -0400 Subject: [PATCH 1/8] Always isolate modules in a separate process when testing. --- src/LinusShops/Prophet/Commands/Scry.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/LinusShops/Prophet/Commands/Scry.php b/src/LinusShops/Prophet/Commands/Scry.php index 42748f0..7c06743 100644 --- a/src/LinusShops/Prophet/Commands/Scry.php +++ b/src/LinusShops/Prophet/Commands/Scry.php @@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output) /** @var Module $module */ foreach ($config->getModuleList() as $module) { if ($this->checkIfRequested($modulesRequested, $module, $output)) { - if ($this->isIsolated($module, $input)) { + if (!$this->isIsolated($input)) { $output->writeln("Isolating {$module->getName()}"); $cmd = $this->getProphetCall()." scry --isolated -m {$module->getName()}"; $this->cli->veryVerbose($cmd, $output); @@ -109,9 +109,9 @@ private function loadClasses($modulesRequested, Config $config, InputInterface $ return $loaded; } - private function isIsolated($module, InputInterface $input) + private function isIsolated(InputInterface $input) { - return $module->isIsolated() && !$input->getOption('isolated'); + return $input->getOption('isolated'); } private function checkIfRequested($modulesRequested, $module, OutputInterface $output) From 863691320f603c9dd874de642e8e5bb71367fbdb Mon Sep 17 00:00:00 2001 From: Sam Schmidt Date: Thu, 7 May 2015 16:53:45 -0400 Subject: [PATCH 2/8] Move loadConfig to ConfigRepository. --- src/LinusShops/Prophet/ConfigRepository.php | 14 +++++++++++++- src/LinusShops/Prophet/ProphetCommand.php | 20 +++----------------- tests/ScryTest.php | 21 +++++++-------------- 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/src/LinusShops/Prophet/ConfigRepository.php b/src/LinusShops/Prophet/ConfigRepository.php index d9c4063..350654a 100644 --- a/src/LinusShops/Prophet/ConfigRepository.php +++ b/src/LinusShops/Prophet/ConfigRepository.php @@ -47,5 +47,17 @@ public static function setProphetPath($prophetPath) self::$prophetPath = rtrim($prophetPath, '/'); } - + public static function loadConfig($path) + { + $loaded = true; + $path = $path.'/prophet.json'; + $json = json_decode(file_get_contents($path), true); + if ($json === false) { + $loaded = false; + } else { + self::setConfig(new Config($json)); + } + + return $loaded; + } } diff --git a/src/LinusShops/Prophet/ProphetCommand.php b/src/LinusShops/Prophet/ProphetCommand.php index a51b8ee..8b398b1 100644 --- a/src/LinusShops/Prophet/ProphetCommand.php +++ b/src/LinusShops/Prophet/ProphetCommand.php @@ -33,7 +33,9 @@ protected function execute(InputInterface $input, OutputInterface $output) { $loaded = $this->checkFile($input, $output); - $loaded = $loaded ? $this->loadConfig($input, $output) : $loaded; + $loaded = $loaded ? + ConfigRepository::loadConfig($input->getOption('path')) + : $loaded; return $loaded; } @@ -53,21 +55,5 @@ private function checkFile(InputInterface $input, OutputInterface $output) return $exists; } - private function loadConfig(InputInterface $input, OutputInterface $output) - { - $loaded = true; - $path = $input->getOption('path').'/prophet.json'; - $json = json_decode(file_get_contents($path), true); - if ($json === false) { - $output->writeln( - "Failed to parse {$path}: invalid json." - ); - $loaded = false; - } else { - ConfigRepository::setConfig(new Config($json)); - } - - return $loaded; - } } diff --git a/tests/ScryTest.php b/tests/ScryTest.php index 27a7f93..518059f 100644 --- a/tests/ScryTest.php +++ b/tests/ScryTest.php @@ -40,24 +40,17 @@ public function setUp() ); } - public function testScry() - { - //For now, execute prophet and check its output against known values. - //Some attempts with Symfony CommandTester and mocking were not - //effective (specifically, the test contexts couldn't be separated), - // so this should do for now. - // Means no code coverage stats though :( - //TODO: revisit this, replace with mocks or different harness to separate contexts - - $output = shell_exec("./prophet scry -p ./magento"); - - $this->assertRegExp('/OK \(1 test, 1 assertion\)/', $output); - } - public function tearDown() { if (file_exists($this->path)) { unlink($this->path); } } + + public function testScryFullExecution() + { + $output = shell_exec("./prophet scry -p ./magento"); + + $this->assertRegExp('/OK \(1 test, 1 assertion\)/', $output); + } } From ccf9fb84db5e74612617b118b45be1e562aac66f Mon Sep 17 00:00:00 2001 From: Sam Schmidt Date: Thu, 7 May 2015 16:56:56 -0400 Subject: [PATCH 3/8] Move json string into function. --- tests/ScryTest.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/ScryTest.php b/tests/ScryTest.php index 518059f..75370f4 100644 --- a/tests/ScryTest.php +++ b/tests/ScryTest.php @@ -21,13 +21,9 @@ class ScryTest extends \PHPUnit_Framework_TestCase { private $path = './magento/prophet.json'; - public function setUp() + public function getJson() { - if (file_exists($this->path)) { - unlink($this->path); - } - - file_put_contents($this->path, <<path)) { + unlink($this->path); + } + + file_put_contents($this->path, $this->getJson()); } public function tearDown() From 71dd83b569318092a9081fc8456e9a90289a8ef6 Mon Sep 17 00:00:00 2001 From: Sam Schmidt Date: Fri, 8 May 2015 09:28:44 -0400 Subject: [PATCH 4/8] Fix isolation to use path. --- src/LinusShops/Prophet/Commands/Scry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LinusShops/Prophet/Commands/Scry.php b/src/LinusShops/Prophet/Commands/Scry.php index 7c06743..e0cb9d0 100644 --- a/src/LinusShops/Prophet/Commands/Scry.php +++ b/src/LinusShops/Prophet/Commands/Scry.php @@ -77,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($this->checkIfRequested($modulesRequested, $module, $output)) { if (!$this->isIsolated($input)) { $output->writeln("Isolating {$module->getName()}"); - $cmd = $this->getProphetCall()." scry --isolated -m {$module->getName()}"; + $cmd = $this->getProphetCall()." scry --isolated -m {$module->getName()} -p {$input->getOption('path')}"; $this->cli->veryVerbose($cmd, $output); passthru($cmd); } else { From 87a63195a5c65a63b019b4f007cd2fcadafdd620 Mon Sep 17 00:00:00 2001 From: Sam Schmidt Date: Fri, 8 May 2015 09:29:33 -0400 Subject: [PATCH 5/8] Refactor command tests into one test file. --- tests/AnalyzeTest.php | 18 -------- tests/InitTest.php | 17 -------- tests/ProphetCommandTest.php | 83 ++++++++++++++++++++++++++++++++++++ tests/ScryTest.php | 60 -------------------------- tests/ValidateTest.php | 18 -------- 5 files changed, 83 insertions(+), 113 deletions(-) delete mode 100644 tests/AnalyzeTest.php delete mode 100644 tests/InitTest.php create mode 100644 tests/ProphetCommandTest.php delete mode 100644 tests/ScryTest.php delete mode 100644 tests/ValidateTest.php diff --git a/tests/AnalyzeTest.php b/tests/AnalyzeTest.php deleted file mode 100644 index 276ef29..0000000 --- a/tests/AnalyzeTest.php +++ /dev/null @@ -1,18 +0,0 @@ -path.'/prophet.json'; + } + + public function setUp() + { + echo $this->getJsonPath(); + if (file_exists($this->getJsonPath())) { + unlink($this->getJsonPath()); + } + + file_put_contents($this->getJsonPath(), $this->getJson()); + } + + public function tearDown() + { + if (file_exists($this->getJsonPath())) { + unlink($this->getJsonPath()); + } + } + + public function testScryFullExecution() + { + $output = shell_exec("./prophet scry -p ./magento"); + + $this->assertRegExp('/OK \(1 test, 1 assertion\)/', $output); + } + + public function testValidateCommand() + { + $application = new Application(); + $application->add(new Validate()); + + $command = $application->find('validate'); + $commandTester = new CommandTester($command); + $commandTester->execute(array( + 'command' => $command->getName() + ), array( + '-p' => './magento' + )); + + echo $commandTester->getDisplay(); + } +} diff --git a/tests/ScryTest.php b/tests/ScryTest.php deleted file mode 100644 index 75370f4..0000000 --- a/tests/ScryTest.php +++ /dev/null @@ -1,60 +0,0 @@ -path)) { - unlink($this->path); - } - - file_put_contents($this->path, $this->getJson()); - } - - public function tearDown() - { - if (file_exists($this->path)) { - unlink($this->path); - } - } - - public function testScryFullExecution() - { - $output = shell_exec("./prophet scry -p ./magento"); - - $this->assertRegExp('/OK \(1 test, 1 assertion\)/', $output); - } -} diff --git a/tests/ValidateTest.php b/tests/ValidateTest.php deleted file mode 100644 index fb60400..0000000 --- a/tests/ValidateTest.php +++ /dev/null @@ -1,18 +0,0 @@ - Date: Fri, 8 May 2015 09:35:37 -0400 Subject: [PATCH 6/8] Added documentation on how prophet works. --- README.md | 9 +++++++++ tests/ProphetCommandTest.php | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f2edbbf..d15ad04 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,15 @@ Objective: provide a test harness that does not require modifying Magento core, and allows testing by module. The only thing that should exist is config files, and the tests themselves. +Prophet accomplishes this by finding Mage.php and the bootstrapping functions +for the Varien autoloader, and instantiates them. By doing this, it is able to +instantiate the Magento environment in which tests can be run. It then loads +PHPUnit and executes tests for the provided module list. + +To ensure that the test context for each module's tests is clean, it creates +a subprocess of prophet to run the module tests. This ensures that there is no +shared state between module test suites. + ##Installation Prophet should be installed via composer. It is recommended to install it globally. diff --git a/tests/ProphetCommandTest.php b/tests/ProphetCommandTest.php index 9cdd997..117c489 100644 --- a/tests/ProphetCommandTest.php +++ b/tests/ProphetCommandTest.php @@ -78,6 +78,6 @@ public function testValidateCommand() '-p' => './magento' )); - echo $commandTester->getDisplay(); + //$commandTester->getDisplay(); } } From aaaab2df44c346fb1f95e83ebf301af31ca82012 Mon Sep 17 00:00:00 2001 From: Sam Schmidt Date: Fri, 8 May 2015 09:36:49 -0400 Subject: [PATCH 7/8] Remove debug echo. --- tests/ProphetCommandTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ProphetCommandTest.php b/tests/ProphetCommandTest.php index 117c489..cc73a4c 100644 --- a/tests/ProphetCommandTest.php +++ b/tests/ProphetCommandTest.php @@ -43,7 +43,6 @@ public function getJsonPath() public function setUp() { - echo $this->getJsonPath(); if (file_exists($this->getJsonPath())) { unlink($this->getJsonPath()); } From ca0663cf7a7f640ee00590fe2a5e7dc380baaf68 Mon Sep 17 00:00:00 2001 From: Sam Schmidt Date: Fri, 8 May 2015 09:37:51 -0400 Subject: [PATCH 8/8] Version bump --- composer.json | 2 +- prophet | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index be0e627..d4edd17 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "linusshops/prophet", "description": "Module testing for Magento Modules", - "version": "0.3.0", + "version": "0.3.1", "type": "utility", "keywords": [ "magento", diff --git a/prophet b/prophet index 87e8f8b..955b92c 100755 --- a/prophet +++ b/prophet @@ -44,7 +44,7 @@ use Symfony\Component\Console\Application; $application = new Application(); $application->setName('Prophet'); -$application->setVersion('0.3.0'); +$application->setVersion('0.3.1'); $application->setDefaultCommand('scry'); \LinusShops\Prophet\ConfigRepository::setProphetPath($_SERVER['argv'][0]);