Skip to content

Commit a4183ff

Browse files
committed
Merge pull request sebastianbergmann#495 from jpic/master
Added --testsuite argument, allowing to filter files/directory by parent testsuite name attribute
2 parents 5a62ff7 + 34bd4fe commit a4183ff

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

PHPUnit/TextUI/Command.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class PHPUnit_TextUI_Command
8686
'debug' => NULL,
8787
'exclude-group=' => NULL,
8888
'filter=' => NULL,
89+
'testsuite=' => NULL,
8990
'group=' => NULL,
9091
'help' => NULL,
9192
'include-path=' => NULL,
@@ -344,6 +345,11 @@ protected function handleArguments(array $argv)
344345
}
345346
break;
346347

348+
case '--testsuite': {
349+
$this->arguments['testsuite'] = $option[1];
350+
}
351+
break;
352+
347353
case '--group': {
348354
$this->arguments['groups'] = explode(',', $option[1]);
349355
}
@@ -657,7 +663,7 @@ class_exists('PHPUnit_Extensions_SeleniumTestCase')) {
657663
}
658664

659665
if (!isset($this->arguments['test'])) {
660-
$testSuite = $configuration->getTestSuiteConfiguration();
666+
$testSuite = $configuration->getTestSuiteConfiguration(isset($this->arguments['testsuite']) ? $this->arguments['testsuite'] : null);
661667

662668
if ($testSuite !== NULL) {
663669
$this->arguments['test'] = $testSuite;
@@ -851,6 +857,7 @@ protected function showHelp()
851857
--testdox-text <file> Write agile documentation in Text format to file.
852858
853859
--filter <pattern> Filter which tests to run.
860+
--testsuite <pattern> Filter which testsuite to run.
854861
--group ... Only runs tests from the specified group(s).
855862
--exclude-group ... Exclude tests from the specified group(s).
856863
--list-groups List available test groups.

PHPUnit/Util/Configuration.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ public function getSeleniumBrowserConfiguration()
758758
* @return PHPUnit_Framework_TestSuite
759759
* @since Method available since Release 3.2.1
760760
*/
761-
public function getTestSuiteConfiguration()
761+
public function getTestSuiteConfiguration($testSuiteFilter=null)
762762
{
763763
$testSuiteNodes = $this->xpath->query('testsuites/testsuite');
764764

@@ -767,15 +767,15 @@ public function getTestSuiteConfiguration()
767767
}
768768

769769
if ($testSuiteNodes->length == 1) {
770-
return $this->getTestSuite($testSuiteNodes->item(0));
770+
return $this->getTestSuite($testSuiteNodes->item(0), $testSuiteFilter);
771771
}
772772

773773
if ($testSuiteNodes->length > 1) {
774774
$suite = new PHPUnit_Framework_TestSuite;
775775

776776
foreach ($testSuiteNodes as $testSuiteNode) {
777777
$suite->addTestSuite(
778-
$this->getTestSuite($testSuiteNode)
778+
$this->getTestSuite($testSuiteNode, $testSuiteFilter)
779779
);
780780
}
781781

@@ -788,7 +788,7 @@ public function getTestSuiteConfiguration()
788788
* @return PHPUnit_Framework_TestSuite
789789
* @since Method available since Release 3.4.0
790790
*/
791-
protected function getTestSuite(DOMElement $testSuiteNode)
791+
protected function getTestSuite(DOMElement $testSuiteNode, $testSuiteFilter=null)
792792
{
793793
if ($testSuiteNode->hasAttribute('name')) {
794794
$suite = new PHPUnit_Framework_TestSuite(
@@ -807,6 +807,10 @@ protected function getTestSuite(DOMElement $testSuiteNode)
807807
$fileIteratorFacade = new File_Iterator_Facade;
808808

809809
foreach ($testSuiteNode->getElementsByTagName('directory') as $directoryNode) {
810+
if ($testSuiteFilter && $directoryNode->parentNode->getAttribute('name') != $testSuiteFilter) {
811+
continue;
812+
}
813+
810814
$directory = (string)$directoryNode->nodeValue;
811815

812816
if (empty($directory)) {
@@ -851,6 +855,10 @@ protected function getTestSuite(DOMElement $testSuiteNode)
851855
}
852856

853857
foreach ($testSuiteNode->getElementsByTagName('file') as $fileNode) {
858+
if ($testSuiteFilter && $fileNode->parentNode->getAttribute('name') != $testSuiteFilter) {
859+
continue;
860+
}
861+
854862
$file = (string)$fileNode->nodeValue;
855863

856864
if (empty($file)) {

0 commit comments

Comments
 (0)