Skip to content

Commit

Permalink
Merge pull request #148 from chbiel/nested-testsuites-support
Browse files Browse the repository at this point in the history
Nested testsuites support
  • Loading branch information
julianseeger committed Feb 5, 2015
2 parents b58733d + 401a100 commit 0990342
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 24 deletions.
45 changes: 27 additions & 18 deletions src/ParaTest/Runners/PHPUnit/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Configuration
*/
protected $xml;

protected $availableNodes = array('file', 'directory', 'testsuite');

/**
* A collection of datastructures
* build from the <testsuite> nodes inside of a
Expand Down Expand Up @@ -79,41 +81,48 @@ public function getSuites()
return null;
}
$suites = array();
$nodes = $this->xml->xpath('//testsuite');
$nodes = $this->xml->xpath('//testsuites/testsuite');

while (list(, $node) = each($nodes)) {
foreach ($node->directory as $dir) {
foreach ($this->getSuitePaths((string) $dir) as $path) {
$suites[(string)$node['name']][] = new SuitePath($path, $dir->attributes()->suffix);
}
}
$suites = array_merge_recursive($suites, $this->getSuiteByName((string)$node['name']));
}
return $suites;
}

public function getTestsuiteItems()
{

}

/**
* Return the contents of the <testsuite> nodes
* contained in a PHPUnit configuration
*
* @param string $suiteName
*
* @return array|null
* @return array
*/
public function getSuiteFiles($suiteName)
public function getSuiteByName($suiteName)
{
$nodes = $this->xml->xpath(sprintf('//testsuite[@name="%s"]', $suiteName));

$files = array();
$suites = array();
while (list(, $node) = each($nodes)) {
foreach ($node->file as $file) {
foreach ($this->getSuitePaths((string) $file) as $path) {
$files[] = $path;
foreach ($this->availableNodes as $nodeName) {
foreach ($node->{$nodeName} as $nodeContent) {
switch ($nodeName) {
case 'testsuite':
$suites = array_merge_recursive($suites, $this->getSuiteByName((string)$nodeContent));
break;
default:
foreach ($this->getSuitePaths((string)$nodeContent) as $path) {
$suites[(string)$node['name']][] = new SuitePath(
$path,
$nodeContent->attributes()->suffix
);
}
break;
}
}
}
}

return $files;
return $suites;
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/ParaTest/Runners/PHPUnit/SuiteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,11 @@ 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 ($configuration->getSuiteByName($this->options->testsuite) 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 All @@ -114,6 +110,8 @@ public function load($path = '')
throw new \RuntimeException("No path or configuration provided (tests must end with Test.php)");
}

$this->files = array_unique($this->files); // remove duplicates

$this->initSuites();
}

Expand Down
25 changes: 25 additions & 0 deletions test/fixtures/phpunit-files-dirs-mix-nested.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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>Nested Suite</testsuite>
</testsuite>
<testsuite name="Nested Suite">
<directory>./passing-tests/</directory>
<file>./passing-tests/GroupsTest.php</file>
</testsuite>
</testsuites>
</phpunit>
18 changes: 17 additions & 1 deletion test/unit/ParaTest/Runners/PHPUnit/SuiteLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public function testLoadTestsuiteWithDirectories()

public function testLoadTestsuiteWithFilesDirsMixed()
{
$options = new Options(array('configuration' => $this->fixture('phpunit-files-dirs-mix.xml'), 'testsuite' => 'ParaTest Fixtures'));
$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');
Expand All @@ -102,6 +104,20 @@ public function testLoadTestsuiteWithFilesDirsMixed()
$this->assertEquals($expected, sizeof($files));
}

public function testLoadTestsuiteWithNestedSuite()
{
$options = new Options(
array('configuration' => $this->fixture('phpunit-files-dirs-mix-nested.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')) + 1;
$this->assertEquals($expected, sizeof($files));
}

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

0 comments on commit 0990342

Please # to comment.