Skip to content

Commit

Permalink
Merge pull request #144 from chbiel/#142-add-testsuite-parameter
Browse files Browse the repository at this point in the history
add support for testsuite parameter (#142)
  • Loading branch information
julianseeger committed Jan 31, 2015
2 parents 47a4f4d + 9f4570c commit 5b3c939
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/ParaTest/Console/Testers/PHPUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function configure(Command $command)
->addOption('stop-on-failure', null, InputOption::VALUE_NONE, 'Don\'t start any more processes after a failure.')
->addOption('log-junit', null, InputOption::VALUE_REQUIRED, 'Log test execution in JUnit XML format to file.')
->addOption('colors', null, InputOption::VALUE_NONE, 'Displays a colored bar as a test result.')
->addOption('testsuite', null, InputOption::VALUE_OPTIONAL, 'Filter which testsuite to run')
->addArgument('path', InputArgument::OPTIONAL, 'The path to a directory or file containing tests. <comment>(default: current directory)</comment>')
->addOption('path', null, InputOption::VALUE_REQUIRED, 'An alias for the path argument.');
$this->command = $command;
Expand Down
26 changes: 26 additions & 0 deletions src/ParaTest/Runners/PHPUnit/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,32 @@ public function getSuites()
return $suites;
}

public function getTestsuiteItems()
{

}

/**
* @param string $suiteName
*
* @return array|null
*/
public function getSuiteFiles($suiteName)
{
$nodes = $this->xml->xpath(sprintf('//testsuite[@name="%s"]', $suiteName));

$files = array();
while (list(, $node) = each($nodes)) {
foreach ($node->file as $file) {
foreach ($this->getSuitePaths((string) $file) as $path) {
$files[] = $path;
}
}
}

return $files;
}

/**
* Return the path of the directory
* that contains the phpunit configuration
Expand Down
3 changes: 3 additions & 0 deletions src/ParaTest/Runners/PHPUnit/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function __construct($opts = array())
$this->runner = $opts['runner'];
$this->noTestTokens = $opts['no-test-tokens'];
$this->colors = $opts['colors'];
$this->testsuite = $opts['testsuite'];

$this->filtered = $this->filterOptions($opts);
$this->initAnnotations();
Expand Down Expand Up @@ -112,6 +113,7 @@ protected static function defaults()
'runner' => 'Runner',
'no-test-tokens' => false,
'colors' => false,
'testsuite' => '',
);
}

Expand Down Expand Up @@ -172,6 +174,7 @@ protected function filterOptions($options)
'runner' => $this->runner,
'no-test-tokens' => $this->noTestTokens,
'colors' => $this->colors,
'testsuite' => $this->testsuite
));
if ($configuration = $this->getConfigurationPath($filtered)) {
$filtered['configuration'] = new Configuration($configuration);
Expand Down
10 changes: 10 additions & 0 deletions src/ParaTest/Runners/PHPUnit/SuiteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ public function load($path = '')

if ($path) {
$this->loadPath($path);
} elseif (isset($this->options->testsuite) && $this->options->testsuite) {
foreach ($configuration->getSuiteFiles($this->options->testsuite) as $file) {
$this->loadFile($file);
}
foreach ($configuration->getSuites() as $suite) {
foreach ($suite as $suitePath) {
$this->loadPath($suitePath);
}
}
$this->files = array_unique($this->files); // remove duplicates
} elseif ($suites = $configuration->getSuites()) {
foreach ($suites as $suite) {
foreach ($suite as $suitePath) {
Expand Down
18 changes: 18 additions & 0 deletions test/fixtures/phpunit-file.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="ParaTest Fixtures">
<file>./passing-tests/GroupsTest.php</file>
</testsuite>
</testsuites>
</phpunit>
20 changes: 20 additions & 0 deletions test/fixtures/phpunit-files-dirs-mix-duplicates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="ParaTest Fixtures">
<directory>./passing-tests/</directory>
<file>./passing-tests/TestOfUnits.php</file>
<file>./passing-tests/GroupsTest.php</file>
</testsuite>
</testsuites>
</phpunit>
20 changes: 20 additions & 0 deletions test/fixtures/phpunit-files-dirs-mix.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="ParaTest Fixtures">
<directory>./failing-tests/</directory>
<file>./passing-tests/TestOfUnits.php</file>
<file>./passing-tests/GroupsTest.php</file>
</testsuite>
</testsuites>
</phpunit>
19 changes: 19 additions & 0 deletions test/fixtures/phpunit-multifile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="ParaTest Fixtures">
<file>./passing-tests/TestOfUnits.php</file>
<file>./passing-tests/GroupsTest.php</file>
</testsuite>
</testsuites>
</phpunit>
3 changes: 2 additions & 1 deletion test/unit/ParaTest/Console/Commands/ParaTestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public function testConfiguredDefinitionWithPHPUnitTester()
new InputOption('path', null, InputOption::VALUE_REQUIRED, 'An alias for the path argument.'),
new InputOption('coverage-clover', null, InputOption::VALUE_REQUIRED, 'Generate code coverage report in Clover XML format.'),
new InputOption('coverage-html', null, InputOption::VALUE_REQUIRED, 'Generate code coverage report in HTML format.'),
new InputOption('coverage-php', null, InputOption::VALUE_REQUIRED, 'Serialize PHP_CodeCoverage object to file.')
new InputOption('coverage-php', null, InputOption::VALUE_REQUIRED, 'Serialize PHP_CodeCoverage object to file.'),
new InputOption('testsuite', null, InputOption::VALUE_OPTIONAL, 'Filter which testsuite to run')
));
$definition = $this->command->getDefinition();
$this->assertEquals($expected, $definition);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/ParaTest/Console/Testers/PHPUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function testConfigureAddsOptionsAndArgumentsToCommand()
new InputOption('log-junit', null, InputOption::VALUE_REQUIRED, 'Log test execution in JUnit XML format to file.'),
new InputOption('colors', null, InputOption::VALUE_NONE, 'Displays a colored bar as a test result.'),
new InputArgument('path', InputArgument::OPTIONAL, 'The path to a directory or file containing tests. <comment>(default: current directory)</comment>'),
new InputOption('path', null, InputOption::VALUE_REQUIRED, 'An alias for the path argument.')
new InputOption('path', null, InputOption::VALUE_REQUIRED, 'An alias for the path argument.'),
new InputOption('testsuite', null, InputOption::VALUE_OPTIONAL, 'Filter which testsuite to run')
));
$tester = new PHPUnit();
$tester->configure($testCommand);
Expand Down
109 changes: 90 additions & 19 deletions test/unit/ParaTest/Runners/PHPUnit/SuiteLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,77 @@ public function testLoadBarePathWithNoPathAndNoConfiguration()
$loader->load();
}

public function testLoadTestsuiteFileFromConfig()
{
$options = new Options(
array('configuration' => $this->fixture('phpunit-file.xml'), 'testsuite' => 'ParaTest Fixtures')
);
$loader = new SuiteLoader($options);
$loader->load();
$files = $this->getObjectValue($loader, 'files');

$expected = 1;
$this->assertEquals($expected, sizeof($files));
}

public function testLoadTestsuiteFilesFromConfig()
{
$options = new Options(
array('configuration' => $this->fixture('phpunit-multifile.xml'), 'testsuite' => 'ParaTest Fixtures')
);
$loader = new SuiteLoader($options);
$loader->load();
$files = $this->getObjectValue($loader, 'files');

$expected = 2;
$this->assertEquals($expected, sizeof($files));
}

public function testLoadTestsuiteWithDirectory()
{
$options = new Options(array('configuration' => $this->fixture('phpunit-passing.xml'), 'testsuite' => 'ParaTest Fixtures'));
$loader = new SuiteLoader($options);
$loader->load();
$files = $this->getObjectValue($loader, 'files');

$expected = sizeof($this->findTests(FIXTURES . DS . 'passing-tests'));
$this->assertEquals($expected, sizeof($files));
}

public function testLoadTestsuiteWithDirectories()
{
$options = new Options(array('configuration' => $this->fixture('phpunit-multidir.xml'), 'testsuite' => 'ParaTest Fixtures'));
$loader = new SuiteLoader($options);
$loader->load();
$files = $this->getObjectValue($loader, 'files');

$expected = sizeof($this->findTests(FIXTURES . DS . 'passing-tests')) +
sizeof($this->findTests(FIXTURES . DS . 'failing-tests'));
$this->assertEquals($expected, sizeof($files));
}

public function testLoadTestsuiteWithFilesDirsMixed()
{
$options = new Options(array('configuration' => $this->fixture('phpunit-files-dirs-mix.xml'), 'testsuite' => 'ParaTest Fixtures'));
$loader = new SuiteLoader($options);
$loader->load();
$files = $this->getObjectValue($loader, 'files');

$expected = sizeof($this->findTests(FIXTURES . DS . 'failing-tests')) + 2;
$this->assertEquals($expected, sizeof($files));
}

public function testLoadTestsuiteWithDuplicateFilesDirMixed()
{
$options = new Options(array('configuration' => $this->fixture('phpunit-files-dirs-mix-duplicates.xml'), 'testsuite' => 'ParaTest Fixtures'));
$loader = new SuiteLoader($options);
$loader->load();
$files = $this->getObjectValue($loader, 'files');

$expected = sizeof($this->findTests(FIXTURES . DS . 'passing-tests')) + 1;
$this->assertEquals($expected, sizeof($files));
}

public function testLoadSuiteFromConfig()
{
$options = new Options(array('configuration' => $this->fixture('phpunit-passing.xml')));
Expand Down Expand Up @@ -83,6 +154,15 @@ public function testLoadFileGetsPathOfFile()
$this->assertEquals($path, array_shift($paths));
}

protected function getLoadedPaths($path, $loader=null)
{
$loader = $loader ?: new SuiteLoader();
$loader->load($path);
$loaded = $this->getObjectValue($loader, 'loadedSuites');
$paths = array_keys($loaded);
return $paths;
}

public function testLoadFileShouldLoadFileWhereNameDoesNotEndInTest()
{
$path = $this->fixture('passing-tests/TestOfUnits.php');
Expand Down Expand Up @@ -118,6 +198,16 @@ public function testFirstParallelSuiteHasCorrectFunctions($paraSuites)
$this->assertEquals('testAddition', $functions[4]->getName());
}

private function suiteByPath($path, array $paraSuites)
{
foreach ($paraSuites as $completePath => $suite) {
if (strstr($completePath, $path)) {
return $suite;
}
}
throw new \RuntimeException("Suite $path not found.");
}

/**
* @depends testLoadDirGetsPathOfAllTestsWithKeys
*/
Expand Down Expand Up @@ -161,23 +251,4 @@ public function testExecutableTestsForFunctionalModeUse()
$testMethodName = $this->getObjectValue($testMethod, 'name');
$this->assertEquals($testMethodName, 'testTwoA|testTwoBDependsOnA');
}

protected function getLoadedPaths($path, $loader=null)
{
$loader = $loader ?: new SuiteLoader();
$loader->load($path);
$loaded = $this->getObjectValue($loader, 'loadedSuites');
$paths = array_keys($loaded);
return $paths;
}

private function suiteByPath($path, array $paraSuites)
{
foreach ($paraSuites as $completePath => $suite) {
if (strstr($completePath, $path)) {
return $suite;
}
}
throw new \RuntimeException("Suite $path not found.");
}
}

0 comments on commit 5b3c939

Please # to comment.