@@ -17,91 +17,91 @@ |
||
17 | 17 | */ |
18 | 18 | class Filter |
19 | 19 | { |
20 | - /** |
|
21 | - * Filters stack frames from PHPUnit classes. |
|
22 | - * |
|
23 | - * @param \Throwable $e |
|
24 | - * @param bool $asString |
|
25 | - * |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public static function getFilteredStacktrace($e, $asString = true) |
|
29 | - { |
|
30 | - $prefix = false; |
|
31 | - $script = \realpath($GLOBALS['_SERVER']['SCRIPT_NAME']); |
|
20 | + /** |
|
21 | + * Filters stack frames from PHPUnit classes. |
|
22 | + * |
|
23 | + * @param \Throwable $e |
|
24 | + * @param bool $asString |
|
25 | + * |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public static function getFilteredStacktrace($e, $asString = true) |
|
29 | + { |
|
30 | + $prefix = false; |
|
31 | + $script = \realpath($GLOBALS['_SERVER']['SCRIPT_NAME']); |
|
32 | 32 | |
33 | - if (\defined('__PHPUNIT_PHAR_ROOT__')) { |
|
34 | - $prefix = __PHPUNIT_PHAR_ROOT__; |
|
35 | - } |
|
33 | + if (\defined('__PHPUNIT_PHAR_ROOT__')) { |
|
34 | + $prefix = __PHPUNIT_PHAR_ROOT__; |
|
35 | + } |
|
36 | 36 | |
37 | - if ($asString === true) { |
|
38 | - $filteredStacktrace = ''; |
|
39 | - } else { |
|
40 | - $filteredStacktrace = []; |
|
41 | - } |
|
37 | + if ($asString === true) { |
|
38 | + $filteredStacktrace = ''; |
|
39 | + } else { |
|
40 | + $filteredStacktrace = []; |
|
41 | + } |
|
42 | 42 | |
43 | - if ($e instanceof SyntheticError) { |
|
44 | - $eTrace = $e->getSyntheticTrace(); |
|
45 | - $eFile = $e->getSyntheticFile(); |
|
46 | - $eLine = $e->getSyntheticLine(); |
|
47 | - } elseif ($e instanceof Exception) { |
|
48 | - $eTrace = $e->getSerializableTrace(); |
|
49 | - $eFile = $e->getFile(); |
|
50 | - $eLine = $e->getLine(); |
|
51 | - } else { |
|
52 | - if ($e->getPrevious()) { |
|
53 | - $e = $e->getPrevious(); |
|
54 | - } |
|
55 | - $eTrace = $e->getTrace(); |
|
56 | - $eFile = $e->getFile(); |
|
57 | - $eLine = $e->getLine(); |
|
58 | - } |
|
43 | + if ($e instanceof SyntheticError) { |
|
44 | + $eTrace = $e->getSyntheticTrace(); |
|
45 | + $eFile = $e->getSyntheticFile(); |
|
46 | + $eLine = $e->getSyntheticLine(); |
|
47 | + } elseif ($e instanceof Exception) { |
|
48 | + $eTrace = $e->getSerializableTrace(); |
|
49 | + $eFile = $e->getFile(); |
|
50 | + $eLine = $e->getLine(); |
|
51 | + } else { |
|
52 | + if ($e->getPrevious()) { |
|
53 | + $e = $e->getPrevious(); |
|
54 | + } |
|
55 | + $eTrace = $e->getTrace(); |
|
56 | + $eFile = $e->getFile(); |
|
57 | + $eLine = $e->getLine(); |
|
58 | + } |
|
59 | 59 | |
60 | - if (!self::frameExists($eTrace, $eFile, $eLine)) { |
|
61 | - \array_unshift( |
|
62 | - $eTrace, |
|
63 | - ['file' => $eFile, 'line' => $eLine] |
|
64 | - ); |
|
65 | - } |
|
60 | + if (!self::frameExists($eTrace, $eFile, $eLine)) { |
|
61 | + \array_unshift( |
|
62 | + $eTrace, |
|
63 | + ['file' => $eFile, 'line' => $eLine] |
|
64 | + ); |
|
65 | + } |
|
66 | 66 | |
67 | - $blacklist = new Blacklist; |
|
67 | + $blacklist = new Blacklist; |
|
68 | 68 | |
69 | - foreach ($eTrace as $frame) { |
|
70 | - if (isset($frame['file']) && \is_file($frame['file']) && |
|
71 | - !$blacklist->isBlacklisted($frame['file']) && |
|
72 | - ($prefix === false || \strpos($frame['file'], $prefix) !== 0) && |
|
73 | - $frame['file'] !== $script) { |
|
74 | - if ($asString === true) { |
|
75 | - $filteredStacktrace .= \sprintf( |
|
76 | - "%s:%s\n", |
|
77 | - $frame['file'], |
|
78 | - $frame['line'] ?? '?' |
|
79 | - ); |
|
80 | - } else { |
|
81 | - $filteredStacktrace[] = $frame; |
|
82 | - } |
|
83 | - } |
|
84 | - } |
|
69 | + foreach ($eTrace as $frame) { |
|
70 | + if (isset($frame['file']) && \is_file($frame['file']) && |
|
71 | + !$blacklist->isBlacklisted($frame['file']) && |
|
72 | + ($prefix === false || \strpos($frame['file'], $prefix) !== 0) && |
|
73 | + $frame['file'] !== $script) { |
|
74 | + if ($asString === true) { |
|
75 | + $filteredStacktrace .= \sprintf( |
|
76 | + "%s:%s\n", |
|
77 | + $frame['file'], |
|
78 | + $frame['line'] ?? '?' |
|
79 | + ); |
|
80 | + } else { |
|
81 | + $filteredStacktrace[] = $frame; |
|
82 | + } |
|
83 | + } |
|
84 | + } |
|
85 | 85 | |
86 | - return $filteredStacktrace; |
|
87 | - } |
|
86 | + return $filteredStacktrace; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @param array $trace |
|
91 | - * @param string $file |
|
92 | - * @param int $line |
|
93 | - * |
|
94 | - * @return bool |
|
95 | - */ |
|
96 | - private static function frameExists(array $trace, $file, $line) |
|
97 | - { |
|
98 | - foreach ($trace as $frame) { |
|
99 | - if (isset($frame['file']) && $frame['file'] == $file && |
|
100 | - isset($frame['line']) && $frame['line'] == $line) { |
|
101 | - return true; |
|
102 | - } |
|
103 | - } |
|
89 | + /** |
|
90 | + * @param array $trace |
|
91 | + * @param string $file |
|
92 | + * @param int $line |
|
93 | + * |
|
94 | + * @return bool |
|
95 | + */ |
|
96 | + private static function frameExists(array $trace, $file, $line) |
|
97 | + { |
|
98 | + foreach ($trace as $frame) { |
|
99 | + if (isset($frame['file']) && $frame['file'] == $file && |
|
100 | + isset($frame['line']) && $frame['line'] == $line) { |
|
101 | + return true; |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | - return false; |
|
106 | - } |
|
105 | + return false; |
|
106 | + } |
|
107 | 107 | } |
@@ -17,97 +17,97 @@ |
||
17 | 17 | */ |
18 | 18 | class Blacklist |
19 | 19 | { |
20 | - /** |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - public static $blacklistedClassNames = [ |
|
24 | - 'File_Iterator' => 1, |
|
25 | - 'PHP_Invoker' => 1, |
|
26 | - 'PHP_Timer' => 1, |
|
27 | - 'PHP_Token' => 1, |
|
28 | - 'PHPUnit\Framework\TestCase' => 2, |
|
29 | - 'PHPUnit\DbUnit\TestCase' => 2, |
|
30 | - 'PHPUnit_Framework_MockObject_Generator' => 1, |
|
31 | - 'Text_Template' => 1, |
|
32 | - 'Symfony\Component\Yaml\Yaml' => 1, |
|
33 | - 'SebastianBergmann\CodeCoverage\CodeCoverage' => 1, |
|
34 | - 'SebastianBergmann\Diff\Diff' => 1, |
|
35 | - 'SebastianBergmann\Environment\Runtime' => 1, |
|
36 | - 'SebastianBergmann\Comparator\Comparator' => 1, |
|
37 | - 'SebastianBergmann\Exporter\Exporter' => 1, |
|
38 | - 'SebastianBergmann\GlobalState\Snapshot' => 1, |
|
39 | - 'SebastianBergmann\RecursionContext\Context' => 1, |
|
40 | - 'SebastianBergmann\Version' => 1, |
|
41 | - 'Composer\Autoload\ClassLoader' => 1, |
|
42 | - 'Doctrine\Instantiator\Instantiator' => 1, |
|
43 | - 'phpDocumentor\Reflection\DocBlock' => 1, |
|
44 | - 'Prophecy\Prophet' => 1, |
|
45 | - 'DeepCopy\DeepCopy' => 1 |
|
46 | - ]; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string[] |
|
50 | - */ |
|
51 | - private static $directories; |
|
52 | - |
|
53 | - /** |
|
54 | - * @return string[] |
|
55 | - */ |
|
56 | - public function getBlacklistedDirectories() |
|
57 | - { |
|
58 | - $this->initialize(); |
|
59 | - |
|
60 | - return self::$directories; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * @param string $file |
|
65 | - * |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function isBlacklisted($file) |
|
69 | - { |
|
70 | - if (\defined('PHPUNIT_TESTSUITE')) { |
|
71 | - return false; |
|
72 | - } |
|
73 | - |
|
74 | - $this->initialize(); |
|
75 | - |
|
76 | - foreach (self::$directories as $directory) { |
|
77 | - if (\strpos($file, $directory) === 0) { |
|
78 | - return true; |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - return false; |
|
83 | - } |
|
84 | - |
|
85 | - private function initialize() |
|
86 | - { |
|
87 | - if (self::$directories === null) { |
|
88 | - self::$directories = []; |
|
89 | - |
|
90 | - foreach (self::$blacklistedClassNames as $className => $parent) { |
|
91 | - if (!\class_exists($className)) { |
|
92 | - continue; |
|
93 | - } |
|
94 | - |
|
95 | - $reflector = new ReflectionClass($className); |
|
96 | - $directory = $reflector->getFileName(); |
|
97 | - |
|
98 | - for ($i = 0; $i < $parent; $i++) { |
|
99 | - $directory = \dirname($directory); |
|
100 | - } |
|
101 | - |
|
102 | - self::$directories[] = $directory; |
|
103 | - } |
|
104 | - |
|
105 | - // Hide process isolation workaround on Windows. |
|
106 | - if (DIRECTORY_SEPARATOR === '\\') { |
|
107 | - // tempnam() prefix is limited to first 3 chars. |
|
108 | - // @see http://php.net/manual/en/function.tempnam.php |
|
109 | - self::$directories[] = \sys_get_temp_dir() . '\\PHP'; |
|
110 | - } |
|
111 | - } |
|
112 | - } |
|
20 | + /** |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + public static $blacklistedClassNames = [ |
|
24 | + 'File_Iterator' => 1, |
|
25 | + 'PHP_Invoker' => 1, |
|
26 | + 'PHP_Timer' => 1, |
|
27 | + 'PHP_Token' => 1, |
|
28 | + 'PHPUnit\Framework\TestCase' => 2, |
|
29 | + 'PHPUnit\DbUnit\TestCase' => 2, |
|
30 | + 'PHPUnit_Framework_MockObject_Generator' => 1, |
|
31 | + 'Text_Template' => 1, |
|
32 | + 'Symfony\Component\Yaml\Yaml' => 1, |
|
33 | + 'SebastianBergmann\CodeCoverage\CodeCoverage' => 1, |
|
34 | + 'SebastianBergmann\Diff\Diff' => 1, |
|
35 | + 'SebastianBergmann\Environment\Runtime' => 1, |
|
36 | + 'SebastianBergmann\Comparator\Comparator' => 1, |
|
37 | + 'SebastianBergmann\Exporter\Exporter' => 1, |
|
38 | + 'SebastianBergmann\GlobalState\Snapshot' => 1, |
|
39 | + 'SebastianBergmann\RecursionContext\Context' => 1, |
|
40 | + 'SebastianBergmann\Version' => 1, |
|
41 | + 'Composer\Autoload\ClassLoader' => 1, |
|
42 | + 'Doctrine\Instantiator\Instantiator' => 1, |
|
43 | + 'phpDocumentor\Reflection\DocBlock' => 1, |
|
44 | + 'Prophecy\Prophet' => 1, |
|
45 | + 'DeepCopy\DeepCopy' => 1 |
|
46 | + ]; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string[] |
|
50 | + */ |
|
51 | + private static $directories; |
|
52 | + |
|
53 | + /** |
|
54 | + * @return string[] |
|
55 | + */ |
|
56 | + public function getBlacklistedDirectories() |
|
57 | + { |
|
58 | + $this->initialize(); |
|
59 | + |
|
60 | + return self::$directories; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * @param string $file |
|
65 | + * |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function isBlacklisted($file) |
|
69 | + { |
|
70 | + if (\defined('PHPUNIT_TESTSUITE')) { |
|
71 | + return false; |
|
72 | + } |
|
73 | + |
|
74 | + $this->initialize(); |
|
75 | + |
|
76 | + foreach (self::$directories as $directory) { |
|
77 | + if (\strpos($file, $directory) === 0) { |
|
78 | + return true; |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + return false; |
|
83 | + } |
|
84 | + |
|
85 | + private function initialize() |
|
86 | + { |
|
87 | + if (self::$directories === null) { |
|
88 | + self::$directories = []; |
|
89 | + |
|
90 | + foreach (self::$blacklistedClassNames as $className => $parent) { |
|
91 | + if (!\class_exists($className)) { |
|
92 | + continue; |
|
93 | + } |
|
94 | + |
|
95 | + $reflector = new ReflectionClass($className); |
|
96 | + $directory = $reflector->getFileName(); |
|
97 | + |
|
98 | + for ($i = 0; $i < $parent; $i++) { |
|
99 | + $directory = \dirname($directory); |
|
100 | + } |
|
101 | + |
|
102 | + self::$directories[] = $directory; |
|
103 | + } |
|
104 | + |
|
105 | + // Hide process isolation workaround on Windows. |
|
106 | + if (DIRECTORY_SEPARATOR === '\\') { |
|
107 | + // tempnam() prefix is limited to first 3 chars. |
|
108 | + // @see http://php.net/manual/en/function.tempnam.php |
|
109 | + self::$directories[] = \sys_get_temp_dir() . '\\PHP'; |
|
110 | + } |
|
111 | + } |
|
112 | + } |
|
113 | 113 | } |
@@ -106,7 +106,7 @@ |
||
106 | 106 | if (DIRECTORY_SEPARATOR === '\\') { |
107 | 107 | // tempnam() prefix is limited to first 3 chars. |
108 | 108 | // @see http://php.net/manual/en/function.tempnam.php |
109 | - self::$directories[] = \sys_get_temp_dir() . '\\PHP'; |
|
109 | + self::$directories[] = \sys_get_temp_dir().'\\PHP'; |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | } |
@@ -22,293 +22,293 @@ |
||
22 | 22 | */ |
23 | 23 | class Xml |
24 | 24 | { |
25 | - /** |
|
26 | - * Load an $actual document into a DOMDocument. This is called |
|
27 | - * from the selector assertions. |
|
28 | - * |
|
29 | - * If $actual is already a DOMDocument, it is returned with |
|
30 | - * no changes. Otherwise, $actual is loaded into a new DOMDocument |
|
31 | - * as either HTML or XML, depending on the value of $isHtml. If $isHtml is |
|
32 | - * false and $xinclude is true, xinclude is performed on the loaded |
|
33 | - * DOMDocument. |
|
34 | - * |
|
35 | - * Note: prior to PHPUnit 3.3.0, this method loaded a file and |
|
36 | - * not a string as it currently does. To load a file into a |
|
37 | - * DOMDocument, use loadFile() instead. |
|
38 | - * |
|
39 | - * @param string|DOMDocument $actual |
|
40 | - * @param bool $isHtml |
|
41 | - * @param string $filename |
|
42 | - * @param bool $xinclude |
|
43 | - * @param bool $strict |
|
44 | - * |
|
45 | - * @return DOMDocument |
|
46 | - */ |
|
47 | - public static function load($actual, $isHtml = false, $filename = '', $xinclude = false, $strict = false) |
|
48 | - { |
|
49 | - if ($actual instanceof DOMDocument) { |
|
50 | - return $actual; |
|
51 | - } |
|
52 | - |
|
53 | - if (!\is_string($actual)) { |
|
54 | - throw new Exception('Could not load XML from ' . \gettype($actual)); |
|
55 | - } |
|
56 | - |
|
57 | - if ($actual === '') { |
|
58 | - throw new Exception('Could not load XML from empty string'); |
|
59 | - } |
|
60 | - |
|
61 | - // Required for XInclude on Windows. |
|
62 | - if ($xinclude) { |
|
63 | - $cwd = \getcwd(); |
|
64 | - @\chdir(\dirname($filename)); |
|
65 | - } |
|
66 | - |
|
67 | - $document = new DOMDocument; |
|
68 | - $document->preserveWhiteSpace = false; |
|
69 | - |
|
70 | - $internal = \libxml_use_internal_errors(true); |
|
71 | - $message = ''; |
|
72 | - $reporting = \error_reporting(0); |
|
73 | - |
|
74 | - if ('' !== $filename) { |
|
75 | - // Necessary for xinclude |
|
76 | - $document->documentURI = $filename; |
|
77 | - } |
|
78 | - |
|
79 | - if ($isHtml) { |
|
80 | - $loaded = $document->loadHTML($actual); |
|
81 | - } else { |
|
82 | - $loaded = $document->loadXML($actual); |
|
83 | - } |
|
84 | - |
|
85 | - if (!$isHtml && $xinclude) { |
|
86 | - $document->xinclude(); |
|
87 | - } |
|
88 | - |
|
89 | - foreach (\libxml_get_errors() as $error) { |
|
90 | - $message .= "\n" . $error->message; |
|
91 | - } |
|
92 | - |
|
93 | - \libxml_use_internal_errors($internal); |
|
94 | - \error_reporting($reporting); |
|
95 | - |
|
96 | - if (isset($cwd)) { |
|
97 | - @\chdir($cwd); |
|
98 | - } |
|
99 | - |
|
100 | - if ($loaded === false || ($strict && $message !== '')) { |
|
101 | - if ($filename !== '') { |
|
102 | - throw new Exception( |
|
103 | - \sprintf( |
|
104 | - 'Could not load "%s".%s', |
|
105 | - $filename, |
|
106 | - $message != '' ? "\n" . $message : '' |
|
107 | - ) |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - if ($message === '') { |
|
112 | - $message = 'Could not load XML for unknown reason'; |
|
113 | - } |
|
114 | - |
|
115 | - throw new Exception($message); |
|
116 | - } |
|
117 | - |
|
118 | - return $document; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Loads an XML (or HTML) file into a DOMDocument object. |
|
123 | - * |
|
124 | - * @param string $filename |
|
125 | - * @param bool $isHtml |
|
126 | - * @param bool $xinclude |
|
127 | - * @param bool $strict |
|
128 | - * |
|
129 | - * @return DOMDocument |
|
130 | - */ |
|
131 | - public static function loadFile($filename, $isHtml = false, $xinclude = false, $strict = false) |
|
132 | - { |
|
133 | - $reporting = \error_reporting(0); |
|
134 | - $contents = \file_get_contents($filename); |
|
135 | - \error_reporting($reporting); |
|
136 | - |
|
137 | - if ($contents === false) { |
|
138 | - throw new Exception( |
|
139 | - \sprintf( |
|
140 | - 'Could not read "%s".', |
|
141 | - $filename |
|
142 | - ) |
|
143 | - ); |
|
144 | - } |
|
145 | - |
|
146 | - return self::load($contents, $isHtml, $filename, $xinclude, $strict); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @param DOMNode $node |
|
151 | - */ |
|
152 | - public static function removeCharacterDataNodes(DOMNode $node) |
|
153 | - { |
|
154 | - if ($node->hasChildNodes()) { |
|
155 | - for ($i = $node->childNodes->length - 1; $i >= 0; $i--) { |
|
156 | - if (($child = $node->childNodes->item($i)) instanceof DOMCharacterData) { |
|
157 | - $node->removeChild($child); |
|
158 | - } |
|
159 | - } |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Escapes a string for the use in XML documents |
|
165 | - * Any Unicode character is allowed, excluding the surrogate blocks, FFFE, |
|
166 | - * and FFFF (not even as character reference). |
|
167 | - * See http://www.w3.org/TR/xml/#charsets |
|
168 | - * |
|
169 | - * @param string $string |
|
170 | - * |
|
171 | - * @return string |
|
172 | - */ |
|
173 | - public static function prepareString($string) |
|
174 | - { |
|
175 | - return \preg_replace( |
|
176 | - '/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]/', |
|
177 | - '', |
|
178 | - \htmlspecialchars( |
|
179 | - self::convertToUtf8($string), |
|
180 | - ENT_QUOTES, |
|
181 | - 'UTF-8' |
|
182 | - ) |
|
183 | - ); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * "Convert" a DOMElement object into a PHP variable. |
|
188 | - * |
|
189 | - * @param DOMElement $element |
|
190 | - * |
|
191 | - * @return mixed |
|
192 | - */ |
|
193 | - public static function xmlToVariable(DOMElement $element) |
|
194 | - { |
|
195 | - $variable = null; |
|
196 | - |
|
197 | - switch ($element->tagName) { |
|
198 | - case 'array': |
|
199 | - $variable = []; |
|
200 | - |
|
201 | - foreach ($element->childNodes as $entry) { |
|
202 | - if (!$entry instanceof DOMElement || $entry->tagName !== 'element') { |
|
203 | - continue; |
|
204 | - } |
|
205 | - $item = $entry->childNodes->item(0); |
|
206 | - |
|
207 | - if ($item instanceof DOMText) { |
|
208 | - $item = $entry->childNodes->item(1); |
|
209 | - } |
|
210 | - |
|
211 | - $value = self::xmlToVariable($item); |
|
212 | - |
|
213 | - if ($entry->hasAttribute('key')) { |
|
214 | - $variable[(string) $entry->getAttribute('key')] = $value; |
|
215 | - } else { |
|
216 | - $variable[] = $value; |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - break; |
|
221 | - |
|
222 | - case 'object': |
|
223 | - $className = $element->getAttribute('class'); |
|
224 | - |
|
225 | - if ($element->hasChildNodes()) { |
|
226 | - $arguments = $element->childNodes->item(0)->childNodes; |
|
227 | - $constructorArgs = []; |
|
228 | - |
|
229 | - foreach ($arguments as $argument) { |
|
230 | - if ($argument instanceof DOMElement) { |
|
231 | - $constructorArgs[] = self::xmlToVariable($argument); |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - $class = new ReflectionClass($className); |
|
236 | - $variable = $class->newInstanceArgs($constructorArgs); |
|
237 | - } else { |
|
238 | - $variable = new $className; |
|
239 | - } |
|
240 | - |
|
241 | - break; |
|
242 | - |
|
243 | - case 'boolean': |
|
244 | - $variable = $element->textContent == 'true'; |
|
245 | - |
|
246 | - break; |
|
247 | - |
|
248 | - case 'integer': |
|
249 | - case 'double': |
|
250 | - case 'string': |
|
251 | - $variable = $element->textContent; |
|
252 | - |
|
253 | - \settype($variable, $element->tagName); |
|
254 | - |
|
255 | - break; |
|
256 | - } |
|
257 | - |
|
258 | - return $variable; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Converts a string to UTF-8 encoding. |
|
263 | - * |
|
264 | - * @param string $string |
|
265 | - * |
|
266 | - * @return string |
|
267 | - */ |
|
268 | - private static function convertToUtf8($string) |
|
269 | - { |
|
270 | - if (!self::isUtf8($string)) { |
|
271 | - if (\function_exists('mb_convert_encoding')) { |
|
272 | - return \mb_convert_encoding($string, 'UTF-8'); |
|
273 | - } |
|
274 | - |
|
275 | - return \utf8_encode($string); |
|
276 | - } |
|
277 | - |
|
278 | - return $string; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Checks a string for UTF-8 encoding. |
|
283 | - * |
|
284 | - * @param string $string |
|
285 | - * |
|
286 | - * @return bool |
|
287 | - */ |
|
288 | - private static function isUtf8($string) |
|
289 | - { |
|
290 | - $length = \strlen($string); |
|
291 | - |
|
292 | - for ($i = 0; $i < $length; $i++) { |
|
293 | - if (\ord($string[$i]) < 0x80) { |
|
294 | - $n = 0; |
|
295 | - } elseif ((\ord($string[$i]) & 0xE0) == 0xC0) { |
|
296 | - $n = 1; |
|
297 | - } elseif ((\ord($string[$i]) & 0xF0) == 0xE0) { |
|
298 | - $n = 2; |
|
299 | - } elseif ((\ord($string[$i]) & 0xF0) == 0xF0) { |
|
300 | - $n = 3; |
|
301 | - } else { |
|
302 | - return false; |
|
303 | - } |
|
304 | - |
|
305 | - for ($j = 0; $j < $n; $j++) { |
|
306 | - if ((++$i == $length) || ((\ord($string[$i]) & 0xC0) != 0x80)) { |
|
307 | - return false; |
|
308 | - } |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - return true; |
|
313 | - } |
|
25 | + /** |
|
26 | + * Load an $actual document into a DOMDocument. This is called |
|
27 | + * from the selector assertions. |
|
28 | + * |
|
29 | + * If $actual is already a DOMDocument, it is returned with |
|
30 | + * no changes. Otherwise, $actual is loaded into a new DOMDocument |
|
31 | + * as either HTML or XML, depending on the value of $isHtml. If $isHtml is |
|
32 | + * false and $xinclude is true, xinclude is performed on the loaded |
|
33 | + * DOMDocument. |
|
34 | + * |
|
35 | + * Note: prior to PHPUnit 3.3.0, this method loaded a file and |
|
36 | + * not a string as it currently does. To load a file into a |
|
37 | + * DOMDocument, use loadFile() instead. |
|
38 | + * |
|
39 | + * @param string|DOMDocument $actual |
|
40 | + * @param bool $isHtml |
|
41 | + * @param string $filename |
|
42 | + * @param bool $xinclude |
|
43 | + * @param bool $strict |
|
44 | + * |
|
45 | + * @return DOMDocument |
|
46 | + */ |
|
47 | + public static function load($actual, $isHtml = false, $filename = '', $xinclude = false, $strict = false) |
|
48 | + { |
|
49 | + if ($actual instanceof DOMDocument) { |
|
50 | + return $actual; |
|
51 | + } |
|
52 | + |
|
53 | + if (!\is_string($actual)) { |
|
54 | + throw new Exception('Could not load XML from ' . \gettype($actual)); |
|
55 | + } |
|
56 | + |
|
57 | + if ($actual === '') { |
|
58 | + throw new Exception('Could not load XML from empty string'); |
|
59 | + } |
|
60 | + |
|
61 | + // Required for XInclude on Windows. |
|
62 | + if ($xinclude) { |
|
63 | + $cwd = \getcwd(); |
|
64 | + @\chdir(\dirname($filename)); |
|
65 | + } |
|
66 | + |
|
67 | + $document = new DOMDocument; |
|
68 | + $document->preserveWhiteSpace = false; |
|
69 | + |
|
70 | + $internal = \libxml_use_internal_errors(true); |
|
71 | + $message = ''; |
|
72 | + $reporting = \error_reporting(0); |
|
73 | + |
|
74 | + if ('' !== $filename) { |
|
75 | + // Necessary for xinclude |
|
76 | + $document->documentURI = $filename; |
|
77 | + } |
|
78 | + |
|
79 | + if ($isHtml) { |
|
80 | + $loaded = $document->loadHTML($actual); |
|
81 | + } else { |
|
82 | + $loaded = $document->loadXML($actual); |
|
83 | + } |
|
84 | + |
|
85 | + if (!$isHtml && $xinclude) { |
|
86 | + $document->xinclude(); |
|
87 | + } |
|
88 | + |
|
89 | + foreach (\libxml_get_errors() as $error) { |
|
90 | + $message .= "\n" . $error->message; |
|
91 | + } |
|
92 | + |
|
93 | + \libxml_use_internal_errors($internal); |
|
94 | + \error_reporting($reporting); |
|
95 | + |
|
96 | + if (isset($cwd)) { |
|
97 | + @\chdir($cwd); |
|
98 | + } |
|
99 | + |
|
100 | + if ($loaded === false || ($strict && $message !== '')) { |
|
101 | + if ($filename !== '') { |
|
102 | + throw new Exception( |
|
103 | + \sprintf( |
|
104 | + 'Could not load "%s".%s', |
|
105 | + $filename, |
|
106 | + $message != '' ? "\n" . $message : '' |
|
107 | + ) |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + if ($message === '') { |
|
112 | + $message = 'Could not load XML for unknown reason'; |
|
113 | + } |
|
114 | + |
|
115 | + throw new Exception($message); |
|
116 | + } |
|
117 | + |
|
118 | + return $document; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Loads an XML (or HTML) file into a DOMDocument object. |
|
123 | + * |
|
124 | + * @param string $filename |
|
125 | + * @param bool $isHtml |
|
126 | + * @param bool $xinclude |
|
127 | + * @param bool $strict |
|
128 | + * |
|
129 | + * @return DOMDocument |
|
130 | + */ |
|
131 | + public static function loadFile($filename, $isHtml = false, $xinclude = false, $strict = false) |
|
132 | + { |
|
133 | + $reporting = \error_reporting(0); |
|
134 | + $contents = \file_get_contents($filename); |
|
135 | + \error_reporting($reporting); |
|
136 | + |
|
137 | + if ($contents === false) { |
|
138 | + throw new Exception( |
|
139 | + \sprintf( |
|
140 | + 'Could not read "%s".', |
|
141 | + $filename |
|
142 | + ) |
|
143 | + ); |
|
144 | + } |
|
145 | + |
|
146 | + return self::load($contents, $isHtml, $filename, $xinclude, $strict); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @param DOMNode $node |
|
151 | + */ |
|
152 | + public static function removeCharacterDataNodes(DOMNode $node) |
|
153 | + { |
|
154 | + if ($node->hasChildNodes()) { |
|
155 | + for ($i = $node->childNodes->length - 1; $i >= 0; $i--) { |
|
156 | + if (($child = $node->childNodes->item($i)) instanceof DOMCharacterData) { |
|
157 | + $node->removeChild($child); |
|
158 | + } |
|
159 | + } |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Escapes a string for the use in XML documents |
|
165 | + * Any Unicode character is allowed, excluding the surrogate blocks, FFFE, |
|
166 | + * and FFFF (not even as character reference). |
|
167 | + * See http://www.w3.org/TR/xml/#charsets |
|
168 | + * |
|
169 | + * @param string $string |
|
170 | + * |
|
171 | + * @return string |
|
172 | + */ |
|
173 | + public static function prepareString($string) |
|
174 | + { |
|
175 | + return \preg_replace( |
|
176 | + '/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]/', |
|
177 | + '', |
|
178 | + \htmlspecialchars( |
|
179 | + self::convertToUtf8($string), |
|
180 | + ENT_QUOTES, |
|
181 | + 'UTF-8' |
|
182 | + ) |
|
183 | + ); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * "Convert" a DOMElement object into a PHP variable. |
|
188 | + * |
|
189 | + * @param DOMElement $element |
|
190 | + * |
|
191 | + * @return mixed |
|
192 | + */ |
|
193 | + public static function xmlToVariable(DOMElement $element) |
|
194 | + { |
|
195 | + $variable = null; |
|
196 | + |
|
197 | + switch ($element->tagName) { |
|
198 | + case 'array': |
|
199 | + $variable = []; |
|
200 | + |
|
201 | + foreach ($element->childNodes as $entry) { |
|
202 | + if (!$entry instanceof DOMElement || $entry->tagName !== 'element') { |
|
203 | + continue; |
|
204 | + } |
|
205 | + $item = $entry->childNodes->item(0); |
|
206 | + |
|
207 | + if ($item instanceof DOMText) { |
|
208 | + $item = $entry->childNodes->item(1); |
|
209 | + } |
|
210 | + |
|
211 | + $value = self::xmlToVariable($item); |
|
212 | + |
|
213 | + if ($entry->hasAttribute('key')) { |
|
214 | + $variable[(string) $entry->getAttribute('key')] = $value; |
|
215 | + } else { |
|
216 | + $variable[] = $value; |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + break; |
|
221 | + |
|
222 | + case 'object': |
|
223 | + $className = $element->getAttribute('class'); |
|
224 | + |
|
225 | + if ($element->hasChildNodes()) { |
|
226 | + $arguments = $element->childNodes->item(0)->childNodes; |
|
227 | + $constructorArgs = []; |
|
228 | + |
|
229 | + foreach ($arguments as $argument) { |
|
230 | + if ($argument instanceof DOMElement) { |
|
231 | + $constructorArgs[] = self::xmlToVariable($argument); |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + $class = new ReflectionClass($className); |
|
236 | + $variable = $class->newInstanceArgs($constructorArgs); |
|
237 | + } else { |
|
238 | + $variable = new $className; |
|
239 | + } |
|
240 | + |
|
241 | + break; |
|
242 | + |
|
243 | + case 'boolean': |
|
244 | + $variable = $element->textContent == 'true'; |
|
245 | + |
|
246 | + break; |
|
247 | + |
|
248 | + case 'integer': |
|
249 | + case 'double': |
|
250 | + case 'string': |
|
251 | + $variable = $element->textContent; |
|
252 | + |
|
253 | + \settype($variable, $element->tagName); |
|
254 | + |
|
255 | + break; |
|
256 | + } |
|
257 | + |
|
258 | + return $variable; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Converts a string to UTF-8 encoding. |
|
263 | + * |
|
264 | + * @param string $string |
|
265 | + * |
|
266 | + * @return string |
|
267 | + */ |
|
268 | + private static function convertToUtf8($string) |
|
269 | + { |
|
270 | + if (!self::isUtf8($string)) { |
|
271 | + if (\function_exists('mb_convert_encoding')) { |
|
272 | + return \mb_convert_encoding($string, 'UTF-8'); |
|
273 | + } |
|
274 | + |
|
275 | + return \utf8_encode($string); |
|
276 | + } |
|
277 | + |
|
278 | + return $string; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Checks a string for UTF-8 encoding. |
|
283 | + * |
|
284 | + * @param string $string |
|
285 | + * |
|
286 | + * @return bool |
|
287 | + */ |
|
288 | + private static function isUtf8($string) |
|
289 | + { |
|
290 | + $length = \strlen($string); |
|
291 | + |
|
292 | + for ($i = 0; $i < $length; $i++) { |
|
293 | + if (\ord($string[$i]) < 0x80) { |
|
294 | + $n = 0; |
|
295 | + } elseif ((\ord($string[$i]) & 0xE0) == 0xC0) { |
|
296 | + $n = 1; |
|
297 | + } elseif ((\ord($string[$i]) & 0xF0) == 0xE0) { |
|
298 | + $n = 2; |
|
299 | + } elseif ((\ord($string[$i]) & 0xF0) == 0xF0) { |
|
300 | + $n = 3; |
|
301 | + } else { |
|
302 | + return false; |
|
303 | + } |
|
304 | + |
|
305 | + for ($j = 0; $j < $n; $j++) { |
|
306 | + if ((++$i == $length) || ((\ord($string[$i]) & 0xC0) != 0x80)) { |
|
307 | + return false; |
|
308 | + } |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + return true; |
|
313 | + } |
|
314 | 314 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | } |
52 | 52 | |
53 | 53 | if (!\is_string($actual)) { |
54 | - throw new Exception('Could not load XML from ' . \gettype($actual)); |
|
54 | + throw new Exception('Could not load XML from '.\gettype($actual)); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | if ($actual === '') { |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | foreach (\libxml_get_errors() as $error) { |
90 | - $message .= "\n" . $error->message; |
|
90 | + $message .= "\n".$error->message; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | \libxml_use_internal_errors($internal); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | \sprintf( |
104 | 104 | 'Could not load "%s".%s', |
105 | 105 | $filename, |
106 | - $message != '' ? "\n" . $message : '' |
|
106 | + $message != '' ? "\n".$message : '' |
|
107 | 107 | ) |
108 | 108 | ); |
109 | 109 | } |
@@ -17,26 +17,26 @@ |
||
17 | 17 | */ |
18 | 18 | class InvalidArgumentHelper |
19 | 19 | { |
20 | - /** |
|
21 | - * @param int $argument |
|
22 | - * @param string $type |
|
23 | - * @param mixed $value |
|
24 | - * |
|
25 | - * @return Exception |
|
26 | - */ |
|
27 | - public static function factory($argument, $type, $value = null) |
|
28 | - { |
|
29 | - $stack = \debug_backtrace(); |
|
20 | + /** |
|
21 | + * @param int $argument |
|
22 | + * @param string $type |
|
23 | + * @param mixed $value |
|
24 | + * |
|
25 | + * @return Exception |
|
26 | + */ |
|
27 | + public static function factory($argument, $type, $value = null) |
|
28 | + { |
|
29 | + $stack = \debug_backtrace(); |
|
30 | 30 | |
31 | - return new Exception( |
|
32 | - \sprintf( |
|
33 | - 'Argument #%d%sof %s::%s() must be a %s', |
|
34 | - $argument, |
|
35 | - $value !== null ? ' (' . \gettype($value) . '#' . $value . ')' : ' (No Value) ', |
|
36 | - $stack[1]['class'], |
|
37 | - $stack[1]['function'], |
|
38 | - $type |
|
39 | - ) |
|
40 | - ); |
|
41 | - } |
|
31 | + return new Exception( |
|
32 | + \sprintf( |
|
33 | + 'Argument #%d%sof %s::%s() must be a %s', |
|
34 | + $argument, |
|
35 | + $value !== null ? ' (' . \gettype($value) . '#' . $value . ')' : ' (No Value) ', |
|
36 | + $stack[1]['class'], |
|
37 | + $stack[1]['function'], |
|
38 | + $type |
|
39 | + ) |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | \sprintf( |
33 | 33 | 'Argument #%d%sof %s::%s() must be a %s', |
34 | 34 | $argument, |
35 | - $value !== null ? ' (' . \gettype($value) . '#' . $value . ')' : ' (No Value) ', |
|
35 | + $value !== null ? ' ('.\gettype($value).'#'.$value.')' : ' (No Value) ', |
|
36 | 36 | $stack[1]['class'], |
37 | 37 | $stack[1]['function'], |
38 | 38 | $type |
@@ -16,151 +16,151 @@ |
||
16 | 16 | */ |
17 | 17 | class Getopt |
18 | 18 | { |
19 | - public static function getopt(array $args, $short_options, $long_options = null) |
|
20 | - { |
|
21 | - if (empty($args)) { |
|
22 | - return [[], []]; |
|
23 | - } |
|
24 | - |
|
25 | - $opts = []; |
|
26 | - $non_opts = []; |
|
27 | - |
|
28 | - if ($long_options) { |
|
29 | - \sort($long_options); |
|
30 | - } |
|
31 | - |
|
32 | - if (isset($args[0][0]) && $args[0][0] != '-') { |
|
33 | - \array_shift($args); |
|
34 | - } |
|
35 | - |
|
36 | - \reset($args); |
|
37 | - |
|
38 | - $args = \array_map('trim', $args); |
|
39 | - |
|
40 | - while (false !== $arg = \current($args)) { |
|
41 | - $i = \key($args); |
|
42 | - \next($args); |
|
43 | - if ($arg == '') { |
|
44 | - continue; |
|
45 | - } |
|
46 | - |
|
47 | - if ($arg == '--') { |
|
48 | - $non_opts = \array_merge($non_opts, \array_slice($args, $i + 1)); |
|
49 | - |
|
50 | - break; |
|
51 | - } |
|
52 | - |
|
53 | - if ($arg[0] != '-' || (\strlen($arg) > 1 && $arg[1] == '-' && !$long_options)) { |
|
54 | - $non_opts[] = $args[$i]; |
|
55 | - |
|
56 | - continue; |
|
57 | - } elseif (\strlen($arg) > 1 && $arg[1] == '-') { |
|
58 | - self::parseLongOption( |
|
59 | - \substr($arg, 2), |
|
60 | - $long_options, |
|
61 | - $opts, |
|
62 | - $args |
|
63 | - ); |
|
64 | - } else { |
|
65 | - self::parseShortOption( |
|
66 | - \substr($arg, 1), |
|
67 | - $short_options, |
|
68 | - $opts, |
|
69 | - $args |
|
70 | - ); |
|
71 | - } |
|
72 | - } |
|
73 | - |
|
74 | - return [$opts, $non_opts]; |
|
75 | - } |
|
76 | - |
|
77 | - protected static function parseShortOption($arg, $short_options, &$opts, &$args) |
|
78 | - { |
|
79 | - $argLen = \strlen($arg); |
|
80 | - |
|
81 | - for ($i = 0; $i < $argLen; $i++) { |
|
82 | - $opt = $arg[$i]; |
|
83 | - $opt_arg = null; |
|
84 | - |
|
85 | - if (($spec = \strstr($short_options, $opt)) === false || $arg[$i] == ':') { |
|
86 | - throw new Exception( |
|
87 | - "unrecognized option -- $opt" |
|
88 | - ); |
|
89 | - } |
|
90 | - |
|
91 | - if (\strlen($spec) > 1 && $spec[1] == ':') { |
|
92 | - if ($i + 1 < $argLen) { |
|
93 | - $opts[] = [$opt, \substr($arg, $i + 1)]; |
|
94 | - |
|
95 | - break; |
|
96 | - } |
|
97 | - if (!(\strlen($spec) > 2 && $spec[2] == ':')) { |
|
98 | - if (false === $opt_arg = \current($args)) { |
|
99 | - throw new Exception( |
|
100 | - "option requires an argument -- $opt" |
|
101 | - ); |
|
102 | - } |
|
103 | - \next($args); |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - $opts[] = [$opt, $opt_arg]; |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - protected static function parseLongOption($arg, $long_options, &$opts, &$args) |
|
112 | - { |
|
113 | - $count = \count($long_options); |
|
114 | - $list = \explode('=', $arg); |
|
115 | - $opt = $list[0]; |
|
116 | - $opt_arg = null; |
|
117 | - |
|
118 | - if (\count($list) > 1) { |
|
119 | - $opt_arg = $list[1]; |
|
120 | - } |
|
121 | - |
|
122 | - $opt_len = \strlen($opt); |
|
123 | - |
|
124 | - for ($i = 0; $i < $count; $i++) { |
|
125 | - $long_opt = $long_options[$i]; |
|
126 | - $opt_start = \substr($long_opt, 0, $opt_len); |
|
127 | - |
|
128 | - if ($opt_start != $opt) { |
|
129 | - continue; |
|
130 | - } |
|
131 | - |
|
132 | - $opt_rest = \substr($long_opt, $opt_len); |
|
133 | - |
|
134 | - if ($opt_rest != '' && $opt[0] != '=' && $i + 1 < $count && |
|
135 | - $opt == \substr($long_options[$i + 1], 0, $opt_len)) { |
|
136 | - throw new Exception( |
|
137 | - "option --$opt is ambiguous" |
|
138 | - ); |
|
139 | - } |
|
140 | - |
|
141 | - if (\substr($long_opt, -1) == '=') { |
|
142 | - if (\substr($long_opt, -2) != '==') { |
|
143 | - if (!\strlen($opt_arg)) { |
|
144 | - if (false === $opt_arg = \current($args)) { |
|
145 | - throw new Exception( |
|
146 | - "option --$opt requires an argument" |
|
147 | - ); |
|
148 | - } |
|
149 | - \next($args); |
|
150 | - } |
|
151 | - } |
|
152 | - } elseif ($opt_arg) { |
|
153 | - throw new Exception( |
|
154 | - "option --$opt doesn't allow an argument" |
|
155 | - ); |
|
156 | - } |
|
157 | - |
|
158 | - $full_option = '--' . \preg_replace('/={1,2}$/', '', $long_opt); |
|
159 | - $opts[] = [$full_option, $opt_arg]; |
|
160 | - |
|
161 | - return; |
|
162 | - } |
|
163 | - |
|
164 | - throw new Exception("unrecognized option --$opt"); |
|
165 | - } |
|
19 | + public static function getopt(array $args, $short_options, $long_options = null) |
|
20 | + { |
|
21 | + if (empty($args)) { |
|
22 | + return [[], []]; |
|
23 | + } |
|
24 | + |
|
25 | + $opts = []; |
|
26 | + $non_opts = []; |
|
27 | + |
|
28 | + if ($long_options) { |
|
29 | + \sort($long_options); |
|
30 | + } |
|
31 | + |
|
32 | + if (isset($args[0][0]) && $args[0][0] != '-') { |
|
33 | + \array_shift($args); |
|
34 | + } |
|
35 | + |
|
36 | + \reset($args); |
|
37 | + |
|
38 | + $args = \array_map('trim', $args); |
|
39 | + |
|
40 | + while (false !== $arg = \current($args)) { |
|
41 | + $i = \key($args); |
|
42 | + \next($args); |
|
43 | + if ($arg == '') { |
|
44 | + continue; |
|
45 | + } |
|
46 | + |
|
47 | + if ($arg == '--') { |
|
48 | + $non_opts = \array_merge($non_opts, \array_slice($args, $i + 1)); |
|
49 | + |
|
50 | + break; |
|
51 | + } |
|
52 | + |
|
53 | + if ($arg[0] != '-' || (\strlen($arg) > 1 && $arg[1] == '-' && !$long_options)) { |
|
54 | + $non_opts[] = $args[$i]; |
|
55 | + |
|
56 | + continue; |
|
57 | + } elseif (\strlen($arg) > 1 && $arg[1] == '-') { |
|
58 | + self::parseLongOption( |
|
59 | + \substr($arg, 2), |
|
60 | + $long_options, |
|
61 | + $opts, |
|
62 | + $args |
|
63 | + ); |
|
64 | + } else { |
|
65 | + self::parseShortOption( |
|
66 | + \substr($arg, 1), |
|
67 | + $short_options, |
|
68 | + $opts, |
|
69 | + $args |
|
70 | + ); |
|
71 | + } |
|
72 | + } |
|
73 | + |
|
74 | + return [$opts, $non_opts]; |
|
75 | + } |
|
76 | + |
|
77 | + protected static function parseShortOption($arg, $short_options, &$opts, &$args) |
|
78 | + { |
|
79 | + $argLen = \strlen($arg); |
|
80 | + |
|
81 | + for ($i = 0; $i < $argLen; $i++) { |
|
82 | + $opt = $arg[$i]; |
|
83 | + $opt_arg = null; |
|
84 | + |
|
85 | + if (($spec = \strstr($short_options, $opt)) === false || $arg[$i] == ':') { |
|
86 | + throw new Exception( |
|
87 | + "unrecognized option -- $opt" |
|
88 | + ); |
|
89 | + } |
|
90 | + |
|
91 | + if (\strlen($spec) > 1 && $spec[1] == ':') { |
|
92 | + if ($i + 1 < $argLen) { |
|
93 | + $opts[] = [$opt, \substr($arg, $i + 1)]; |
|
94 | + |
|
95 | + break; |
|
96 | + } |
|
97 | + if (!(\strlen($spec) > 2 && $spec[2] == ':')) { |
|
98 | + if (false === $opt_arg = \current($args)) { |
|
99 | + throw new Exception( |
|
100 | + "option requires an argument -- $opt" |
|
101 | + ); |
|
102 | + } |
|
103 | + \next($args); |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + $opts[] = [$opt, $opt_arg]; |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + protected static function parseLongOption($arg, $long_options, &$opts, &$args) |
|
112 | + { |
|
113 | + $count = \count($long_options); |
|
114 | + $list = \explode('=', $arg); |
|
115 | + $opt = $list[0]; |
|
116 | + $opt_arg = null; |
|
117 | + |
|
118 | + if (\count($list) > 1) { |
|
119 | + $opt_arg = $list[1]; |
|
120 | + } |
|
121 | + |
|
122 | + $opt_len = \strlen($opt); |
|
123 | + |
|
124 | + for ($i = 0; $i < $count; $i++) { |
|
125 | + $long_opt = $long_options[$i]; |
|
126 | + $opt_start = \substr($long_opt, 0, $opt_len); |
|
127 | + |
|
128 | + if ($opt_start != $opt) { |
|
129 | + continue; |
|
130 | + } |
|
131 | + |
|
132 | + $opt_rest = \substr($long_opt, $opt_len); |
|
133 | + |
|
134 | + if ($opt_rest != '' && $opt[0] != '=' && $i + 1 < $count && |
|
135 | + $opt == \substr($long_options[$i + 1], 0, $opt_len)) { |
|
136 | + throw new Exception( |
|
137 | + "option --$opt is ambiguous" |
|
138 | + ); |
|
139 | + } |
|
140 | + |
|
141 | + if (\substr($long_opt, -1) == '=') { |
|
142 | + if (\substr($long_opt, -2) != '==') { |
|
143 | + if (!\strlen($opt_arg)) { |
|
144 | + if (false === $opt_arg = \current($args)) { |
|
145 | + throw new Exception( |
|
146 | + "option --$opt requires an argument" |
|
147 | + ); |
|
148 | + } |
|
149 | + \next($args); |
|
150 | + } |
|
151 | + } |
|
152 | + } elseif ($opt_arg) { |
|
153 | + throw new Exception( |
|
154 | + "option --$opt doesn't allow an argument" |
|
155 | + ); |
|
156 | + } |
|
157 | + |
|
158 | + $full_option = '--' . \preg_replace('/={1,2}$/', '', $long_opt); |
|
159 | + $opts[] = [$full_option, $opt_arg]; |
|
160 | + |
|
161 | + return; |
|
162 | + } |
|
163 | + |
|
164 | + throw new Exception("unrecognized option --$opt"); |
|
165 | + } |
|
166 | 166 | } |
@@ -155,7 +155,7 @@ |
||
155 | 155 | ); |
156 | 156 | } |
157 | 157 | |
158 | - $full_option = '--' . \preg_replace('/={1,2}$/', '', $long_opt); |
|
158 | + $full_option = '--'.\preg_replace('/={1,2}$/', '', $long_opt); |
|
159 | 159 | $opts[] = [$full_option, $opt_arg]; |
160 | 160 | |
161 | 161 | return; |
@@ -16,29 +16,29 @@ |
||
16 | 16 | |
17 | 17 | class TextTestListRenderer |
18 | 18 | { |
19 | - public function render(TestSuite $suite): string |
|
20 | - { |
|
21 | - $buffer = 'Available test(s):' . PHP_EOL; |
|
19 | + public function render(TestSuite $suite): string |
|
20 | + { |
|
21 | + $buffer = 'Available test(s):' . PHP_EOL; |
|
22 | 22 | |
23 | - foreach (new \RecursiveIteratorIterator($suite->getIterator()) as $test) { |
|
24 | - if ($test instanceof TestCase) { |
|
25 | - $name = \sprintf( |
|
26 | - '%s::%s', |
|
27 | - \get_class($test), |
|
28 | - \str_replace(' with data set ', '', $test->getName()) |
|
29 | - ); |
|
30 | - } elseif ($test instanceof PhptTestCase) { |
|
31 | - $name = $test->getName(); |
|
32 | - } else { |
|
33 | - continue; |
|
34 | - } |
|
23 | + foreach (new \RecursiveIteratorIterator($suite->getIterator()) as $test) { |
|
24 | + if ($test instanceof TestCase) { |
|
25 | + $name = \sprintf( |
|
26 | + '%s::%s', |
|
27 | + \get_class($test), |
|
28 | + \str_replace(' with data set ', '', $test->getName()) |
|
29 | + ); |
|
30 | + } elseif ($test instanceof PhptTestCase) { |
|
31 | + $name = $test->getName(); |
|
32 | + } else { |
|
33 | + continue; |
|
34 | + } |
|
35 | 35 | |
36 | - $buffer .= \sprintf( |
|
37 | - ' - %s' . PHP_EOL, |
|
38 | - $name |
|
39 | - ); |
|
40 | - } |
|
36 | + $buffer .= \sprintf( |
|
37 | + ' - %s' . PHP_EOL, |
|
38 | + $name |
|
39 | + ); |
|
40 | + } |
|
41 | 41 | |
42 | - return $buffer; |
|
43 | - } |
|
42 | + return $buffer; |
|
43 | + } |
|
44 | 44 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /* |
3 | 3 | * This file is part of PHPUnit. |
4 | 4 | * |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | { |
19 | 19 | public function render(TestSuite $suite): string |
20 | 20 | { |
21 | - $buffer = 'Available test(s):' . PHP_EOL; |
|
21 | + $buffer = 'Available test(s):'.PHP_EOL; |
|
22 | 22 | |
23 | 23 | foreach (new \RecursiveIteratorIterator($suite->getIterator()) as $test) { |
24 | 24 | if ($test instanceof TestCase) { |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | $buffer .= \sprintf( |
37 | - ' - %s' . PHP_EOL, |
|
37 | + ' - %s'.PHP_EOL, |
|
38 | 38 | $name |
39 | 39 | ); |
40 | 40 | } |
@@ -16,65 +16,65 @@ |
||
16 | 16 | */ |
17 | 17 | class Fileloader |
18 | 18 | { |
19 | - /** |
|
20 | - * Checks if a PHP sourcefile is readable. |
|
21 | - * The sourcefile is loaded through the load() method. |
|
22 | - * |
|
23 | - * @param string $filename |
|
24 | - * |
|
25 | - * @return string |
|
26 | - * |
|
27 | - * @throws Exception |
|
28 | - */ |
|
29 | - public static function checkAndLoad($filename) |
|
30 | - { |
|
31 | - $includePathFilename = \stream_resolve_include_path($filename); |
|
19 | + /** |
|
20 | + * Checks if a PHP sourcefile is readable. |
|
21 | + * The sourcefile is loaded through the load() method. |
|
22 | + * |
|
23 | + * @param string $filename |
|
24 | + * |
|
25 | + * @return string |
|
26 | + * |
|
27 | + * @throws Exception |
|
28 | + */ |
|
29 | + public static function checkAndLoad($filename) |
|
30 | + { |
|
31 | + $includePathFilename = \stream_resolve_include_path($filename); |
|
32 | 32 | |
33 | - // As a fallback, PHP looks in the directory of the file executing the stream_resolve_include_path function. |
|
34 | - // We don't want to load the Test.php file here, so skip it if it found that. |
|
35 | - // PHP prioritizes the include_path setting, so if the current directory is in there, it will first look in the |
|
36 | - // current working directory. |
|
37 | - $localFile = __DIR__ . DIRECTORY_SEPARATOR . $filename; |
|
33 | + // As a fallback, PHP looks in the directory of the file executing the stream_resolve_include_path function. |
|
34 | + // We don't want to load the Test.php file here, so skip it if it found that. |
|
35 | + // PHP prioritizes the include_path setting, so if the current directory is in there, it will first look in the |
|
36 | + // current working directory. |
|
37 | + $localFile = __DIR__ . DIRECTORY_SEPARATOR . $filename; |
|
38 | 38 | |
39 | - // @see https://github.com/sebastianbergmann/phpunit/pull/2751 |
|
40 | - $isReadable = @\fopen($includePathFilename, 'r') !== false; |
|
39 | + // @see https://github.com/sebastianbergmann/phpunit/pull/2751 |
|
40 | + $isReadable = @\fopen($includePathFilename, 'r') !== false; |
|
41 | 41 | |
42 | - if (!$includePathFilename || !$isReadable || $includePathFilename === $localFile) { |
|
43 | - throw new Exception( |
|
44 | - \sprintf('Cannot open file "%s".' . "\n", $filename) |
|
45 | - ); |
|
46 | - } |
|
42 | + if (!$includePathFilename || !$isReadable || $includePathFilename === $localFile) { |
|
43 | + throw new Exception( |
|
44 | + \sprintf('Cannot open file "%s".' . "\n", $filename) |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | |
48 | - self::load($includePathFilename); |
|
48 | + self::load($includePathFilename); |
|
49 | 49 | |
50 | - return $includePathFilename; |
|
51 | - } |
|
50 | + return $includePathFilename; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Loads a PHP sourcefile. |
|
55 | - * |
|
56 | - * @param string $filename |
|
57 | - * |
|
58 | - * @return mixed |
|
59 | - */ |
|
60 | - public static function load($filename) |
|
61 | - { |
|
62 | - $oldVariableNames = \array_keys(\get_defined_vars()); |
|
53 | + /** |
|
54 | + * Loads a PHP sourcefile. |
|
55 | + * |
|
56 | + * @param string $filename |
|
57 | + * |
|
58 | + * @return mixed |
|
59 | + */ |
|
60 | + public static function load($filename) |
|
61 | + { |
|
62 | + $oldVariableNames = \array_keys(\get_defined_vars()); |
|
63 | 63 | |
64 | - include_once $filename; |
|
64 | + include_once $filename; |
|
65 | 65 | |
66 | - $newVariables = \get_defined_vars(); |
|
67 | - $newVariableNames = \array_diff( |
|
68 | - \array_keys($newVariables), |
|
69 | - $oldVariableNames |
|
70 | - ); |
|
66 | + $newVariables = \get_defined_vars(); |
|
67 | + $newVariableNames = \array_diff( |
|
68 | + \array_keys($newVariables), |
|
69 | + $oldVariableNames |
|
70 | + ); |
|
71 | 71 | |
72 | - foreach ($newVariableNames as $variableName) { |
|
73 | - if ($variableName != 'oldVariableNames') { |
|
74 | - $GLOBALS[$variableName] = $newVariables[$variableName]; |
|
75 | - } |
|
76 | - } |
|
72 | + foreach ($newVariableNames as $variableName) { |
|
73 | + if ($variableName != 'oldVariableNames') { |
|
74 | + $GLOBALS[$variableName] = $newVariables[$variableName]; |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - return $filename; |
|
79 | - } |
|
78 | + return $filename; |
|
79 | + } |
|
80 | 80 | } |
@@ -34,14 +34,14 @@ |
||
34 | 34 | // We don't want to load the Test.php file here, so skip it if it found that. |
35 | 35 | // PHP prioritizes the include_path setting, so if the current directory is in there, it will first look in the |
36 | 36 | // current working directory. |
37 | - $localFile = __DIR__ . DIRECTORY_SEPARATOR . $filename; |
|
37 | + $localFile = __DIR__.DIRECTORY_SEPARATOR.$filename; |
|
38 | 38 | |
39 | 39 | // @see https://github.com/sebastianbergmann/phpunit/pull/2751 |
40 | 40 | $isReadable = @\fopen($includePathFilename, 'r') !== false; |
41 | 41 | |
42 | 42 | if (!$includePathFilename || !$isReadable || $includePathFilename === $localFile) { |
43 | 43 | throw new Exception( |
44 | - \sprintf('Cannot open file "%s".' . "\n", $filename) |
|
44 | + \sprintf('Cannot open file "%s".'."\n", $filename) |
|
45 | 45 | ); |
46 | 46 | } |
47 | 47 |
@@ -15,29 +15,29 @@ |
||
15 | 15 | */ |
16 | 16 | class Type |
17 | 17 | { |
18 | - /** |
|
19 | - * @param string $type |
|
20 | - * |
|
21 | - * @return bool |
|
22 | - */ |
|
23 | - public static function isType($type) |
|
24 | - { |
|
25 | - return \in_array( |
|
26 | - $type, |
|
27 | - [ |
|
28 | - 'numeric', |
|
29 | - 'integer', |
|
30 | - 'int', |
|
31 | - 'float', |
|
32 | - 'string', |
|
33 | - 'boolean', |
|
34 | - 'bool', |
|
35 | - 'null', |
|
36 | - 'array', |
|
37 | - 'object', |
|
38 | - 'resource', |
|
39 | - 'scalar' |
|
40 | - ] |
|
41 | - ); |
|
42 | - } |
|
18 | + /** |
|
19 | + * @param string $type |
|
20 | + * |
|
21 | + * @return bool |
|
22 | + */ |
|
23 | + public static function isType($type) |
|
24 | + { |
|
25 | + return \in_array( |
|
26 | + $type, |
|
27 | + [ |
|
28 | + 'numeric', |
|
29 | + 'integer', |
|
30 | + 'int', |
|
31 | + 'float', |
|
32 | + 'string', |
|
33 | + 'boolean', |
|
34 | + 'bool', |
|
35 | + 'null', |
|
36 | + 'array', |
|
37 | + 'object', |
|
38 | + 'resource', |
|
39 | + 'scalar' |
|
40 | + ] |
|
41 | + ); |
|
42 | + } |
|
43 | 43 | } |
@@ -15,26 +15,26 @@ |
||
15 | 15 | */ |
16 | 16 | class Filesystem |
17 | 17 | { |
18 | - /** |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected static $buffer = []; |
|
18 | + /** |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected static $buffer = []; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Maps class names to source file names: |
|
25 | - * - PEAR CS: Foo_Bar_Baz -> Foo/Bar/Baz.php |
|
26 | - * - Namespace: Foo\Bar\Baz -> Foo/Bar/Baz.php |
|
27 | - * |
|
28 | - * @param string $className |
|
29 | - * |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public static function classNameToFilename($className) |
|
33 | - { |
|
34 | - return \str_replace( |
|
35 | - ['_', '\\'], |
|
36 | - DIRECTORY_SEPARATOR, |
|
37 | - $className |
|
38 | - ) . '.php'; |
|
39 | - } |
|
23 | + /** |
|
24 | + * Maps class names to source file names: |
|
25 | + * - PEAR CS: Foo_Bar_Baz -> Foo/Bar/Baz.php |
|
26 | + * - Namespace: Foo\Bar\Baz -> Foo/Bar/Baz.php |
|
27 | + * |
|
28 | + * @param string $className |
|
29 | + * |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public static function classNameToFilename($className) |
|
33 | + { |
|
34 | + return \str_replace( |
|
35 | + ['_', '\\'], |
|
36 | + DIRECTORY_SEPARATOR, |
|
37 | + $className |
|
38 | + ) . '.php'; |
|
39 | + } |
|
40 | 40 | } |
@@ -35,6 +35,6 @@ |
||
35 | 35 | ['_', '\\'], |
36 | 36 | DIRECTORY_SEPARATOR, |
37 | 37 | $className |
38 | - ) . '.php'; |
|
38 | + ).'.php'; |
|
39 | 39 | } |
40 | 40 | } |