Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / phpunit / phpunit / src / Runner / Filter / Test.php
1 <?php
2 /*
3  * This file is part of PHPUnit.
4  *
5  * (c) Sebastian Bergmann <sebastian@phpunit.de>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * @since Class available since Release 4.0.0
13  */
14 class PHPUnit_Runner_Filter_Test extends RecursiveFilterIterator
15 {
16     /**
17      * @var string
18      */
19     protected $filter = null;
20
21     /**
22      * @var int
23      */
24     protected $filterMin;
25     /**
26      * @var int
27      */
28     protected $filterMax;
29
30     /**
31      * @param RecursiveIterator $iterator
32      * @param string            $filter
33      */
34     public function __construct(RecursiveIterator $iterator, $filter)
35     {
36         parent::__construct($iterator);
37         $this->setFilter($filter);
38     }
39
40     /**
41      * @param string $filter
42      */
43     protected function setFilter($filter)
44     {
45         if (PHPUnit_Util_Regex::pregMatchSafe($filter, '') === false) {
46             // Handles:
47             //  * testAssertEqualsSucceeds#4
48             //  * testAssertEqualsSucceeds#4-8
49             if (preg_match('/^(.*?)#(\d+)(?:-(\d+))?$/', $filter, $matches)) {
50                 if (isset($matches[3]) && $matches[2] < $matches[3]) {
51                     $filter = sprintf(
52                         '%s.*with data set #(\d+)$',
53                         $matches[1]
54                     );
55
56                     $this->filterMin = $matches[2];
57                     $this->filterMax = $matches[3];
58                 } else {
59                     $filter = sprintf(
60                         '%s.*with data set #%s$',
61                         $matches[1],
62                         $matches[2]
63                     );
64                 }
65             } // Handles:
66             //  * testDetermineJsonError@JSON_ERROR_NONE
67             //  * testDetermineJsonError@JSON.*
68             elseif (preg_match('/^(.*?)@(.+)$/', $filter, $matches)) {
69                 $filter = sprintf(
70                     '%s.*with data set "%s"$',
71                     $matches[1],
72                     $matches[2]
73                 );
74             }
75
76             // Escape delimiters in regular expression. Do NOT use preg_quote,
77             // to keep magic characters.
78             $filter = sprintf('/%s/', str_replace(
79                 '/',
80                 '\\/',
81                 $filter
82             ));
83         }
84
85         $this->filter = $filter;
86     }
87
88     /**
89      * @return bool
90      */
91     public function accept()
92     {
93         $test = $this->getInnerIterator()->current();
94
95         if ($test instanceof PHPUnit_Framework_TestSuite) {
96             return true;
97         }
98
99         $tmp = PHPUnit_Util_Test::describe($test, false);
100
101         if ($tmp[0] != '') {
102             $name = implode('::', $tmp);
103         } else {
104             $name = $tmp[1];
105         }
106
107         $accepted = @preg_match($this->filter, $name, $matches);
108
109         if ($accepted && isset($this->filterMax)) {
110             $set      = end($matches);
111             $accepted = $set >= $this->filterMin && $set <= $this->filterMax;
112         }
113
114         return $accepted;
115     }
116 }