Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #19 from linusshops/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
dersam committed May 8, 2015
2 parents 8cc6efa + cb30c10 commit 7a7633c
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 140 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion prophet
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
8 changes: 4 additions & 4 deletions src/LinusShops/Prophet/Commands/Scry.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ 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("<info>Isolating {$module->getName()}</info>");
$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 {
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion src/LinusShops/Prophet/ConfigRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
20 changes: 3 additions & 17 deletions src/LinusShops/Prophet/ProphetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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(
"<error>Failed to parse {$path}: invalid json.</error>"
);

$loaded = false;
} else {
ConfigRepository::setConfig(new Config($json));
}

return $loaded;
}
}
18 changes: 0 additions & 18 deletions tests/AnalyzeTest.php

This file was deleted.

17 changes: 0 additions & 17 deletions tests/InitTest.php

This file was deleted.

82 changes: 82 additions & 0 deletions tests/ProphetCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
use LinusShops\Prophet\Commands\Scry;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

/**
*
*
* @author Sam Schmidt
* @date 2015-05-04
* @company Linus Shops
*/

namespace LinusShops\Prophet;

use LinusShops\Prophet\Commands\Scry;
use LinusShops\Prophet\Commands\Validate;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

class ProphetCommandTest extends \PHPUnit_Framework_TestCase
{
private $path = './magento';

public function getJson()
{
return <<<JSON
{
"modules": [
{
"path": "vendor/linusshops/prophet-magento-test-module",
"name": "test-module"
}
]
}
JSON;
}

public function getJsonPath()
{
return $this->path.'/prophet.json';
}

public function setUp()
{
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'
));

//$commandTester->getDisplay();
}
}
63 changes: 0 additions & 63 deletions tests/ScryTest.php

This file was deleted.

18 changes: 0 additions & 18 deletions tests/ValidateTest.php

This file was deleted.

0 comments on commit 7a7633c

Please sign in to comment.