3 * This file is part of PHPUnit.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * @since Class available since Release 4.0.0
14 class PHPUnit_Runner_Filter_Test extends RecursiveFilterIterator
19 protected $filter = null;
31 * @param RecursiveIterator $iterator
32 * @param string $filter
34 public function __construct(RecursiveIterator $iterator, $filter)
36 parent::__construct($iterator);
37 $this->setFilter($filter);
41 * @param string $filter
43 protected function setFilter($filter)
45 if (PHPUnit_Util_Regex::pregMatchSafe($filter, '') === false) {
47 // * testAssertEqualsSucceeds#4
48 // * testAssertEqualsSucceeds#4-8
49 if (preg_match('/^(.*?)#(\d+)(?:-(\d+))?$/', $filter, $matches)) {
50 if (isset($matches[3]) && $matches[2] < $matches[3]) {
52 '%s.*with data set #(\d+)$',
56 $this->filterMin = $matches[2];
57 $this->filterMax = $matches[3];
60 '%s.*with data set #%s$',
66 // * testDetermineJsonError@JSON_ERROR_NONE
67 // * testDetermineJsonError@JSON.*
68 elseif (preg_match('/^(.*?)@(.+)$/', $filter, $matches)) {
70 '%s.*with data set "%s"$',
76 // Escape delimiters in regular expression. Do NOT use preg_quote,
77 // to keep magic characters.
78 $filter = sprintf('/%s/', str_replace(
85 $this->filter = $filter;
91 public function accept()
93 $test = $this->getInnerIterator()->current();
95 if ($test instanceof PHPUnit_Framework_TestSuite) {
99 $tmp = PHPUnit_Util_Test::describe($test, false);
102 $name = implode('::', $tmp);
107 $accepted = @preg_match($this->filter, $name, $matches);
109 if ($accepted && isset($this->filterMax)) {
110 $set = end($matches);
111 $accepted = $set >= $this->filterMin && $set <= $this->filterMax;