Skip to content

Commit

Permalink
Refs #622
Browse files Browse the repository at this point in the history
Expanded `--filter` to support:

 * `TestClass#1-3`
 * `TestClass#1`
 * `#1-3`
 * `#1`
 * `TestClass@providerName`
 * `TestClass@providerName.*`
 * `@providerName`
 * `@providerName.*`
  • Loading branch information
whatthejeff committed Sep 1, 2013
1 parent 81622f2 commit 41c7255
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 6 deletions.
14 changes: 8 additions & 6 deletions PHPUnit/Runner/Filter/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,24 @@ public function __construct(RecursiveIterator $iterator, $filter)
*/
protected function setFilter($filter)
{
if (preg_match('/^[a-zA-Z0-9_]/', $filter)) {
if ($filter[0] != substr($filter, -1) ||
preg_match('/^[a-zA-Z0-9_]/', $filter)) {

// Handles:
// * testAssertEqualsSucceeds#4
// * testAssertEqualsSucceeds#4-8
if (preg_match('/^(.+)#(\d+)(?:-(\d+))?$/', $filter, $matches)) {
if (preg_match('/^(.*?)#(\d+)(?:-(\d+))?$/', $filter, $matches)) {
if (isset($matches[3]) && $matches[2] < $matches[3]) {
$filter = sprintf(
'%s with data set #(\d+)$',
'%s.*with data set #(\d+)$',
$matches[1]
);

$this->filterMin = $matches[2];
$this->filterMax = $matches[3];
} else {
$filter = sprintf(
'%s with data set #%s$',
'%s.*with data set #%s$',
$matches[1],
$matches[2]
);
Expand All @@ -108,9 +110,9 @@ protected function setFilter($filter)
// Handles:
// * testDetermineJsonError@JSON_ERROR_NONE
// * testDetermineJsonError@JSON.*
elseif (preg_match('/^(.+?)@(.+)$/', $filter, $matches)) {
elseif (preg_match('/^(.*?)@(.+)$/', $filter, $matches)) {
$filter = sprintf(
'%s with data set "%s"$',
'%s.*with data set "%s"$',
$matches[1],
$matches[2]
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
phpunit --process-isolation --filter DataProviderFilterTest#1-3 DataProviderFilterTest ../_files/DataProviderFilterTest.php
--FILE--
<?php
define('PHPUNIT_TESTSUITE', TRUE);

$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--process-isolation';
$_SERVER['argv'][3] = '--filter';
$_SERVER['argv'][4] = 'DataProviderFilterTest#1-3';
$_SERVER['argv'][5] = 'DataProviderFilterTest';
$_SERVER['argv'][6] = dirname(__FILE__).'/../_files/DataProviderFilterTest.php';

require __DIR__ . '/../bootstrap.php';
PHPUnit_TextUI_Command::main();
?>
--EXPECTF--
PHPUnit %s by Sebastian Bergmann.

...

Time: %s, Memory: %sMb

OK (3 tests, 3 assertions)
23 changes: 23 additions & 0 deletions Tests/TextUI/filter-dataprovider-by-classname-and-range.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
phpunit --filter DataProviderFilterTest#1-3 DataProviderFilterTest ../_files/DataProviderFilterTest.php
--FILE--
<?php
define('PHPUNIT_TESTSUITE', TRUE);

$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--filter';
$_SERVER['argv'][3] = 'DataProviderFilterTest#1-3';
$_SERVER['argv'][4] = 'DataProviderFilterTest';
$_SERVER['argv'][5] = dirname(__FILE__).'/../_files/DataProviderFilterTest.php';

require __DIR__ . '/../bootstrap.php';
PHPUnit_TextUI_Command::main();
?>
--EXPECTF--
PHPUnit %s by Sebastian Bergmann.

...

Time: %s, Memory: %sMb

OK (3 tests, 3 assertions)
24 changes: 24 additions & 0 deletions Tests/TextUI/filter-dataprovider-by-only-range-isolation.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
phpunit --process-isolation --filter \#1-3 DataProviderFilterTest ../_files/DataProviderFilterTest.php
--FILE--
<?php
define('PHPUNIT_TESTSUITE', TRUE);

$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--process-isolation';
$_SERVER['argv'][3] = '--filter';
$_SERVER['argv'][4] = '#1-3';
$_SERVER['argv'][5] = 'DataProviderFilterTest';
$_SERVER['argv'][6] = dirname(__FILE__).'/../_files/DataProviderFilterTest.php';

require __DIR__ . '/../bootstrap.php';
PHPUnit_TextUI_Command::main();
?>
--EXPECTF--
PHPUnit %s by Sebastian Bergmann.

...

Time: %s, Memory: %sMb

OK (3 tests, 3 assertions)
23 changes: 23 additions & 0 deletions Tests/TextUI/filter-dataprovider-by-only-range.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
phpunit --filter \#1-3 DataProviderFilterTest ../_files/DataProviderFilterTest.php
--FILE--
<?php
define('PHPUNIT_TESTSUITE', TRUE);

$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--filter';
$_SERVER['argv'][3] = '#1-3';
$_SERVER['argv'][4] = 'DataProviderFilterTest';
$_SERVER['argv'][5] = dirname(__FILE__).'/../_files/DataProviderFilterTest.php';

require __DIR__ . '/../bootstrap.php';
PHPUnit_TextUI_Command::main();
?>
--EXPECTF--
PHPUnit %s by Sebastian Bergmann.

...

Time: %s, Memory: %sMb

OK (3 tests, 3 assertions)
24 changes: 24 additions & 0 deletions Tests/TextUI/filter-dataprovider-by-only-regexp-isolation.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
phpunit --process-isolation --filter @false.* DataProviderFilterTest ../_files/DataProviderFilterTest.php
--FILE--
<?php
define('PHPUNIT_TESTSUITE', TRUE);

$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--process-isolation';
$_SERVER['argv'][3] = '--filter';
$_SERVER['argv'][4] = '@false.*';
$_SERVER['argv'][5] = 'DataProviderFilterTest';
$_SERVER['argv'][6] = dirname(__FILE__).'/../_files/DataProviderFilterTest.php';

require __DIR__ . '/../bootstrap.php';
PHPUnit_TextUI_Command::main();
?>
--EXPECTF--
PHPUnit %s by Sebastian Bergmann.

..

Time: %s, Memory: %sMb

OK (2 tests, 2 assertions)
23 changes: 23 additions & 0 deletions Tests/TextUI/filter-dataprovider-by-only-regexp.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
phpunit --filter @false.* DataProviderFilterTest ../_files/DataProviderFilterTest.php
--FILE--
<?php
define('PHPUNIT_TESTSUITE', TRUE);

$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--filter';
$_SERVER['argv'][3] = '@false.*';
$_SERVER['argv'][4] = 'DataProviderFilterTest';
$_SERVER['argv'][5] = dirname(__FILE__).'/../_files/DataProviderFilterTest.php';

require __DIR__ . '/../bootstrap.php';
PHPUnit_TextUI_Command::main();
?>
--EXPECTF--
PHPUnit %s by Sebastian Bergmann.

..

Time: %s, Memory: %sMb

OK (2 tests, 2 assertions)
24 changes: 24 additions & 0 deletions Tests/TextUI/filter-dataprovider-by-only-string-isolation.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
phpunit --process-isolation --filter @false\ test DataProviderFilterTest ../_files/DataProviderFilterTest.php
--FILE--
<?php
define('PHPUNIT_TESTSUITE', TRUE);

$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--process-isolation';
$_SERVER['argv'][3] = '--filter';
$_SERVER['argv'][4] = '@false test';
$_SERVER['argv'][5] = 'DataProviderFilterTest';
$_SERVER['argv'][6] = dirname(__FILE__).'/../_files/DataProviderFilterTest.php';

require __DIR__ . '/../bootstrap.php';
PHPUnit_TextUI_Command::main();
?>
--EXPECTF--
PHPUnit %s by Sebastian Bergmann.

.

Time: %s, Memory: %sMb

OK (1 test, 1 assertion)
23 changes: 23 additions & 0 deletions Tests/TextUI/filter-dataprovider-by-only-string.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
phpunit --filter @false\ test DataProviderFilterTest ../_files/DataProviderFilterTest.php
--FILE--
<?php
define('PHPUNIT_TESTSUITE', TRUE);

$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--filter';
$_SERVER['argv'][3] = '@false test';
$_SERVER['argv'][4] = 'DataProviderFilterTest';
$_SERVER['argv'][5] = dirname(__FILE__).'/../_files/DataProviderFilterTest.php';

require __DIR__ . '/../bootstrap.php';
PHPUnit_TextUI_Command::main();
?>
--EXPECTF--
PHPUnit %s by Sebastian Bergmann.

.

Time: %s, Memory: %sMb

OK (1 test, 1 assertion)

0 comments on commit 41c7255

Please sign in to comment.