diff --git a/src/ParaTest/Runners/PHPUnit/Configuration.php b/src/ParaTest/Runners/PHPUnit/Configuration.php index 60bdb439..e7d15de0 100644 --- a/src/ParaTest/Runners/PHPUnit/Configuration.php +++ b/src/ParaTest/Runners/PHPUnit/Configuration.php @@ -23,6 +23,8 @@ class Configuration */ protected $xml; + protected $availableNodes = array('file', 'directory', 'testsuite'); + /** * A collection of datastructures * build from the nodes inside of a @@ -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 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; } /** diff --git a/src/ParaTest/Runners/PHPUnit/SuiteLoader.php b/src/ParaTest/Runners/PHPUnit/SuiteLoader.php index 24aa79e1..3033706a 100644 --- a/src/ParaTest/Runners/PHPUnit/SuiteLoader.php +++ b/src/ParaTest/Runners/PHPUnit/SuiteLoader.php @@ -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) { @@ -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(); } diff --git a/test/fixtures/phpunit-files-dirs-mix-nested.xml b/test/fixtures/phpunit-files-dirs-mix-nested.xml new file mode 100644 index 00000000..5a0cef90 --- /dev/null +++ b/test/fixtures/phpunit-files-dirs-mix-nested.xml @@ -0,0 +1,25 @@ + + + + + ./failing-tests/ + ./passing-tests/TestOfUnits.php + ./passing-tests/GroupsTest.php + Nested Suite + + + ./passing-tests/ + ./passing-tests/GroupsTest.php + + + diff --git a/test/unit/ParaTest/Runners/PHPUnit/SuiteLoaderTest.php b/test/unit/ParaTest/Runners/PHPUnit/SuiteLoaderTest.php index dba1fd7e..5fdc0dd2 100644 --- a/test/unit/ParaTest/Runners/PHPUnit/SuiteLoaderTest.php +++ b/test/unit/ParaTest/Runners/PHPUnit/SuiteLoaderTest.php @@ -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'); @@ -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'));