Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added the "--filter <pattern>" command-line option to selectively run…

… the tests of a test suite. Closes #31, although in a different way.
  • Loading branch information...
commit 53d21fa4e104563072651d7de41d7969db15f46e 1 parent 8ff19a0
@sebastianbergmann authored
View
15 PHPUnit/Framework/TestSuite.php
@@ -438,11 +438,12 @@ public function getName()
* Runs the tests and collects their result in a TestResult.
*
* @param PHPUnit_Framework_TestResult $result
+ * @param mixed $filter
* @return PHPUnit_Framework_TestResult
* @throws InvalidArgumentException
* @access public
*/
- public function run(PHPUnit_Framework_TestResult $result = NULL)
+ public function run(PHPUnit_Framework_TestResult $result = NULL, $filter = FALSE)
{
if ($result === NULL) {
$result = $this->createResult();
@@ -455,7 +456,17 @@ public function run(PHPUnit_Framework_TestResult $result = NULL)
break;
}
- $this->runTest($test, $result);
+ $name = $test->getName();
+ $runTest = TRUE;
+
+ if ($name !== NULL && !$test instanceof PHPUnit_Framework_TestSuite &&
+ $filter !== FALSE && preg_match($filter, $name) == 0) {
+ $runTest = FALSE;
+ }
+
+ if ($runTest) {
+ $this->runTest($test, $result);
+ }
}
$result->endTestSuite($this);
View
18 PHPUnit/TextUI/TestRunner.php
@@ -148,6 +148,7 @@ protected function start(Array $arguments)
$possibleOptions = array(
'help',
+ 'filter=',
'loader=',
'log-eclipse=',
'log-tap=',
@@ -189,6 +190,15 @@ protected function start(Array $arguments)
}
break;
+ case '--filter': {
+ if (preg_match('/[a-zA-Z0-9_]/', $option[1])) {
+ $parameters['filter'] = '/^' . $option[1] . '$/';
+ } else {
+ $parameters['filter'] = $option[1];
+ }
+ }
+ break;
+
case '--loader': {
$loaderName = $option[1];
}
@@ -355,6 +365,8 @@ protected function createTestResult()
*/
public function doRun(PHPUnit_Framework_Test $suite, Array $parameters = array())
{
+ $parameters['filter'] = isset($parameters['filter']) ? $parameters['filter'] : FALSE;
+
if (isset($parameters['graphvizDirectory'])) {
$parameters['graphvizDirectory'] = $this->getDirectory($parameters['graphvizDirectory']);
}
@@ -430,7 +442,7 @@ public function doRun(PHPUnit_Framework_Test $suite, Array $parameters = array()
}
PHPUnit_Util_Timer::start();
- $suite->run($result);
+ $suite->run($result, $parameters['filter']);
$timeElapsed = PHPUnit_Util_Timer::stop();
$result->flushListeners();
@@ -481,7 +493,9 @@ public function showError($message)
public function showHelp()
{
self::printVersionString();
- print "Usage: phpunit [switches] UnitTest [UnitTest.php]\n\n";
+
+ print "Usage: phpunit [switches] UnitTest [UnitTest.php]\n\n" .
+ " --filter <pattern> Filter which tests to run.\n\n";
if (class_exists('Image_GraphViz')) {
print " --log-graphviz <dir> Log test execution in GraphViz markup.\n";
View
2  package.xml
@@ -55,6 +55,8 @@ User-Visible Changes
+ Added a TestListener that generates a logfile of the test execution using the Test Anything Protocol (TAP).
+ + Added the "--filter <pattern>" command-line option to selectively run the tests of a test suite.
+
+ Added the "--repeat <times>" command-line option to the TextUI test runner to run the test(s) repeatedly.
* PHPUnit_Framework_Assert::assertContains() and PHPUnit_Framework_Assert::assertNotContains() can now work on strings.
Please sign in to comment.
Something went wrong with that request. Please try again.