@@ -13,34 +13,34 @@ |
||
13 | 13 | */ |
14 | 14 | class PHP_Token_Stream_CachingFactory |
15 | 15 | { |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected static $cache = []; |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected static $cache = []; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param string $filename |
|
23 | - * |
|
24 | - * @return PHP_Token_Stream |
|
25 | - */ |
|
26 | - public static function get($filename) |
|
27 | - { |
|
28 | - if (!isset(self::$cache[$filename])) { |
|
29 | - self::$cache[$filename] = new PHP_Token_Stream($filename); |
|
30 | - } |
|
21 | + /** |
|
22 | + * @param string $filename |
|
23 | + * |
|
24 | + * @return PHP_Token_Stream |
|
25 | + */ |
|
26 | + public static function get($filename) |
|
27 | + { |
|
28 | + if (!isset(self::$cache[$filename])) { |
|
29 | + self::$cache[$filename] = new PHP_Token_Stream($filename); |
|
30 | + } |
|
31 | 31 | |
32 | - return self::$cache[$filename]; |
|
33 | - } |
|
32 | + return self::$cache[$filename]; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param string $filename |
|
37 | - */ |
|
38 | - public static function clear($filename = null) |
|
39 | - { |
|
40 | - if (is_string($filename)) { |
|
41 | - unset(self::$cache[$filename]); |
|
42 | - } else { |
|
43 | - self::$cache = []; |
|
44 | - } |
|
45 | - } |
|
35 | + /** |
|
36 | + * @param string $filename |
|
37 | + */ |
|
38 | + public static function clear($filename = null) |
|
39 | + { |
|
40 | + if (is_string($filename)) { |
|
41 | + unset(self::$cache[$filename]); |
|
42 | + } else { |
|
43 | + self::$cache = []; |
|
44 | + } |
|
45 | + } |
|
46 | 46 | } |
@@ -15,121 +15,121 @@ |
||
15 | 15 | */ |
16 | 16 | class Text_Template |
17 | 17 | { |
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $template = ''; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $openDelimiter = '{'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $closeDelimiter = '}'; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $values = array(); |
|
37 | - |
|
38 | - /** |
|
39 | - * Constructor. |
|
40 | - * |
|
41 | - * @param string $file |
|
42 | - * @throws InvalidArgumentException |
|
43 | - */ |
|
44 | - public function __construct($file = '', $openDelimiter = '{', $closeDelimiter = '}') |
|
45 | - { |
|
46 | - $this->setFile($file); |
|
47 | - $this->openDelimiter = $openDelimiter; |
|
48 | - $this->closeDelimiter = $closeDelimiter; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Sets the template file. |
|
53 | - * |
|
54 | - * @param string $file |
|
55 | - * @throws InvalidArgumentException |
|
56 | - */ |
|
57 | - public function setFile($file) |
|
58 | - { |
|
59 | - $distFile = $file . '.dist'; |
|
60 | - |
|
61 | - if (file_exists($file)) { |
|
62 | - $this->template = file_get_contents($file); |
|
63 | - } |
|
64 | - |
|
65 | - else if (file_exists($distFile)) { |
|
66 | - $this->template = file_get_contents($distFile); |
|
67 | - } |
|
68 | - |
|
69 | - else { |
|
70 | - throw new InvalidArgumentException( |
|
71 | - 'Template file could not be loaded.' |
|
72 | - ); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Sets one or more template variables. |
|
78 | - * |
|
79 | - * @param array $values |
|
80 | - * @param bool $merge |
|
81 | - */ |
|
82 | - public function setVar(array $values, $merge = TRUE) |
|
83 | - { |
|
84 | - if (!$merge || empty($this->values)) { |
|
85 | - $this->values = $values; |
|
86 | - } else { |
|
87 | - $this->values = array_merge($this->values, $values); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Renders the template and returns the result. |
|
93 | - * |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function render() |
|
97 | - { |
|
98 | - $keys = array(); |
|
99 | - |
|
100 | - foreach ($this->values as $key => $value) { |
|
101 | - $keys[] = $this->openDelimiter . $key . $this->closeDelimiter; |
|
102 | - } |
|
103 | - |
|
104 | - return str_replace($keys, $this->values, $this->template); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Renders the template and writes the result to a file. |
|
109 | - * |
|
110 | - * @param string $target |
|
111 | - */ |
|
112 | - public function renderTo($target) |
|
113 | - { |
|
114 | - $fp = @fopen($target, 'wt'); |
|
115 | - |
|
116 | - if ($fp) { |
|
117 | - fwrite($fp, $this->render()); |
|
118 | - fclose($fp); |
|
119 | - } else { |
|
120 | - $error = error_get_last(); |
|
121 | - |
|
122 | - throw new RuntimeException( |
|
123 | - sprintf( |
|
124 | - 'Could not write to %s: %s', |
|
125 | - $target, |
|
126 | - substr( |
|
127 | - $error['message'], |
|
128 | - strpos($error['message'], ':') + 2 |
|
129 | - ) |
|
130 | - ) |
|
131 | - ); |
|
132 | - } |
|
133 | - } |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $template = ''; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $openDelimiter = '{'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $closeDelimiter = '}'; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $values = array(); |
|
37 | + |
|
38 | + /** |
|
39 | + * Constructor. |
|
40 | + * |
|
41 | + * @param string $file |
|
42 | + * @throws InvalidArgumentException |
|
43 | + */ |
|
44 | + public function __construct($file = '', $openDelimiter = '{', $closeDelimiter = '}') |
|
45 | + { |
|
46 | + $this->setFile($file); |
|
47 | + $this->openDelimiter = $openDelimiter; |
|
48 | + $this->closeDelimiter = $closeDelimiter; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Sets the template file. |
|
53 | + * |
|
54 | + * @param string $file |
|
55 | + * @throws InvalidArgumentException |
|
56 | + */ |
|
57 | + public function setFile($file) |
|
58 | + { |
|
59 | + $distFile = $file . '.dist'; |
|
60 | + |
|
61 | + if (file_exists($file)) { |
|
62 | + $this->template = file_get_contents($file); |
|
63 | + } |
|
64 | + |
|
65 | + else if (file_exists($distFile)) { |
|
66 | + $this->template = file_get_contents($distFile); |
|
67 | + } |
|
68 | + |
|
69 | + else { |
|
70 | + throw new InvalidArgumentException( |
|
71 | + 'Template file could not be loaded.' |
|
72 | + ); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Sets one or more template variables. |
|
78 | + * |
|
79 | + * @param array $values |
|
80 | + * @param bool $merge |
|
81 | + */ |
|
82 | + public function setVar(array $values, $merge = TRUE) |
|
83 | + { |
|
84 | + if (!$merge || empty($this->values)) { |
|
85 | + $this->values = $values; |
|
86 | + } else { |
|
87 | + $this->values = array_merge($this->values, $values); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Renders the template and returns the result. |
|
93 | + * |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function render() |
|
97 | + { |
|
98 | + $keys = array(); |
|
99 | + |
|
100 | + foreach ($this->values as $key => $value) { |
|
101 | + $keys[] = $this->openDelimiter . $key . $this->closeDelimiter; |
|
102 | + } |
|
103 | + |
|
104 | + return str_replace($keys, $this->values, $this->template); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Renders the template and writes the result to a file. |
|
109 | + * |
|
110 | + * @param string $target |
|
111 | + */ |
|
112 | + public function renderTo($target) |
|
113 | + { |
|
114 | + $fp = @fopen($target, 'wt'); |
|
115 | + |
|
116 | + if ($fp) { |
|
117 | + fwrite($fp, $this->render()); |
|
118 | + fclose($fp); |
|
119 | + } else { |
|
120 | + $error = error_get_last(); |
|
121 | + |
|
122 | + throw new RuntimeException( |
|
123 | + sprintf( |
|
124 | + 'Could not write to %s: %s', |
|
125 | + $target, |
|
126 | + substr( |
|
127 | + $error['message'], |
|
128 | + strpos($error['message'], ':') + 2 |
|
129 | + ) |
|
130 | + ) |
|
131 | + ); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | } |
135 | 135 |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function setFile($file) |
58 | 58 | { |
59 | - $distFile = $file . '.dist'; |
|
59 | + $distFile = $file.'.dist'; |
|
60 | 60 | |
61 | 61 | if (file_exists($file)) { |
62 | 62 | $this->template = file_get_contents($file); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $keys = array(); |
99 | 99 | |
100 | 100 | foreach ($this->values as $key => $value) { |
101 | - $keys[] = $this->openDelimiter . $key . $this->closeDelimiter; |
|
101 | + $keys[] = $this->openDelimiter.$key.$this->closeDelimiter; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | return str_replace($keys, $this->values, $this->template); |
@@ -60,13 +60,9 @@ |
||
60 | 60 | |
61 | 61 | if (file_exists($file)) { |
62 | 62 | $this->template = file_get_contents($file); |
63 | - } |
|
64 | - |
|
65 | - else if (file_exists($distFile)) { |
|
63 | + } else if (file_exists($distFile)) { |
|
66 | 64 | $this->template = file_get_contents($distFile); |
67 | - } |
|
68 | - |
|
69 | - else { |
|
65 | + } else { |
|
70 | 66 | throw new InvalidArgumentException( |
71 | 67 | 'Template file could not be loaded.' |
72 | 68 | ); |
@@ -15,201 +15,201 @@ |
||
15 | 15 | |
16 | 16 | class GetoptTest extends TestCase |
17 | 17 | { |
18 | - public function testItIncludeTheLongOptionsAfterTheArgument() |
|
19 | - { |
|
20 | - $args = [ |
|
21 | - 'command', |
|
22 | - 'myArgument', |
|
23 | - '--colors', |
|
24 | - ]; |
|
25 | - $actual = Getopt::getopt($args, '', ['colors==']); |
|
26 | - |
|
27 | - $expected = [ |
|
28 | - [ |
|
29 | - [ |
|
30 | - '--colors', |
|
31 | - null, |
|
32 | - ], |
|
33 | - ], |
|
34 | - [ |
|
35 | - 'myArgument', |
|
36 | - ], |
|
37 | - ]; |
|
38 | - |
|
39 | - $this->assertEquals($expected, $actual); |
|
40 | - } |
|
41 | - |
|
42 | - public function testItIncludeTheShortOptionsAfterTheArgument() |
|
43 | - { |
|
44 | - $args = [ |
|
45 | - 'command', |
|
46 | - 'myArgument', |
|
47 | - '-v', |
|
48 | - ]; |
|
49 | - $actual = Getopt::getopt($args, 'v'); |
|
50 | - |
|
51 | - $expected = [ |
|
52 | - [ |
|
53 | - [ |
|
54 | - 'v', |
|
55 | - null, |
|
56 | - ], |
|
57 | - ], |
|
58 | - [ |
|
59 | - 'myArgument', |
|
60 | - ], |
|
61 | - ]; |
|
62 | - |
|
63 | - $this->assertEquals($expected, $actual); |
|
64 | - } |
|
65 | - |
|
66 | - public function testShortOptionUnrecognizedException() |
|
67 | - { |
|
68 | - $args = [ |
|
69 | - 'command', |
|
70 | - 'myArgument', |
|
71 | - '-v', |
|
72 | - ]; |
|
73 | - |
|
74 | - $this->expectException(Exception::class); |
|
75 | - $this->expectExceptionMessage('unrecognized option -- v'); |
|
76 | - |
|
77 | - Getopt::getopt($args, ''); |
|
78 | - } |
|
79 | - |
|
80 | - public function testShortOptionRequiresAnArgumentException() |
|
81 | - { |
|
82 | - $args = [ |
|
83 | - 'command', |
|
84 | - 'myArgument', |
|
85 | - '-f', |
|
86 | - ]; |
|
87 | - |
|
88 | - $this->expectException(Exception::class); |
|
89 | - $this->expectExceptionMessage('option requires an argument -- f'); |
|
90 | - |
|
91 | - Getopt::getopt($args, 'f:'); |
|
92 | - } |
|
93 | - |
|
94 | - public function testShortOptionHandleAnOptionalValue() |
|
95 | - { |
|
96 | - $args = [ |
|
97 | - 'command', |
|
98 | - 'myArgument', |
|
99 | - '-f', |
|
100 | - ]; |
|
101 | - $actual = Getopt::getopt($args, 'f::'); |
|
102 | - $expected = [ |
|
103 | - [ |
|
104 | - [ |
|
105 | - 'f', |
|
106 | - null, |
|
107 | - ], |
|
108 | - ], |
|
109 | - [ |
|
110 | - 'myArgument', |
|
111 | - ], |
|
112 | - ]; |
|
113 | - $this->assertEquals($expected, $actual); |
|
114 | - } |
|
115 | - |
|
116 | - public function testLongOptionIsAmbiguousException() |
|
117 | - { |
|
118 | - $args = [ |
|
119 | - 'command', |
|
120 | - '--col', |
|
121 | - ]; |
|
122 | - |
|
123 | - $this->expectException(Exception::class); |
|
124 | - $this->expectExceptionMessage('option --col is ambiguous'); |
|
125 | - |
|
126 | - Getopt::getopt($args, '', ['columns', 'colors']); |
|
127 | - } |
|
128 | - |
|
129 | - public function testLongOptionUnrecognizedException() |
|
130 | - { |
|
131 | - // the exception 'unrecognized option --option' is not thrown |
|
132 | - // if the there are not defined extended options |
|
133 | - $args = [ |
|
134 | - 'command', |
|
135 | - '--foo', |
|
136 | - ]; |
|
137 | - |
|
138 | - $this->expectException(Exception::class); |
|
139 | - $this->expectExceptionMessage('unrecognized option --foo'); |
|
140 | - |
|
141 | - Getopt::getopt($args, '', ['colors']); |
|
142 | - } |
|
143 | - |
|
144 | - public function testLongOptionRequiresAnArgumentException() |
|
145 | - { |
|
146 | - $args = [ |
|
147 | - 'command', |
|
148 | - '--foo', |
|
149 | - ]; |
|
150 | - |
|
151 | - $this->expectException(Exception::class); |
|
152 | - $this->expectExceptionMessage('option --foo requires an argument'); |
|
153 | - |
|
154 | - Getopt::getopt($args, '', ['foo=']); |
|
155 | - } |
|
156 | - |
|
157 | - public function testLongOptionDoesNotAllowAnArgumentException() |
|
158 | - { |
|
159 | - $args = [ |
|
160 | - 'command', |
|
161 | - '--foo=bar', |
|
162 | - ]; |
|
163 | - |
|
164 | - $this->expectException(Exception::class); |
|
165 | - $this->expectExceptionMessage("option --foo doesn't allow an argument"); |
|
166 | - |
|
167 | - Getopt::getopt($args, '', ['foo']); |
|
168 | - } |
|
169 | - |
|
170 | - public function testItHandlesLongParametesWithValues() |
|
171 | - { |
|
172 | - $command = 'command parameter-0 --exec parameter-1 --conf config.xml --optn parameter-2 --optn=content-of-o parameter-n'; |
|
173 | - $args = \explode(' ', $command); |
|
174 | - unset($args[0]); |
|
175 | - $expected = [ |
|
176 | - [ |
|
177 | - ['--exec', null], |
|
178 | - ['--conf', 'config.xml'], |
|
179 | - ['--optn', null], |
|
180 | - ['--optn', 'content-of-o'], |
|
181 | - ], |
|
182 | - [ |
|
183 | - 'parameter-0', |
|
184 | - 'parameter-1', |
|
185 | - 'parameter-2', |
|
186 | - 'parameter-n', |
|
187 | - ], |
|
188 | - ]; |
|
189 | - $actual = Getopt::getopt($args, '', ['exec', 'conf=', 'optn==']); |
|
190 | - $this->assertEquals($expected, $actual); |
|
191 | - } |
|
192 | - |
|
193 | - public function testItHandlesShortParametesWithValues() |
|
194 | - { |
|
195 | - $command = 'command parameter-0 -x parameter-1 -c config.xml -o parameter-2 -ocontent-of-o parameter-n'; |
|
196 | - $args = \explode(' ', $command); |
|
197 | - unset($args[0]); |
|
198 | - $expected = [ |
|
199 | - [ |
|
200 | - ['x', null], |
|
201 | - ['c', 'config.xml'], |
|
202 | - ['o', null], |
|
203 | - ['o', 'content-of-o'], |
|
204 | - ], |
|
205 | - [ |
|
206 | - 'parameter-0', |
|
207 | - 'parameter-1', |
|
208 | - 'parameter-2', |
|
209 | - 'parameter-n', |
|
210 | - ], |
|
211 | - ]; |
|
212 | - $actual = Getopt::getopt($args, 'xc:o::'); |
|
213 | - $this->assertEquals($expected, $actual); |
|
214 | - } |
|
18 | + public function testItIncludeTheLongOptionsAfterTheArgument() |
|
19 | + { |
|
20 | + $args = [ |
|
21 | + 'command', |
|
22 | + 'myArgument', |
|
23 | + '--colors', |
|
24 | + ]; |
|
25 | + $actual = Getopt::getopt($args, '', ['colors==']); |
|
26 | + |
|
27 | + $expected = [ |
|
28 | + [ |
|
29 | + [ |
|
30 | + '--colors', |
|
31 | + null, |
|
32 | + ], |
|
33 | + ], |
|
34 | + [ |
|
35 | + 'myArgument', |
|
36 | + ], |
|
37 | + ]; |
|
38 | + |
|
39 | + $this->assertEquals($expected, $actual); |
|
40 | + } |
|
41 | + |
|
42 | + public function testItIncludeTheShortOptionsAfterTheArgument() |
|
43 | + { |
|
44 | + $args = [ |
|
45 | + 'command', |
|
46 | + 'myArgument', |
|
47 | + '-v', |
|
48 | + ]; |
|
49 | + $actual = Getopt::getopt($args, 'v'); |
|
50 | + |
|
51 | + $expected = [ |
|
52 | + [ |
|
53 | + [ |
|
54 | + 'v', |
|
55 | + null, |
|
56 | + ], |
|
57 | + ], |
|
58 | + [ |
|
59 | + 'myArgument', |
|
60 | + ], |
|
61 | + ]; |
|
62 | + |
|
63 | + $this->assertEquals($expected, $actual); |
|
64 | + } |
|
65 | + |
|
66 | + public function testShortOptionUnrecognizedException() |
|
67 | + { |
|
68 | + $args = [ |
|
69 | + 'command', |
|
70 | + 'myArgument', |
|
71 | + '-v', |
|
72 | + ]; |
|
73 | + |
|
74 | + $this->expectException(Exception::class); |
|
75 | + $this->expectExceptionMessage('unrecognized option -- v'); |
|
76 | + |
|
77 | + Getopt::getopt($args, ''); |
|
78 | + } |
|
79 | + |
|
80 | + public function testShortOptionRequiresAnArgumentException() |
|
81 | + { |
|
82 | + $args = [ |
|
83 | + 'command', |
|
84 | + 'myArgument', |
|
85 | + '-f', |
|
86 | + ]; |
|
87 | + |
|
88 | + $this->expectException(Exception::class); |
|
89 | + $this->expectExceptionMessage('option requires an argument -- f'); |
|
90 | + |
|
91 | + Getopt::getopt($args, 'f:'); |
|
92 | + } |
|
93 | + |
|
94 | + public function testShortOptionHandleAnOptionalValue() |
|
95 | + { |
|
96 | + $args = [ |
|
97 | + 'command', |
|
98 | + 'myArgument', |
|
99 | + '-f', |
|
100 | + ]; |
|
101 | + $actual = Getopt::getopt($args, 'f::'); |
|
102 | + $expected = [ |
|
103 | + [ |
|
104 | + [ |
|
105 | + 'f', |
|
106 | + null, |
|
107 | + ], |
|
108 | + ], |
|
109 | + [ |
|
110 | + 'myArgument', |
|
111 | + ], |
|
112 | + ]; |
|
113 | + $this->assertEquals($expected, $actual); |
|
114 | + } |
|
115 | + |
|
116 | + public function testLongOptionIsAmbiguousException() |
|
117 | + { |
|
118 | + $args = [ |
|
119 | + 'command', |
|
120 | + '--col', |
|
121 | + ]; |
|
122 | + |
|
123 | + $this->expectException(Exception::class); |
|
124 | + $this->expectExceptionMessage('option --col is ambiguous'); |
|
125 | + |
|
126 | + Getopt::getopt($args, '', ['columns', 'colors']); |
|
127 | + } |
|
128 | + |
|
129 | + public function testLongOptionUnrecognizedException() |
|
130 | + { |
|
131 | + // the exception 'unrecognized option --option' is not thrown |
|
132 | + // if the there are not defined extended options |
|
133 | + $args = [ |
|
134 | + 'command', |
|
135 | + '--foo', |
|
136 | + ]; |
|
137 | + |
|
138 | + $this->expectException(Exception::class); |
|
139 | + $this->expectExceptionMessage('unrecognized option --foo'); |
|
140 | + |
|
141 | + Getopt::getopt($args, '', ['colors']); |
|
142 | + } |
|
143 | + |
|
144 | + public function testLongOptionRequiresAnArgumentException() |
|
145 | + { |
|
146 | + $args = [ |
|
147 | + 'command', |
|
148 | + '--foo', |
|
149 | + ]; |
|
150 | + |
|
151 | + $this->expectException(Exception::class); |
|
152 | + $this->expectExceptionMessage('option --foo requires an argument'); |
|
153 | + |
|
154 | + Getopt::getopt($args, '', ['foo=']); |
|
155 | + } |
|
156 | + |
|
157 | + public function testLongOptionDoesNotAllowAnArgumentException() |
|
158 | + { |
|
159 | + $args = [ |
|
160 | + 'command', |
|
161 | + '--foo=bar', |
|
162 | + ]; |
|
163 | + |
|
164 | + $this->expectException(Exception::class); |
|
165 | + $this->expectExceptionMessage("option --foo doesn't allow an argument"); |
|
166 | + |
|
167 | + Getopt::getopt($args, '', ['foo']); |
|
168 | + } |
|
169 | + |
|
170 | + public function testItHandlesLongParametesWithValues() |
|
171 | + { |
|
172 | + $command = 'command parameter-0 --exec parameter-1 --conf config.xml --optn parameter-2 --optn=content-of-o parameter-n'; |
|
173 | + $args = \explode(' ', $command); |
|
174 | + unset($args[0]); |
|
175 | + $expected = [ |
|
176 | + [ |
|
177 | + ['--exec', null], |
|
178 | + ['--conf', 'config.xml'], |
|
179 | + ['--optn', null], |
|
180 | + ['--optn', 'content-of-o'], |
|
181 | + ], |
|
182 | + [ |
|
183 | + 'parameter-0', |
|
184 | + 'parameter-1', |
|
185 | + 'parameter-2', |
|
186 | + 'parameter-n', |
|
187 | + ], |
|
188 | + ]; |
|
189 | + $actual = Getopt::getopt($args, '', ['exec', 'conf=', 'optn==']); |
|
190 | + $this->assertEquals($expected, $actual); |
|
191 | + } |
|
192 | + |
|
193 | + public function testItHandlesShortParametesWithValues() |
|
194 | + { |
|
195 | + $command = 'command parameter-0 -x parameter-1 -c config.xml -o parameter-2 -ocontent-of-o parameter-n'; |
|
196 | + $args = \explode(' ', $command); |
|
197 | + unset($args[0]); |
|
198 | + $expected = [ |
|
199 | + [ |
|
200 | + ['x', null], |
|
201 | + ['c', 'config.xml'], |
|
202 | + ['o', null], |
|
203 | + ['o', 'content-of-o'], |
|
204 | + ], |
|
205 | + [ |
|
206 | + 'parameter-0', |
|
207 | + 'parameter-1', |
|
208 | + 'parameter-2', |
|
209 | + 'parameter-n', |
|
210 | + ], |
|
211 | + ]; |
|
212 | + $actual = Getopt::getopt($args, 'xc:o::'); |
|
213 | + $this->assertEquals($expected, $actual); |
|
214 | + } |
|
215 | 215 | } |
@@ -14,38 +14,38 @@ |
||
14 | 14 | |
15 | 15 | class RegularExpressionTest extends TestCase |
16 | 16 | { |
17 | - public function validRegexpProvider() |
|
18 | - { |
|
19 | - return [ |
|
20 | - ['#valid regexp#', 'valid regexp', 1], |
|
21 | - [';val.*xp;', 'valid regexp', 1], |
|
22 | - ['/val.*xp/i', 'VALID REGEXP', 1], |
|
23 | - ['/a val.*p/','valid regexp', 0], |
|
24 | - ]; |
|
25 | - } |
|
17 | + public function validRegexpProvider() |
|
18 | + { |
|
19 | + return [ |
|
20 | + ['#valid regexp#', 'valid regexp', 1], |
|
21 | + [';val.*xp;', 'valid regexp', 1], |
|
22 | + ['/val.*xp/i', 'VALID REGEXP', 1], |
|
23 | + ['/a val.*p/','valid regexp', 0], |
|
24 | + ]; |
|
25 | + } |
|
26 | 26 | |
27 | - public function invalidRegexpProvider() |
|
28 | - { |
|
29 | - return [ |
|
30 | - ['valid regexp', 'valid regexp'], |
|
31 | - [';val.*xp', 'valid regexp'], |
|
32 | - ['val.*xp/i', 'VALID REGEXP'], |
|
33 | - ]; |
|
34 | - } |
|
27 | + public function invalidRegexpProvider() |
|
28 | + { |
|
29 | + return [ |
|
30 | + ['valid regexp', 'valid regexp'], |
|
31 | + [';val.*xp', 'valid regexp'], |
|
32 | + ['val.*xp/i', 'VALID REGEXP'], |
|
33 | + ]; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @dataProvider validRegexpProvider |
|
38 | - */ |
|
39 | - public function testValidRegex($pattern, $subject, $return) |
|
40 | - { |
|
41 | - $this->assertEquals($return, RegularExpression::safeMatch($pattern, $subject)); |
|
42 | - } |
|
36 | + /** |
|
37 | + * @dataProvider validRegexpProvider |
|
38 | + */ |
|
39 | + public function testValidRegex($pattern, $subject, $return) |
|
40 | + { |
|
41 | + $this->assertEquals($return, RegularExpression::safeMatch($pattern, $subject)); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @dataProvider invalidRegexpProvider |
|
46 | - */ |
|
47 | - public function testInvalidRegex($pattern, $subject) |
|
48 | - { |
|
49 | - $this->assertFalse(RegularExpression::safeMatch($pattern, $subject)); |
|
50 | - } |
|
44 | + /** |
|
45 | + * @dataProvider invalidRegexpProvider |
|
46 | + */ |
|
47 | + public function testInvalidRegex($pattern, $subject) |
|
48 | + { |
|
49 | + $this->assertFalse(RegularExpression::safeMatch($pattern, $subject)); |
|
50 | + } |
|
51 | 51 | } |
@@ -20,7 +20,7 @@ |
||
20 | 20 | ['#valid regexp#', 'valid regexp', 1], |
21 | 21 | [';val.*xp;', 'valid regexp', 1], |
22 | 22 | ['/val.*xp/i', 'VALID REGEXP', 1], |
23 | - ['/a val.*p/','valid regexp', 0], |
|
23 | + ['/a val.*p/', 'valid regexp', 0], |
|
24 | 24 | ]; |
25 | 25 | } |
26 | 26 |
@@ -14,60 +14,60 @@ |
||
14 | 14 | |
15 | 15 | class NamePrettifierTest extends TestCase |
16 | 16 | { |
17 | - /** |
|
18 | - * @var NamePrettifier |
|
19 | - */ |
|
20 | - private $namePrettifier; |
|
17 | + /** |
|
18 | + * @var NamePrettifier |
|
19 | + */ |
|
20 | + private $namePrettifier; |
|
21 | 21 | |
22 | - protected function setUp() |
|
23 | - { |
|
24 | - $this->namePrettifier = new NamePrettifier; |
|
25 | - } |
|
22 | + protected function setUp() |
|
23 | + { |
|
24 | + $this->namePrettifier = new NamePrettifier; |
|
25 | + } |
|
26 | 26 | |
27 | - public function testTitleHasSensibleDefaults() |
|
28 | - { |
|
29 | - $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTest')); |
|
30 | - $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFoo')); |
|
31 | - $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFooTest')); |
|
32 | - $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('Test\FooTest')); |
|
33 | - } |
|
27 | + public function testTitleHasSensibleDefaults() |
|
28 | + { |
|
29 | + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTest')); |
|
30 | + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFoo')); |
|
31 | + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFooTest')); |
|
32 | + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('Test\FooTest')); |
|
33 | + } |
|
34 | 34 | |
35 | - public function testCaterForUserDefinedSuffix() |
|
36 | - { |
|
37 | - $this->namePrettifier->setSuffix('TestCase'); |
|
38 | - $this->namePrettifier->setPrefix(null); |
|
35 | + public function testCaterForUserDefinedSuffix() |
|
36 | + { |
|
37 | + $this->namePrettifier->setSuffix('TestCase'); |
|
38 | + $this->namePrettifier->setPrefix(null); |
|
39 | 39 | |
40 | - $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTestCase')); |
|
41 | - $this->assertEquals('TestFoo', $this->namePrettifier->prettifyTestClass('TestFoo')); |
|
42 | - $this->assertEquals('FooTest', $this->namePrettifier->prettifyTestClass('FooTest')); |
|
43 | - } |
|
40 | + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTestCase')); |
|
41 | + $this->assertEquals('TestFoo', $this->namePrettifier->prettifyTestClass('TestFoo')); |
|
42 | + $this->assertEquals('FooTest', $this->namePrettifier->prettifyTestClass('FooTest')); |
|
43 | + } |
|
44 | 44 | |
45 | - public function testCaterForUserDefinedPrefix() |
|
46 | - { |
|
47 | - $this->namePrettifier->setSuffix(null); |
|
48 | - $this->namePrettifier->setPrefix('XXX'); |
|
45 | + public function testCaterForUserDefinedPrefix() |
|
46 | + { |
|
47 | + $this->namePrettifier->setSuffix(null); |
|
48 | + $this->namePrettifier->setPrefix('XXX'); |
|
49 | 49 | |
50 | - $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('XXXFoo')); |
|
51 | - $this->assertEquals('TestXXX', $this->namePrettifier->prettifyTestClass('TestXXX')); |
|
52 | - $this->assertEquals('XXX', $this->namePrettifier->prettifyTestClass('XXXXXX')); |
|
53 | - } |
|
50 | + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('XXXFoo')); |
|
51 | + $this->assertEquals('TestXXX', $this->namePrettifier->prettifyTestClass('TestXXX')); |
|
52 | + $this->assertEquals('XXX', $this->namePrettifier->prettifyTestClass('XXXXXX')); |
|
53 | + } |
|
54 | 54 | |
55 | - public function testTestNameIsConvertedToASentence() |
|
56 | - { |
|
57 | - $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('testThisIsATest')); |
|
58 | - $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('testThisIsATest2')); |
|
59 | - $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('this_is_a_test')); |
|
60 | - $this->assertEquals('Foo for bar is 0', $this->namePrettifier->prettifyTestMethod('testFooForBarIs0')); |
|
61 | - $this->assertEquals('Foo for baz is 1', $this->namePrettifier->prettifyTestMethod('testFooForBazIs1')); |
|
62 | - $this->assertEquals('', $this->namePrettifier->prettifyTestMethod('test')); |
|
63 | - } |
|
55 | + public function testTestNameIsConvertedToASentence() |
|
56 | + { |
|
57 | + $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('testThisIsATest')); |
|
58 | + $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('testThisIsATest2')); |
|
59 | + $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('this_is_a_test')); |
|
60 | + $this->assertEquals('Foo for bar is 0', $this->namePrettifier->prettifyTestMethod('testFooForBarIs0')); |
|
61 | + $this->assertEquals('Foo for baz is 1', $this->namePrettifier->prettifyTestMethod('testFooForBazIs1')); |
|
62 | + $this->assertEquals('', $this->namePrettifier->prettifyTestMethod('test')); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @ticket 224 |
|
67 | - */ |
|
68 | - public function testTestNameIsNotGroupedWhenNotInSequence() |
|
69 | - { |
|
70 | - $this->assertEquals('Sets redirect header on 301', $this->namePrettifier->prettifyTestMethod('testSetsRedirectHeaderOn301')); |
|
71 | - $this->assertEquals('Sets redirect header on 302', $this->namePrettifier->prettifyTestMethod('testSetsRedirectHeaderOn302')); |
|
72 | - } |
|
65 | + /** |
|
66 | + * @ticket 224 |
|
67 | + */ |
|
68 | + public function testTestNameIsNotGroupedWhenNotInSequence() |
|
69 | + { |
|
70 | + $this->assertEquals('Sets redirect header on 301', $this->namePrettifier->prettifyTestMethod('testSetsRedirectHeaderOn301')); |
|
71 | + $this->assertEquals('Sets redirect header on 302', $this->namePrettifier->prettifyTestMethod('testSetsRedirectHeaderOn302')); |
|
72 | + } |
|
73 | 73 | } |
@@ -14,23 +14,23 @@ |
||
14 | 14 | |
15 | 15 | class GlobalStateTest extends TestCase |
16 | 16 | { |
17 | - public function testIncludedFilesAsStringSkipsVfsProtocols() |
|
18 | - { |
|
19 | - $dir = __DIR__; |
|
20 | - $files = [ |
|
21 | - 'phpunit', // The 0 index is not used |
|
22 | - $dir . '/ConfigurationTest.php', |
|
23 | - $dir . '/GlobalStateTest.php', |
|
24 | - 'vfs://' . $dir . '/RegexTest.php', |
|
25 | - 'phpvfs53e46260465c7://' . $dir . '/TestTest.php', |
|
26 | - 'file://' . $dir . '/XmlTest.php' |
|
27 | - ]; |
|
17 | + public function testIncludedFilesAsStringSkipsVfsProtocols() |
|
18 | + { |
|
19 | + $dir = __DIR__; |
|
20 | + $files = [ |
|
21 | + 'phpunit', // The 0 index is not used |
|
22 | + $dir . '/ConfigurationTest.php', |
|
23 | + $dir . '/GlobalStateTest.php', |
|
24 | + 'vfs://' . $dir . '/RegexTest.php', |
|
25 | + 'phpvfs53e46260465c7://' . $dir . '/TestTest.php', |
|
26 | + 'file://' . $dir . '/XmlTest.php' |
|
27 | + ]; |
|
28 | 28 | |
29 | - $this->assertEquals( |
|
30 | - "require_once '" . $dir . "/ConfigurationTest.php';\n" . |
|
31 | - "require_once '" . $dir . "/GlobalStateTest.php';\n" . |
|
32 | - "require_once 'file://" . $dir . "/XmlTest.php';\n", |
|
33 | - GlobalState::processIncludedFilesAsString($files) |
|
34 | - ); |
|
35 | - } |
|
29 | + $this->assertEquals( |
|
30 | + "require_once '" . $dir . "/ConfigurationTest.php';\n" . |
|
31 | + "require_once '" . $dir . "/GlobalStateTest.php';\n" . |
|
32 | + "require_once 'file://" . $dir . "/XmlTest.php';\n", |
|
33 | + GlobalState::processIncludedFilesAsString($files) |
|
34 | + ); |
|
35 | + } |
|
36 | 36 | } |
@@ -19,17 +19,17 @@ |
||
19 | 19 | $dir = __DIR__; |
20 | 20 | $files = [ |
21 | 21 | 'phpunit', // The 0 index is not used |
22 | - $dir . '/ConfigurationTest.php', |
|
23 | - $dir . '/GlobalStateTest.php', |
|
24 | - 'vfs://' . $dir . '/RegexTest.php', |
|
25 | - 'phpvfs53e46260465c7://' . $dir . '/TestTest.php', |
|
26 | - 'file://' . $dir . '/XmlTest.php' |
|
22 | + $dir.'/ConfigurationTest.php', |
|
23 | + $dir.'/GlobalStateTest.php', |
|
24 | + 'vfs://'.$dir.'/RegexTest.php', |
|
25 | + 'phpvfs53e46260465c7://'.$dir.'/TestTest.php', |
|
26 | + 'file://'.$dir.'/XmlTest.php' |
|
27 | 27 | ]; |
28 | 28 | |
29 | 29 | $this->assertEquals( |
30 | - "require_once '" . $dir . "/ConfigurationTest.php';\n" . |
|
31 | - "require_once '" . $dir . "/GlobalStateTest.php';\n" . |
|
32 | - "require_once 'file://" . $dir . "/XmlTest.php';\n", |
|
30 | + "require_once '".$dir."/ConfigurationTest.php';\n". |
|
31 | + "require_once '".$dir."/GlobalStateTest.php';\n". |
|
32 | + "require_once 'file://".$dir."/XmlTest.php';\n", |
|
33 | 33 | GlobalState::processIncludedFilesAsString($files) |
34 | 34 | ); |
35 | 35 | } |
@@ -18,985 +18,985 @@ |
||
18 | 18 | |
19 | 19 | class TestTest extends TestCase |
20 | 20 | { |
21 | - /** |
|
22 | - * @todo Split up in separate tests |
|
23 | - */ |
|
24 | - public function testGetExpectedException() |
|
25 | - { |
|
26 | - $this->assertArraySubset( |
|
27 | - ['class' => 'FooBarBaz', 'code' => null, 'message' => ''], |
|
28 | - Test::getExpectedException(\ExceptionTest::class, 'testOne') |
|
29 | - ); |
|
30 | - |
|
31 | - $this->assertArraySubset( |
|
32 | - ['class' => 'Foo_Bar_Baz', 'code' => null, 'message' => ''], |
|
33 | - Test::getExpectedException(\ExceptionTest::class, 'testTwo') |
|
34 | - ); |
|
35 | - |
|
36 | - $this->assertArraySubset( |
|
37 | - ['class' => \Foo\Bar\Baz::class, 'code' => null, 'message' => ''], |
|
38 | - Test::getExpectedException(\ExceptionTest::class, 'testThree') |
|
39 | - ); |
|
40 | - |
|
41 | - $this->assertArraySubset( |
|
42 | - ['class' => 'ほげ', 'code' => null, 'message' => ''], |
|
43 | - Test::getExpectedException(\ExceptionTest::class, 'testFour') |
|
44 | - ); |
|
45 | - |
|
46 | - $this->assertArraySubset( |
|
47 | - ['class' => 'Class', 'code' => 1234, 'message' => 'Message'], |
|
48 | - Test::getExpectedException(\ExceptionTest::class, 'testFive') |
|
49 | - ); |
|
50 | - |
|
51 | - $this->assertArraySubset( |
|
52 | - ['class' => 'Class', 'code' => 1234, 'message' => 'Message'], |
|
53 | - Test::getExpectedException(\ExceptionTest::class, 'testSix') |
|
54 | - ); |
|
55 | - |
|
56 | - $this->assertArraySubset( |
|
57 | - ['class' => 'Class', 'code' => 'ExceptionCode', 'message' => 'Message'], |
|
58 | - Test::getExpectedException(\ExceptionTest::class, 'testSeven') |
|
59 | - ); |
|
60 | - |
|
61 | - $this->assertArraySubset( |
|
62 | - ['class' => 'Class', 'code' => 0, 'message' => 'Message'], |
|
63 | - Test::getExpectedException(\ExceptionTest::class, 'testEight') |
|
64 | - ); |
|
65 | - |
|
66 | - $this->assertArraySubset( |
|
67 | - ['class' => 'Class', 'code' => \ExceptionTest::ERROR_CODE, 'message' => \ExceptionTest::ERROR_MESSAGE], |
|
68 | - Test::getExpectedException(\ExceptionTest::class, 'testNine') |
|
69 | - ); |
|
70 | - |
|
71 | - $this->assertArraySubset( |
|
72 | - ['class' => 'Class', 'code' => null, 'message' => ''], |
|
73 | - Test::getExpectedException(\ExceptionTest::class, 'testSingleLine') |
|
74 | - ); |
|
75 | - |
|
76 | - $this->assertArraySubset( |
|
77 | - ['class' => 'Class', 'code' => \My\Space\ExceptionNamespaceTest::ERROR_CODE, 'message' => \My\Space\ExceptionNamespaceTest::ERROR_MESSAGE], |
|
78 | - Test::getExpectedException(\My\Space\ExceptionNamespaceTest::class, 'testConstants') |
|
79 | - ); |
|
80 | - |
|
81 | - // Ensure the Class::CONST expression is only evaluated when the constant really exists |
|
82 | - $this->assertArraySubset( |
|
83 | - ['class' => 'Class', 'code' => 'ExceptionTest::UNKNOWN_CODE_CONSTANT', 'message' => 'ExceptionTest::UNKNOWN_MESSAGE_CONSTANT'], |
|
84 | - Test::getExpectedException(\ExceptionTest::class, 'testUnknownConstants') |
|
85 | - ); |
|
86 | - |
|
87 | - $this->assertArraySubset( |
|
88 | - ['class' => 'Class', 'code' => 'My\Space\ExceptionNamespaceTest::UNKNOWN_CODE_CONSTANT', 'message' => 'My\Space\ExceptionNamespaceTest::UNKNOWN_MESSAGE_CONSTANT'], |
|
89 | - Test::getExpectedException(\My\Space\ExceptionNamespaceTest::class, 'testUnknownConstants') |
|
90 | - ); |
|
91 | - } |
|
92 | - |
|
93 | - public function testGetExpectedRegExp() |
|
94 | - { |
|
95 | - $this->assertArraySubset( |
|
96 | - ['message_regex' => '#regex#'], |
|
97 | - Test::getExpectedException(\ExceptionTest::class, 'testWithRegexMessage') |
|
98 | - ); |
|
99 | - |
|
100 | - $this->assertArraySubset( |
|
101 | - ['message_regex' => '#regex#'], |
|
102 | - Test::getExpectedException(\ExceptionTest::class, 'testWithRegexMessageFromClassConstant') |
|
103 | - ); |
|
104 | - |
|
105 | - $this->assertArraySubset( |
|
106 | - ['message_regex' => 'ExceptionTest::UNKNOWN_MESSAGE_REGEX_CONSTANT'], |
|
107 | - Test::getExpectedException(\ExceptionTest::class, 'testWithUnknowRegexMessageFromClassConstant') |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @dataProvider requirementsProvider |
|
113 | - */ |
|
114 | - public function testGetRequirements($test, $result) |
|
115 | - { |
|
116 | - $this->assertEquals( |
|
117 | - $result, |
|
118 | - Test::getRequirements(\RequirementsTest::class, $test) |
|
119 | - ); |
|
120 | - } |
|
121 | - |
|
122 | - public function requirementsProvider() |
|
123 | - { |
|
124 | - return [ |
|
125 | - ['testOne', []], |
|
126 | - ['testTwo', ['PHPUnit' => ['version' => '1.0', 'operator' => '']]], |
|
127 | - ['testThree', ['PHP' => ['version' => '2.0', 'operator' => '']]], |
|
128 | - ['testFour', [ |
|
129 | - 'PHPUnit' => ['version' => '2.0', 'operator' => ''], |
|
130 | - 'PHP' => ['version' => '1.0', 'operator' => ''], |
|
131 | - ]], |
|
132 | - ['testFive', ['PHP' => ['version' => '5.4.0RC6', 'operator' => '']]], |
|
133 | - ['testSix', ['PHP' => ['version' => '5.4.0-alpha1', 'operator' => '']]], |
|
134 | - ['testSeven', ['PHP' => ['version' => '5.4.0beta2', 'operator' => '']]], |
|
135 | - ['testEight', ['PHP' => ['version' => '5.4-dev', 'operator' => '']]], |
|
136 | - ['testNine', ['functions' => ['testFunc']]], |
|
137 | - ['testTen', ['extensions' => ['testExt']]], |
|
138 | - ['testEleven', [ |
|
139 | - 'OS' => 'SunOS', |
|
140 | - 'OSFAMILY' => 'Solaris', |
|
141 | - ]], |
|
142 | - [ |
|
143 | - 'testSpace', |
|
144 | - [ |
|
145 | - 'extensions' => ['spl'], |
|
146 | - 'OS' => '.*', |
|
147 | - ], |
|
148 | - ], |
|
149 | - [ |
|
150 | - 'testAllPossibleRequirements', |
|
151 | - [ |
|
152 | - 'PHP' => ['version' => '99-dev', 'operator' => ''], |
|
153 | - 'PHPUnit' => ['version' => '9-dev', 'operator' => ''], |
|
154 | - 'OS' => 'DOESNOTEXIST', |
|
155 | - 'functions' => [ |
|
156 | - 'testFuncOne', |
|
157 | - 'testFuncTwo', |
|
158 | - ], |
|
159 | - 'extensions' => [ |
|
160 | - 'testExtOne', |
|
161 | - 'testExtTwo', |
|
162 | - 'testExtThree', |
|
163 | - ], |
|
164 | - 'extension_versions' => [ |
|
165 | - 'testExtThree' => ['version' => '2.0', 'operator' => ''], |
|
166 | - ], |
|
167 | - ], |
|
168 | - ], |
|
169 | - ['testSpecificExtensionVersion', |
|
170 | - [ |
|
171 | - 'extension_versions' => ['testExt' => ['version' => '1.8.0', 'operator' => '']], |
|
172 | - 'extensions' => ['testExt'] |
|
173 | - ] |
|
174 | - ], |
|
175 | - ['testPHPVersionOperatorLessThan', |
|
176 | - [ |
|
177 | - 'PHP' => ['version' => '5.4', 'operator' => '<'] |
|
178 | - ] |
|
179 | - ], |
|
180 | - ['testPHPVersionOperatorLessThanEquals', |
|
181 | - [ |
|
182 | - 'PHP' => ['version' => '5.4', 'operator' => '<='] |
|
183 | - ] |
|
184 | - ], |
|
185 | - ['testPHPVersionOperatorGreaterThan', |
|
186 | - [ |
|
187 | - 'PHP' => ['version' => '99', 'operator' => '>'] |
|
188 | - ] |
|
189 | - ], |
|
190 | - ['testPHPVersionOperatorGreaterThanEquals', |
|
191 | - [ |
|
192 | - 'PHP' => ['version' => '99', 'operator' => '>='] |
|
193 | - ] |
|
194 | - ], |
|
195 | - ['testPHPVersionOperatorEquals', |
|
196 | - [ |
|
197 | - 'PHP' => ['version' => '5.4', 'operator' => '='] |
|
198 | - ] |
|
199 | - ], |
|
200 | - ['testPHPVersionOperatorDoubleEquals', |
|
201 | - [ |
|
202 | - 'PHP' => ['version' => '5.4', 'operator' => '=='] |
|
203 | - ] |
|
204 | - ], |
|
205 | - ['testPHPVersionOperatorBangEquals', |
|
206 | - [ |
|
207 | - 'PHP' => ['version' => '99', 'operator' => '!='] |
|
208 | - ] |
|
209 | - ], |
|
210 | - ['testPHPVersionOperatorNotEquals', |
|
211 | - [ |
|
212 | - 'PHP' => ['version' => '99', 'operator' => '<>'] |
|
213 | - ] |
|
214 | - ], |
|
215 | - ['testPHPVersionOperatorNoSpace', |
|
216 | - [ |
|
217 | - 'PHP' => ['version' => '99', 'operator' => '>='] |
|
218 | - ] |
|
219 | - ], |
|
220 | - ['testPHPUnitVersionOperatorLessThan', |
|
221 | - [ |
|
222 | - 'PHPUnit' => ['version' => '1.0', 'operator' => '<'] |
|
223 | - ] |
|
224 | - ], |
|
225 | - ['testPHPUnitVersionOperatorLessThanEquals', |
|
226 | - [ |
|
227 | - 'PHPUnit' => ['version' => '1.0', 'operator' => '<='] |
|
228 | - ] |
|
229 | - ], |
|
230 | - ['testPHPUnitVersionOperatorGreaterThan', |
|
231 | - [ |
|
232 | - 'PHPUnit' => ['version' => '99', 'operator' => '>'] |
|
233 | - ] |
|
234 | - ], |
|
235 | - ['testPHPUnitVersionOperatorGreaterThanEquals', |
|
236 | - [ |
|
237 | - 'PHPUnit' => ['version' => '99', 'operator' => '>='] |
|
238 | - ] |
|
239 | - ], |
|
240 | - ['testPHPUnitVersionOperatorEquals', |
|
241 | - [ |
|
242 | - 'PHPUnit' => ['version' => '1.0', 'operator' => '='] |
|
243 | - ] |
|
244 | - ], |
|
245 | - ['testPHPUnitVersionOperatorDoubleEquals', |
|
246 | - [ |
|
247 | - 'PHPUnit' => ['version' => '1.0', 'operator' => '=='] |
|
248 | - ] |
|
249 | - ], |
|
250 | - ['testPHPUnitVersionOperatorBangEquals', |
|
251 | - [ |
|
252 | - 'PHPUnit' => ['version' => '99', 'operator' => '!='] |
|
253 | - ] |
|
254 | - ], |
|
255 | - ['testPHPUnitVersionOperatorNotEquals', |
|
256 | - [ |
|
257 | - 'PHPUnit' => ['version' => '99', 'operator' => '<>'] |
|
258 | - ] |
|
259 | - ], |
|
260 | - ['testPHPUnitVersionOperatorNoSpace', |
|
261 | - [ |
|
262 | - 'PHPUnit' => ['version' => '99', 'operator' => '>='] |
|
263 | - ] |
|
264 | - ], |
|
265 | - ['testExtensionVersionOperatorLessThanEquals', |
|
266 | - [ |
|
267 | - 'extensions' => ['testExtOne'], |
|
268 | - 'extension_versions' => ['testExtOne' => ['version' => '1.0', 'operator' => '<=']] |
|
269 | - ] |
|
270 | - ], |
|
271 | - ['testExtensionVersionOperatorGreaterThan', |
|
272 | - [ |
|
273 | - 'extensions' => ['testExtOne'], |
|
274 | - 'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '>']] |
|
275 | - ] |
|
276 | - ], |
|
277 | - ['testExtensionVersionOperatorGreaterThanEquals', |
|
278 | - [ |
|
279 | - 'extensions' => ['testExtOne'], |
|
280 | - 'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '>=']] |
|
281 | - ] |
|
282 | - ], |
|
283 | - ['testExtensionVersionOperatorEquals', |
|
284 | - [ |
|
285 | - 'extensions' => ['testExtOne'], |
|
286 | - 'extension_versions' => ['testExtOne' => ['version' => '1.0', 'operator' => '=']] |
|
287 | - ] |
|
288 | - ], |
|
289 | - ['testExtensionVersionOperatorDoubleEquals', |
|
290 | - [ |
|
291 | - 'extensions' => ['testExtOne'], |
|
292 | - 'extension_versions' => ['testExtOne' => ['version' => '1.0', 'operator' => '==']] |
|
293 | - ] |
|
294 | - ], |
|
295 | - ['testExtensionVersionOperatorBangEquals', |
|
296 | - [ |
|
297 | - 'extensions' => ['testExtOne'], |
|
298 | - 'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '!=']] |
|
299 | - ] |
|
300 | - ], |
|
301 | - ['testExtensionVersionOperatorNotEquals', |
|
302 | - [ |
|
303 | - 'extensions' => ['testExtOne'], |
|
304 | - 'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '<>']] |
|
305 | - ] |
|
306 | - ], |
|
307 | - ['testExtensionVersionOperatorNoSpace', |
|
308 | - [ |
|
309 | - 'extensions' => ['testExtOne'], |
|
310 | - 'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '>=']] |
|
311 | - ] |
|
312 | - ] |
|
313 | - ]; |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * @dataProvider requirementsWithVersionConstraintsProvider |
|
318 | - */ |
|
319 | - public function testGetRequirementsWithVersionConstraints($test, array $result) |
|
320 | - { |
|
321 | - $requirements = Test::getRequirements(\RequirementsTest::class, $test); |
|
322 | - foreach ($result as $type => $expected_requirement) { |
|
323 | - $this->assertArrayHasKey( |
|
324 | - "{$type}_constraint", |
|
325 | - $requirements |
|
326 | - ); |
|
327 | - $this->assertArrayHasKey( |
|
328 | - 'constraint', |
|
329 | - $requirements["{$type}_constraint"] |
|
330 | - ); |
|
331 | - $this->assertInstanceOf( |
|
332 | - VersionConstraint::class, |
|
333 | - $requirements["{$type}_constraint"]['constraint'] |
|
334 | - ); |
|
335 | - $this->assertSame( |
|
336 | - $expected_requirement['constraint'], |
|
337 | - $requirements["{$type}_constraint"]['constraint']->asString() |
|
338 | - ); |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - public function requirementsWithVersionConstraintsProvider() |
|
343 | - { |
|
344 | - return [ |
|
345 | - [ |
|
346 | - 'testVersionConstraintTildeMajor', |
|
347 | - [ |
|
348 | - 'PHP' => [ |
|
349 | - 'constraint' => '~1.0' |
|
350 | - ], |
|
351 | - 'PHPUnit' => [ |
|
352 | - 'constraint' => '~2.0' |
|
353 | - ] |
|
354 | - ] |
|
355 | - ], |
|
356 | - [ |
|
357 | - 'testVersionConstraintCaretMajor', |
|
358 | - [ |
|
359 | - 'PHP' => [ |
|
360 | - 'constraint' => '^1.0' |
|
361 | - ], |
|
362 | - 'PHPUnit' => [ |
|
363 | - 'constraint' => '^2.0' |
|
364 | - ] |
|
365 | - ] |
|
366 | - ], |
|
367 | - [ |
|
368 | - 'testVersionConstraintTildeMinor', |
|
369 | - [ |
|
370 | - 'PHP' => [ |
|
371 | - 'constraint' => '~3.4.7' |
|
372 | - ], |
|
373 | - 'PHPUnit' => [ |
|
374 | - 'constraint' => '~4.7.1' |
|
375 | - ] |
|
376 | - ] |
|
377 | - ], |
|
378 | - [ |
|
379 | - 'testVersionConstraintCaretMinor', |
|
380 | - [ |
|
381 | - 'PHP' => [ |
|
382 | - 'constraint' => '^7.0.17' |
|
383 | - ], |
|
384 | - 'PHPUnit' => [ |
|
385 | - 'constraint' => '^4.7.1' |
|
386 | - ] |
|
387 | - ] |
|
388 | - ], |
|
389 | - [ |
|
390 | - 'testVersionConstraintCaretOr', |
|
391 | - [ |
|
392 | - 'PHP' => [ |
|
393 | - 'constraint' => '^5.6 || ^7.0' |
|
394 | - ], |
|
395 | - 'PHPUnit' => [ |
|
396 | - 'constraint' => '^5.0 || ^6.0' |
|
397 | - ] |
|
398 | - ] |
|
399 | - ], |
|
400 | - [ |
|
401 | - 'testVersionConstraintTildeOr', |
|
402 | - [ |
|
403 | - 'PHP' => [ |
|
404 | - 'constraint' => '~5.6.22 || ~7.0.17' |
|
405 | - ], |
|
406 | - 'PHPUnit' => [ |
|
407 | - 'constraint' => '^5.0.5 || ^6.0.6' |
|
408 | - ] |
|
409 | - ] |
|
410 | - ], |
|
411 | - [ |
|
412 | - 'testVersionConstraintTildeOrCaret', |
|
413 | - [ |
|
414 | - 'PHP' => [ |
|
415 | - 'constraint' => '~5.6.22 || ^7.0' |
|
416 | - ], |
|
417 | - 'PHPUnit' => [ |
|
418 | - 'constraint' => '~5.6.22 || ^7.0' |
|
419 | - ] |
|
420 | - ] |
|
421 | - ], |
|
422 | - [ |
|
423 | - 'testVersionConstraintCaretOrTilde', |
|
424 | - [ |
|
425 | - 'PHP' => [ |
|
426 | - 'constraint' => '^5.6 || ~7.0.17' |
|
427 | - ], |
|
428 | - 'PHPUnit' => [ |
|
429 | - 'constraint' => '^5.6 || ~7.0.17' |
|
430 | - ] |
|
431 | - ] |
|
432 | - ], |
|
433 | - [ |
|
434 | - 'testVersionConstraintRegexpIgnoresWhitespace', |
|
435 | - [ |
|
436 | - 'PHP' => [ |
|
437 | - 'constraint' => '~5.6.22 || ~7.0.17' |
|
438 | - ], |
|
439 | - 'PHPUnit' => [ |
|
440 | - 'constraint' => '~5.6.22 || ~7.0.17' |
|
441 | - ] |
|
442 | - ] |
|
443 | - ] |
|
444 | - ]; |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * @dataProvider requirementsWithInvalidVersionConstraintsThrowsExceptionProvider |
|
449 | - */ |
|
450 | - public function testGetRequirementsWithInvalidVersionConstraintsThrowsException($test) |
|
451 | - { |
|
452 | - $this->expectException(Warning::class); |
|
453 | - Test::getRequirements(\RequirementsTest::class, $test); |
|
454 | - } |
|
455 | - |
|
456 | - public function requirementsWithInvalidVersionConstraintsThrowsExceptionProvider() |
|
457 | - { |
|
458 | - return [ |
|
459 | - ['testVersionConstraintInvalidPhpConstraint'], |
|
460 | - ['testVersionConstraintInvalidPhpUnitConstraint'] |
|
461 | - ]; |
|
462 | - } |
|
463 | - |
|
464 | - public function testGetRequirementsMergesClassAndMethodDocBlocks() |
|
465 | - { |
|
466 | - $expectedAnnotations = [ |
|
467 | - 'PHP' => ['version' => '5.4', 'operator' => ''], |
|
468 | - 'PHPUnit' => ['version' => '3.7', 'operator' => ''], |
|
469 | - 'OS' => 'WINNT', |
|
470 | - 'functions' => [ |
|
471 | - 'testFuncClass', |
|
472 | - 'testFuncMethod', |
|
473 | - ], |
|
474 | - 'extensions' => [ |
|
475 | - 'testExtClass', |
|
476 | - 'testExtMethod', |
|
477 | - ] |
|
478 | - ]; |
|
479 | - |
|
480 | - $this->assertEquals( |
|
481 | - $expectedAnnotations, |
|
482 | - Test::getRequirements(\RequirementsClassDocBlockTest::class, 'testMethod') |
|
483 | - ); |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * @dataProvider missingRequirementsProvider |
|
488 | - */ |
|
489 | - public function testGetMissingRequirements($test, $result) |
|
490 | - { |
|
491 | - $this->assertEquals( |
|
492 | - $result, |
|
493 | - Test::getMissingRequirements(\RequirementsTest::class, $test) |
|
494 | - ); |
|
495 | - } |
|
496 | - |
|
497 | - public function missingRequirementsProvider() |
|
498 | - { |
|
499 | - return [ |
|
500 | - ['testOne', []], |
|
501 | - ['testNine', ['Function testFunc is required.']], |
|
502 | - ['testTen', ['Extension testExt is required.']], |
|
503 | - ['testAlwaysSkip', ['PHPUnit >= 1111111 is required.']], |
|
504 | - ['testAlwaysSkip2', ['PHP >= 9999999 is required.']], |
|
505 | - ['testAlwaysSkip3', ['Operating system matching /DOESNOTEXIST/i is required.']], |
|
506 | - ['testAllPossibleRequirements', [ |
|
507 | - 'PHP >= 99-dev is required.', |
|
508 | - 'PHPUnit >= 9-dev is required.', |
|
509 | - 'Operating system matching /DOESNOTEXIST/i is required.', |
|
510 | - 'Function testFuncOne is required.', |
|
511 | - 'Function testFuncTwo is required.', |
|
512 | - 'Extension testExtOne is required.', |
|
513 | - 'Extension testExtTwo is required.', |
|
514 | - 'Extension testExtThree >= 2.0 is required.', |
|
515 | - ]], |
|
516 | - ['testPHPVersionOperatorLessThan', ['PHP < 5.4 is required.']], |
|
517 | - ['testPHPVersionOperatorLessThanEquals', ['PHP <= 5.4 is required.']], |
|
518 | - ['testPHPVersionOperatorGreaterThan', ['PHP > 99 is required.']], |
|
519 | - ['testPHPVersionOperatorGreaterThanEquals', ['PHP >= 99 is required.']], |
|
520 | - ['testPHPVersionOperatorNoSpace', ['PHP >= 99 is required.']], |
|
521 | - ['testPHPVersionOperatorEquals', ['PHP = 5.4 is required.']], |
|
522 | - ['testPHPVersionOperatorDoubleEquals', ['PHP == 5.4 is required.']], |
|
523 | - ['testPHPUnitVersionOperatorLessThan', ['PHPUnit < 1.0 is required.']], |
|
524 | - ['testPHPUnitVersionOperatorLessThanEquals', ['PHPUnit <= 1.0 is required.']], |
|
525 | - ['testPHPUnitVersionOperatorGreaterThan', ['PHPUnit > 99 is required.']], |
|
526 | - ['testPHPUnitVersionOperatorGreaterThanEquals', ['PHPUnit >= 99 is required.']], |
|
527 | - ['testPHPUnitVersionOperatorEquals', ['PHPUnit = 1.0 is required.']], |
|
528 | - ['testPHPUnitVersionOperatorDoubleEquals', ['PHPUnit == 1.0 is required.']], |
|
529 | - ['testPHPUnitVersionOperatorNoSpace', ['PHPUnit >= 99 is required.']], |
|
530 | - ['testExtensionVersionOperatorLessThan', ['Extension testExtOne < 1.0 is required.']], |
|
531 | - ['testExtensionVersionOperatorLessThanEquals', ['Extension testExtOne <= 1.0 is required.']], |
|
532 | - ['testExtensionVersionOperatorGreaterThan', ['Extension testExtOne > 99 is required.']], |
|
533 | - ['testExtensionVersionOperatorGreaterThanEquals', ['Extension testExtOne >= 99 is required.']], |
|
534 | - ['testExtensionVersionOperatorEquals', ['Extension testExtOne = 1.0 is required.']], |
|
535 | - ['testExtensionVersionOperatorDoubleEquals', ['Extension testExtOne == 1.0 is required.']], |
|
536 | - ['testExtensionVersionOperatorNoSpace', ['Extension testExtOne >= 99 is required.']], |
|
537 | - ['testVersionConstraintTildeMajor', [ |
|
538 | - 'PHP version does not match the required constraint ~1.0.', |
|
539 | - 'PHPUnit version does not match the required constraint ~2.0.' |
|
540 | - ]], |
|
541 | - ['testVersionConstraintCaretMajor', [ |
|
542 | - 'PHP version does not match the required constraint ^1.0.', |
|
543 | - 'PHPUnit version does not match the required constraint ^2.0.' |
|
544 | - ]] |
|
545 | - ]; |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * @todo This test does not really test functionality of \PHPUnit\Util\Test |
|
550 | - */ |
|
551 | - public function testGetProvidedDataRegEx() |
|
552 | - { |
|
553 | - $result = \preg_match(Test::REGEX_DATA_PROVIDER, '@dataProvider method', $matches); |
|
554 | - $this->assertEquals(1, $result); |
|
555 | - $this->assertEquals('method', $matches[1]); |
|
556 | - |
|
557 | - $result = \preg_match(Test::REGEX_DATA_PROVIDER, '@dataProvider class::method', $matches); |
|
558 | - $this->assertEquals(1, $result); |
|
559 | - $this->assertEquals('class::method', $matches[1]); |
|
560 | - |
|
561 | - $result = \preg_match(Test::REGEX_DATA_PROVIDER, '@dataProvider namespace\class::method', $matches); |
|
562 | - $this->assertEquals(1, $result); |
|
563 | - $this->assertEquals('namespace\class::method', $matches[1]); |
|
564 | - |
|
565 | - $result = \preg_match(Test::REGEX_DATA_PROVIDER, '@dataProvider namespace\namespace\class::method', $matches); |
|
566 | - $this->assertEquals(1, $result); |
|
567 | - $this->assertEquals('namespace\namespace\class::method', $matches[1]); |
|
568 | - |
|
569 | - $result = \preg_match(Test::REGEX_DATA_PROVIDER, '@dataProvider メソッド', $matches); |
|
570 | - $this->assertEquals(1, $result); |
|
571 | - $this->assertEquals('メソッド', $matches[1]); |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * Check if all data providers are being merged. |
|
576 | - */ |
|
577 | - public function testMultipleDataProviders() |
|
578 | - { |
|
579 | - $dataSets = Test::getProvidedData(\MultipleDataProviderTest::class, 'testOne'); |
|
580 | - |
|
581 | - $this->assertCount(9, $dataSets); |
|
582 | - |
|
583 | - $aCount = 0; |
|
584 | - $bCount = 0; |
|
585 | - $cCount = 0; |
|
586 | - |
|
587 | - for ($i = 0; $i < 9; $i++) { |
|
588 | - $aCount += $dataSets[$i][0] != null ? 1 : 0; |
|
589 | - $bCount += $dataSets[$i][1] != null ? 1 : 0; |
|
590 | - $cCount += $dataSets[$i][2] != null ? 1 : 0; |
|
591 | - } |
|
592 | - |
|
593 | - $this->assertEquals(3, $aCount); |
|
594 | - $this->assertEquals(3, $bCount); |
|
595 | - $this->assertEquals(3, $cCount); |
|
596 | - } |
|
597 | - |
|
598 | - public function testMultipleYieldIteratorDataProviders() |
|
599 | - { |
|
600 | - $dataSets = Test::getProvidedData(\MultipleDataProviderTest::class, 'testTwo'); |
|
601 | - |
|
602 | - $this->assertEquals(9, \count($dataSets)); |
|
603 | - |
|
604 | - $aCount = 0; |
|
605 | - $bCount = 0; |
|
606 | - $cCount = 0; |
|
607 | - |
|
608 | - for ($i = 0; $i < 9; $i++) { |
|
609 | - $aCount += $dataSets[$i][0] != null ? 1 : 0; |
|
610 | - $bCount += $dataSets[$i][1] != null ? 1 : 0; |
|
611 | - $cCount += $dataSets[$i][2] != null ? 1 : 0; |
|
612 | - } |
|
613 | - |
|
614 | - $this->assertEquals(3, $aCount); |
|
615 | - $this->assertEquals(3, $bCount); |
|
616 | - $this->assertEquals(3, $cCount); |
|
617 | - } |
|
618 | - |
|
619 | - public function testWithVariousIterableDataProviders() |
|
620 | - { |
|
621 | - $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'test'); |
|
622 | - |
|
623 | - $this->assertEquals([ |
|
624 | - ['A'], |
|
625 | - ['B'], |
|
626 | - ['C'], |
|
627 | - ['D'], |
|
628 | - ['E'], |
|
629 | - ['F'], |
|
630 | - ['G'], |
|
631 | - ['H'], |
|
632 | - ['I'], |
|
633 | - ], $dataSets); |
|
634 | - } |
|
635 | - |
|
636 | - public function testTestWithEmptyAnnotation() |
|
637 | - { |
|
638 | - $result = Test::getDataFromTestWithAnnotation("/**\n * @anotherAnnotation\n */"); |
|
639 | - $this->assertNull($result); |
|
640 | - } |
|
641 | - |
|
642 | - public function testTestWithSimpleCase() |
|
643 | - { |
|
644 | - $result = Test::getDataFromTestWithAnnotation('/** |
|
21 | + /** |
|
22 | + * @todo Split up in separate tests |
|
23 | + */ |
|
24 | + public function testGetExpectedException() |
|
25 | + { |
|
26 | + $this->assertArraySubset( |
|
27 | + ['class' => 'FooBarBaz', 'code' => null, 'message' => ''], |
|
28 | + Test::getExpectedException(\ExceptionTest::class, 'testOne') |
|
29 | + ); |
|
30 | + |
|
31 | + $this->assertArraySubset( |
|
32 | + ['class' => 'Foo_Bar_Baz', 'code' => null, 'message' => ''], |
|
33 | + Test::getExpectedException(\ExceptionTest::class, 'testTwo') |
|
34 | + ); |
|
35 | + |
|
36 | + $this->assertArraySubset( |
|
37 | + ['class' => \Foo\Bar\Baz::class, 'code' => null, 'message' => ''], |
|
38 | + Test::getExpectedException(\ExceptionTest::class, 'testThree') |
|
39 | + ); |
|
40 | + |
|
41 | + $this->assertArraySubset( |
|
42 | + ['class' => 'ほげ', 'code' => null, 'message' => ''], |
|
43 | + Test::getExpectedException(\ExceptionTest::class, 'testFour') |
|
44 | + ); |
|
45 | + |
|
46 | + $this->assertArraySubset( |
|
47 | + ['class' => 'Class', 'code' => 1234, 'message' => 'Message'], |
|
48 | + Test::getExpectedException(\ExceptionTest::class, 'testFive') |
|
49 | + ); |
|
50 | + |
|
51 | + $this->assertArraySubset( |
|
52 | + ['class' => 'Class', 'code' => 1234, 'message' => 'Message'], |
|
53 | + Test::getExpectedException(\ExceptionTest::class, 'testSix') |
|
54 | + ); |
|
55 | + |
|
56 | + $this->assertArraySubset( |
|
57 | + ['class' => 'Class', 'code' => 'ExceptionCode', 'message' => 'Message'], |
|
58 | + Test::getExpectedException(\ExceptionTest::class, 'testSeven') |
|
59 | + ); |
|
60 | + |
|
61 | + $this->assertArraySubset( |
|
62 | + ['class' => 'Class', 'code' => 0, 'message' => 'Message'], |
|
63 | + Test::getExpectedException(\ExceptionTest::class, 'testEight') |
|
64 | + ); |
|
65 | + |
|
66 | + $this->assertArraySubset( |
|
67 | + ['class' => 'Class', 'code' => \ExceptionTest::ERROR_CODE, 'message' => \ExceptionTest::ERROR_MESSAGE], |
|
68 | + Test::getExpectedException(\ExceptionTest::class, 'testNine') |
|
69 | + ); |
|
70 | + |
|
71 | + $this->assertArraySubset( |
|
72 | + ['class' => 'Class', 'code' => null, 'message' => ''], |
|
73 | + Test::getExpectedException(\ExceptionTest::class, 'testSingleLine') |
|
74 | + ); |
|
75 | + |
|
76 | + $this->assertArraySubset( |
|
77 | + ['class' => 'Class', 'code' => \My\Space\ExceptionNamespaceTest::ERROR_CODE, 'message' => \My\Space\ExceptionNamespaceTest::ERROR_MESSAGE], |
|
78 | + Test::getExpectedException(\My\Space\ExceptionNamespaceTest::class, 'testConstants') |
|
79 | + ); |
|
80 | + |
|
81 | + // Ensure the Class::CONST expression is only evaluated when the constant really exists |
|
82 | + $this->assertArraySubset( |
|
83 | + ['class' => 'Class', 'code' => 'ExceptionTest::UNKNOWN_CODE_CONSTANT', 'message' => 'ExceptionTest::UNKNOWN_MESSAGE_CONSTANT'], |
|
84 | + Test::getExpectedException(\ExceptionTest::class, 'testUnknownConstants') |
|
85 | + ); |
|
86 | + |
|
87 | + $this->assertArraySubset( |
|
88 | + ['class' => 'Class', 'code' => 'My\Space\ExceptionNamespaceTest::UNKNOWN_CODE_CONSTANT', 'message' => 'My\Space\ExceptionNamespaceTest::UNKNOWN_MESSAGE_CONSTANT'], |
|
89 | + Test::getExpectedException(\My\Space\ExceptionNamespaceTest::class, 'testUnknownConstants') |
|
90 | + ); |
|
91 | + } |
|
92 | + |
|
93 | + public function testGetExpectedRegExp() |
|
94 | + { |
|
95 | + $this->assertArraySubset( |
|
96 | + ['message_regex' => '#regex#'], |
|
97 | + Test::getExpectedException(\ExceptionTest::class, 'testWithRegexMessage') |
|
98 | + ); |
|
99 | + |
|
100 | + $this->assertArraySubset( |
|
101 | + ['message_regex' => '#regex#'], |
|
102 | + Test::getExpectedException(\ExceptionTest::class, 'testWithRegexMessageFromClassConstant') |
|
103 | + ); |
|
104 | + |
|
105 | + $this->assertArraySubset( |
|
106 | + ['message_regex' => 'ExceptionTest::UNKNOWN_MESSAGE_REGEX_CONSTANT'], |
|
107 | + Test::getExpectedException(\ExceptionTest::class, 'testWithUnknowRegexMessageFromClassConstant') |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @dataProvider requirementsProvider |
|
113 | + */ |
|
114 | + public function testGetRequirements($test, $result) |
|
115 | + { |
|
116 | + $this->assertEquals( |
|
117 | + $result, |
|
118 | + Test::getRequirements(\RequirementsTest::class, $test) |
|
119 | + ); |
|
120 | + } |
|
121 | + |
|
122 | + public function requirementsProvider() |
|
123 | + { |
|
124 | + return [ |
|
125 | + ['testOne', []], |
|
126 | + ['testTwo', ['PHPUnit' => ['version' => '1.0', 'operator' => '']]], |
|
127 | + ['testThree', ['PHP' => ['version' => '2.0', 'operator' => '']]], |
|
128 | + ['testFour', [ |
|
129 | + 'PHPUnit' => ['version' => '2.0', 'operator' => ''], |
|
130 | + 'PHP' => ['version' => '1.0', 'operator' => ''], |
|
131 | + ]], |
|
132 | + ['testFive', ['PHP' => ['version' => '5.4.0RC6', 'operator' => '']]], |
|
133 | + ['testSix', ['PHP' => ['version' => '5.4.0-alpha1', 'operator' => '']]], |
|
134 | + ['testSeven', ['PHP' => ['version' => '5.4.0beta2', 'operator' => '']]], |
|
135 | + ['testEight', ['PHP' => ['version' => '5.4-dev', 'operator' => '']]], |
|
136 | + ['testNine', ['functions' => ['testFunc']]], |
|
137 | + ['testTen', ['extensions' => ['testExt']]], |
|
138 | + ['testEleven', [ |
|
139 | + 'OS' => 'SunOS', |
|
140 | + 'OSFAMILY' => 'Solaris', |
|
141 | + ]], |
|
142 | + [ |
|
143 | + 'testSpace', |
|
144 | + [ |
|
145 | + 'extensions' => ['spl'], |
|
146 | + 'OS' => '.*', |
|
147 | + ], |
|
148 | + ], |
|
149 | + [ |
|
150 | + 'testAllPossibleRequirements', |
|
151 | + [ |
|
152 | + 'PHP' => ['version' => '99-dev', 'operator' => ''], |
|
153 | + 'PHPUnit' => ['version' => '9-dev', 'operator' => ''], |
|
154 | + 'OS' => 'DOESNOTEXIST', |
|
155 | + 'functions' => [ |
|
156 | + 'testFuncOne', |
|
157 | + 'testFuncTwo', |
|
158 | + ], |
|
159 | + 'extensions' => [ |
|
160 | + 'testExtOne', |
|
161 | + 'testExtTwo', |
|
162 | + 'testExtThree', |
|
163 | + ], |
|
164 | + 'extension_versions' => [ |
|
165 | + 'testExtThree' => ['version' => '2.0', 'operator' => ''], |
|
166 | + ], |
|
167 | + ], |
|
168 | + ], |
|
169 | + ['testSpecificExtensionVersion', |
|
170 | + [ |
|
171 | + 'extension_versions' => ['testExt' => ['version' => '1.8.0', 'operator' => '']], |
|
172 | + 'extensions' => ['testExt'] |
|
173 | + ] |
|
174 | + ], |
|
175 | + ['testPHPVersionOperatorLessThan', |
|
176 | + [ |
|
177 | + 'PHP' => ['version' => '5.4', 'operator' => '<'] |
|
178 | + ] |
|
179 | + ], |
|
180 | + ['testPHPVersionOperatorLessThanEquals', |
|
181 | + [ |
|
182 | + 'PHP' => ['version' => '5.4', 'operator' => '<='] |
|
183 | + ] |
|
184 | + ], |
|
185 | + ['testPHPVersionOperatorGreaterThan', |
|
186 | + [ |
|
187 | + 'PHP' => ['version' => '99', 'operator' => '>'] |
|
188 | + ] |
|
189 | + ], |
|
190 | + ['testPHPVersionOperatorGreaterThanEquals', |
|
191 | + [ |
|
192 | + 'PHP' => ['version' => '99', 'operator' => '>='] |
|
193 | + ] |
|
194 | + ], |
|
195 | + ['testPHPVersionOperatorEquals', |
|
196 | + [ |
|
197 | + 'PHP' => ['version' => '5.4', 'operator' => '='] |
|
198 | + ] |
|
199 | + ], |
|
200 | + ['testPHPVersionOperatorDoubleEquals', |
|
201 | + [ |
|
202 | + 'PHP' => ['version' => '5.4', 'operator' => '=='] |
|
203 | + ] |
|
204 | + ], |
|
205 | + ['testPHPVersionOperatorBangEquals', |
|
206 | + [ |
|
207 | + 'PHP' => ['version' => '99', 'operator' => '!='] |
|
208 | + ] |
|
209 | + ], |
|
210 | + ['testPHPVersionOperatorNotEquals', |
|
211 | + [ |
|
212 | + 'PHP' => ['version' => '99', 'operator' => '<>'] |
|
213 | + ] |
|
214 | + ], |
|
215 | + ['testPHPVersionOperatorNoSpace', |
|
216 | + [ |
|
217 | + 'PHP' => ['version' => '99', 'operator' => '>='] |
|
218 | + ] |
|
219 | + ], |
|
220 | + ['testPHPUnitVersionOperatorLessThan', |
|
221 | + [ |
|
222 | + 'PHPUnit' => ['version' => '1.0', 'operator' => '<'] |
|
223 | + ] |
|
224 | + ], |
|
225 | + ['testPHPUnitVersionOperatorLessThanEquals', |
|
226 | + [ |
|
227 | + 'PHPUnit' => ['version' => '1.0', 'operator' => '<='] |
|
228 | + ] |
|
229 | + ], |
|
230 | + ['testPHPUnitVersionOperatorGreaterThan', |
|
231 | + [ |
|
232 | + 'PHPUnit' => ['version' => '99', 'operator' => '>'] |
|
233 | + ] |
|
234 | + ], |
|
235 | + ['testPHPUnitVersionOperatorGreaterThanEquals', |
|
236 | + [ |
|
237 | + 'PHPUnit' => ['version' => '99', 'operator' => '>='] |
|
238 | + ] |
|
239 | + ], |
|
240 | + ['testPHPUnitVersionOperatorEquals', |
|
241 | + [ |
|
242 | + 'PHPUnit' => ['version' => '1.0', 'operator' => '='] |
|
243 | + ] |
|
244 | + ], |
|
245 | + ['testPHPUnitVersionOperatorDoubleEquals', |
|
246 | + [ |
|
247 | + 'PHPUnit' => ['version' => '1.0', 'operator' => '=='] |
|
248 | + ] |
|
249 | + ], |
|
250 | + ['testPHPUnitVersionOperatorBangEquals', |
|
251 | + [ |
|
252 | + 'PHPUnit' => ['version' => '99', 'operator' => '!='] |
|
253 | + ] |
|
254 | + ], |
|
255 | + ['testPHPUnitVersionOperatorNotEquals', |
|
256 | + [ |
|
257 | + 'PHPUnit' => ['version' => '99', 'operator' => '<>'] |
|
258 | + ] |
|
259 | + ], |
|
260 | + ['testPHPUnitVersionOperatorNoSpace', |
|
261 | + [ |
|
262 | + 'PHPUnit' => ['version' => '99', 'operator' => '>='] |
|
263 | + ] |
|
264 | + ], |
|
265 | + ['testExtensionVersionOperatorLessThanEquals', |
|
266 | + [ |
|
267 | + 'extensions' => ['testExtOne'], |
|
268 | + 'extension_versions' => ['testExtOne' => ['version' => '1.0', 'operator' => '<=']] |
|
269 | + ] |
|
270 | + ], |
|
271 | + ['testExtensionVersionOperatorGreaterThan', |
|
272 | + [ |
|
273 | + 'extensions' => ['testExtOne'], |
|
274 | + 'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '>']] |
|
275 | + ] |
|
276 | + ], |
|
277 | + ['testExtensionVersionOperatorGreaterThanEquals', |
|
278 | + [ |
|
279 | + 'extensions' => ['testExtOne'], |
|
280 | + 'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '>=']] |
|
281 | + ] |
|
282 | + ], |
|
283 | + ['testExtensionVersionOperatorEquals', |
|
284 | + [ |
|
285 | + 'extensions' => ['testExtOne'], |
|
286 | + 'extension_versions' => ['testExtOne' => ['version' => '1.0', 'operator' => '=']] |
|
287 | + ] |
|
288 | + ], |
|
289 | + ['testExtensionVersionOperatorDoubleEquals', |
|
290 | + [ |
|
291 | + 'extensions' => ['testExtOne'], |
|
292 | + 'extension_versions' => ['testExtOne' => ['version' => '1.0', 'operator' => '==']] |
|
293 | + ] |
|
294 | + ], |
|
295 | + ['testExtensionVersionOperatorBangEquals', |
|
296 | + [ |
|
297 | + 'extensions' => ['testExtOne'], |
|
298 | + 'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '!=']] |
|
299 | + ] |
|
300 | + ], |
|
301 | + ['testExtensionVersionOperatorNotEquals', |
|
302 | + [ |
|
303 | + 'extensions' => ['testExtOne'], |
|
304 | + 'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '<>']] |
|
305 | + ] |
|
306 | + ], |
|
307 | + ['testExtensionVersionOperatorNoSpace', |
|
308 | + [ |
|
309 | + 'extensions' => ['testExtOne'], |
|
310 | + 'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '>=']] |
|
311 | + ] |
|
312 | + ] |
|
313 | + ]; |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * @dataProvider requirementsWithVersionConstraintsProvider |
|
318 | + */ |
|
319 | + public function testGetRequirementsWithVersionConstraints($test, array $result) |
|
320 | + { |
|
321 | + $requirements = Test::getRequirements(\RequirementsTest::class, $test); |
|
322 | + foreach ($result as $type => $expected_requirement) { |
|
323 | + $this->assertArrayHasKey( |
|
324 | + "{$type}_constraint", |
|
325 | + $requirements |
|
326 | + ); |
|
327 | + $this->assertArrayHasKey( |
|
328 | + 'constraint', |
|
329 | + $requirements["{$type}_constraint"] |
|
330 | + ); |
|
331 | + $this->assertInstanceOf( |
|
332 | + VersionConstraint::class, |
|
333 | + $requirements["{$type}_constraint"]['constraint'] |
|
334 | + ); |
|
335 | + $this->assertSame( |
|
336 | + $expected_requirement['constraint'], |
|
337 | + $requirements["{$type}_constraint"]['constraint']->asString() |
|
338 | + ); |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + public function requirementsWithVersionConstraintsProvider() |
|
343 | + { |
|
344 | + return [ |
|
345 | + [ |
|
346 | + 'testVersionConstraintTildeMajor', |
|
347 | + [ |
|
348 | + 'PHP' => [ |
|
349 | + 'constraint' => '~1.0' |
|
350 | + ], |
|
351 | + 'PHPUnit' => [ |
|
352 | + 'constraint' => '~2.0' |
|
353 | + ] |
|
354 | + ] |
|
355 | + ], |
|
356 | + [ |
|
357 | + 'testVersionConstraintCaretMajor', |
|
358 | + [ |
|
359 | + 'PHP' => [ |
|
360 | + 'constraint' => '^1.0' |
|
361 | + ], |
|
362 | + 'PHPUnit' => [ |
|
363 | + 'constraint' => '^2.0' |
|
364 | + ] |
|
365 | + ] |
|
366 | + ], |
|
367 | + [ |
|
368 | + 'testVersionConstraintTildeMinor', |
|
369 | + [ |
|
370 | + 'PHP' => [ |
|
371 | + 'constraint' => '~3.4.7' |
|
372 | + ], |
|
373 | + 'PHPUnit' => [ |
|
374 | + 'constraint' => '~4.7.1' |
|
375 | + ] |
|
376 | + ] |
|
377 | + ], |
|
378 | + [ |
|
379 | + 'testVersionConstraintCaretMinor', |
|
380 | + [ |
|
381 | + 'PHP' => [ |
|
382 | + 'constraint' => '^7.0.17' |
|
383 | + ], |
|
384 | + 'PHPUnit' => [ |
|
385 | + 'constraint' => '^4.7.1' |
|
386 | + ] |
|
387 | + ] |
|
388 | + ], |
|
389 | + [ |
|
390 | + 'testVersionConstraintCaretOr', |
|
391 | + [ |
|
392 | + 'PHP' => [ |
|
393 | + 'constraint' => '^5.6 || ^7.0' |
|
394 | + ], |
|
395 | + 'PHPUnit' => [ |
|
396 | + 'constraint' => '^5.0 || ^6.0' |
|
397 | + ] |
|
398 | + ] |
|
399 | + ], |
|
400 | + [ |
|
401 | + 'testVersionConstraintTildeOr', |
|
402 | + [ |
|
403 | + 'PHP' => [ |
|
404 | + 'constraint' => '~5.6.22 || ~7.0.17' |
|
405 | + ], |
|
406 | + 'PHPUnit' => [ |
|
407 | + 'constraint' => '^5.0.5 || ^6.0.6' |
|
408 | + ] |
|
409 | + ] |
|
410 | + ], |
|
411 | + [ |
|
412 | + 'testVersionConstraintTildeOrCaret', |
|
413 | + [ |
|
414 | + 'PHP' => [ |
|
415 | + 'constraint' => '~5.6.22 || ^7.0' |
|
416 | + ], |
|
417 | + 'PHPUnit' => [ |
|
418 | + 'constraint' => '~5.6.22 || ^7.0' |
|
419 | + ] |
|
420 | + ] |
|
421 | + ], |
|
422 | + [ |
|
423 | + 'testVersionConstraintCaretOrTilde', |
|
424 | + [ |
|
425 | + 'PHP' => [ |
|
426 | + 'constraint' => '^5.6 || ~7.0.17' |
|
427 | + ], |
|
428 | + 'PHPUnit' => [ |
|
429 | + 'constraint' => '^5.6 || ~7.0.17' |
|
430 | + ] |
|
431 | + ] |
|
432 | + ], |
|
433 | + [ |
|
434 | + 'testVersionConstraintRegexpIgnoresWhitespace', |
|
435 | + [ |
|
436 | + 'PHP' => [ |
|
437 | + 'constraint' => '~5.6.22 || ~7.0.17' |
|
438 | + ], |
|
439 | + 'PHPUnit' => [ |
|
440 | + 'constraint' => '~5.6.22 || ~7.0.17' |
|
441 | + ] |
|
442 | + ] |
|
443 | + ] |
|
444 | + ]; |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * @dataProvider requirementsWithInvalidVersionConstraintsThrowsExceptionProvider |
|
449 | + */ |
|
450 | + public function testGetRequirementsWithInvalidVersionConstraintsThrowsException($test) |
|
451 | + { |
|
452 | + $this->expectException(Warning::class); |
|
453 | + Test::getRequirements(\RequirementsTest::class, $test); |
|
454 | + } |
|
455 | + |
|
456 | + public function requirementsWithInvalidVersionConstraintsThrowsExceptionProvider() |
|
457 | + { |
|
458 | + return [ |
|
459 | + ['testVersionConstraintInvalidPhpConstraint'], |
|
460 | + ['testVersionConstraintInvalidPhpUnitConstraint'] |
|
461 | + ]; |
|
462 | + } |
|
463 | + |
|
464 | + public function testGetRequirementsMergesClassAndMethodDocBlocks() |
|
465 | + { |
|
466 | + $expectedAnnotations = [ |
|
467 | + 'PHP' => ['version' => '5.4', 'operator' => ''], |
|
468 | + 'PHPUnit' => ['version' => '3.7', 'operator' => ''], |
|
469 | + 'OS' => 'WINNT', |
|
470 | + 'functions' => [ |
|
471 | + 'testFuncClass', |
|
472 | + 'testFuncMethod', |
|
473 | + ], |
|
474 | + 'extensions' => [ |
|
475 | + 'testExtClass', |
|
476 | + 'testExtMethod', |
|
477 | + ] |
|
478 | + ]; |
|
479 | + |
|
480 | + $this->assertEquals( |
|
481 | + $expectedAnnotations, |
|
482 | + Test::getRequirements(\RequirementsClassDocBlockTest::class, 'testMethod') |
|
483 | + ); |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * @dataProvider missingRequirementsProvider |
|
488 | + */ |
|
489 | + public function testGetMissingRequirements($test, $result) |
|
490 | + { |
|
491 | + $this->assertEquals( |
|
492 | + $result, |
|
493 | + Test::getMissingRequirements(\RequirementsTest::class, $test) |
|
494 | + ); |
|
495 | + } |
|
496 | + |
|
497 | + public function missingRequirementsProvider() |
|
498 | + { |
|
499 | + return [ |
|
500 | + ['testOne', []], |
|
501 | + ['testNine', ['Function testFunc is required.']], |
|
502 | + ['testTen', ['Extension testExt is required.']], |
|
503 | + ['testAlwaysSkip', ['PHPUnit >= 1111111 is required.']], |
|
504 | + ['testAlwaysSkip2', ['PHP >= 9999999 is required.']], |
|
505 | + ['testAlwaysSkip3', ['Operating system matching /DOESNOTEXIST/i is required.']], |
|
506 | + ['testAllPossibleRequirements', [ |
|
507 | + 'PHP >= 99-dev is required.', |
|
508 | + 'PHPUnit >= 9-dev is required.', |
|
509 | + 'Operating system matching /DOESNOTEXIST/i is required.', |
|
510 | + 'Function testFuncOne is required.', |
|
511 | + 'Function testFuncTwo is required.', |
|
512 | + 'Extension testExtOne is required.', |
|
513 | + 'Extension testExtTwo is required.', |
|
514 | + 'Extension testExtThree >= 2.0 is required.', |
|
515 | + ]], |
|
516 | + ['testPHPVersionOperatorLessThan', ['PHP < 5.4 is required.']], |
|
517 | + ['testPHPVersionOperatorLessThanEquals', ['PHP <= 5.4 is required.']], |
|
518 | + ['testPHPVersionOperatorGreaterThan', ['PHP > 99 is required.']], |
|
519 | + ['testPHPVersionOperatorGreaterThanEquals', ['PHP >= 99 is required.']], |
|
520 | + ['testPHPVersionOperatorNoSpace', ['PHP >= 99 is required.']], |
|
521 | + ['testPHPVersionOperatorEquals', ['PHP = 5.4 is required.']], |
|
522 | + ['testPHPVersionOperatorDoubleEquals', ['PHP == 5.4 is required.']], |
|
523 | + ['testPHPUnitVersionOperatorLessThan', ['PHPUnit < 1.0 is required.']], |
|
524 | + ['testPHPUnitVersionOperatorLessThanEquals', ['PHPUnit <= 1.0 is required.']], |
|
525 | + ['testPHPUnitVersionOperatorGreaterThan', ['PHPUnit > 99 is required.']], |
|
526 | + ['testPHPUnitVersionOperatorGreaterThanEquals', ['PHPUnit >= 99 is required.']], |
|
527 | + ['testPHPUnitVersionOperatorEquals', ['PHPUnit = 1.0 is required.']], |
|
528 | + ['testPHPUnitVersionOperatorDoubleEquals', ['PHPUnit == 1.0 is required.']], |
|
529 | + ['testPHPUnitVersionOperatorNoSpace', ['PHPUnit >= 99 is required.']], |
|
530 | + ['testExtensionVersionOperatorLessThan', ['Extension testExtOne < 1.0 is required.']], |
|
531 | + ['testExtensionVersionOperatorLessThanEquals', ['Extension testExtOne <= 1.0 is required.']], |
|
532 | + ['testExtensionVersionOperatorGreaterThan', ['Extension testExtOne > 99 is required.']], |
|
533 | + ['testExtensionVersionOperatorGreaterThanEquals', ['Extension testExtOne >= 99 is required.']], |
|
534 | + ['testExtensionVersionOperatorEquals', ['Extension testExtOne = 1.0 is required.']], |
|
535 | + ['testExtensionVersionOperatorDoubleEquals', ['Extension testExtOne == 1.0 is required.']], |
|
536 | + ['testExtensionVersionOperatorNoSpace', ['Extension testExtOne >= 99 is required.']], |
|
537 | + ['testVersionConstraintTildeMajor', [ |
|
538 | + 'PHP version does not match the required constraint ~1.0.', |
|
539 | + 'PHPUnit version does not match the required constraint ~2.0.' |
|
540 | + ]], |
|
541 | + ['testVersionConstraintCaretMajor', [ |
|
542 | + 'PHP version does not match the required constraint ^1.0.', |
|
543 | + 'PHPUnit version does not match the required constraint ^2.0.' |
|
544 | + ]] |
|
545 | + ]; |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * @todo This test does not really test functionality of \PHPUnit\Util\Test |
|
550 | + */ |
|
551 | + public function testGetProvidedDataRegEx() |
|
552 | + { |
|
553 | + $result = \preg_match(Test::REGEX_DATA_PROVIDER, '@dataProvider method', $matches); |
|
554 | + $this->assertEquals(1, $result); |
|
555 | + $this->assertEquals('method', $matches[1]); |
|
556 | + |
|
557 | + $result = \preg_match(Test::REGEX_DATA_PROVIDER, '@dataProvider class::method', $matches); |
|
558 | + $this->assertEquals(1, $result); |
|
559 | + $this->assertEquals('class::method', $matches[1]); |
|
560 | + |
|
561 | + $result = \preg_match(Test::REGEX_DATA_PROVIDER, '@dataProvider namespace\class::method', $matches); |
|
562 | + $this->assertEquals(1, $result); |
|
563 | + $this->assertEquals('namespace\class::method', $matches[1]); |
|
564 | + |
|
565 | + $result = \preg_match(Test::REGEX_DATA_PROVIDER, '@dataProvider namespace\namespace\class::method', $matches); |
|
566 | + $this->assertEquals(1, $result); |
|
567 | + $this->assertEquals('namespace\namespace\class::method', $matches[1]); |
|
568 | + |
|
569 | + $result = \preg_match(Test::REGEX_DATA_PROVIDER, '@dataProvider メソッド', $matches); |
|
570 | + $this->assertEquals(1, $result); |
|
571 | + $this->assertEquals('メソッド', $matches[1]); |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * Check if all data providers are being merged. |
|
576 | + */ |
|
577 | + public function testMultipleDataProviders() |
|
578 | + { |
|
579 | + $dataSets = Test::getProvidedData(\MultipleDataProviderTest::class, 'testOne'); |
|
580 | + |
|
581 | + $this->assertCount(9, $dataSets); |
|
582 | + |
|
583 | + $aCount = 0; |
|
584 | + $bCount = 0; |
|
585 | + $cCount = 0; |
|
586 | + |
|
587 | + for ($i = 0; $i < 9; $i++) { |
|
588 | + $aCount += $dataSets[$i][0] != null ? 1 : 0; |
|
589 | + $bCount += $dataSets[$i][1] != null ? 1 : 0; |
|
590 | + $cCount += $dataSets[$i][2] != null ? 1 : 0; |
|
591 | + } |
|
592 | + |
|
593 | + $this->assertEquals(3, $aCount); |
|
594 | + $this->assertEquals(3, $bCount); |
|
595 | + $this->assertEquals(3, $cCount); |
|
596 | + } |
|
597 | + |
|
598 | + public function testMultipleYieldIteratorDataProviders() |
|
599 | + { |
|
600 | + $dataSets = Test::getProvidedData(\MultipleDataProviderTest::class, 'testTwo'); |
|
601 | + |
|
602 | + $this->assertEquals(9, \count($dataSets)); |
|
603 | + |
|
604 | + $aCount = 0; |
|
605 | + $bCount = 0; |
|
606 | + $cCount = 0; |
|
607 | + |
|
608 | + for ($i = 0; $i < 9; $i++) { |
|
609 | + $aCount += $dataSets[$i][0] != null ? 1 : 0; |
|
610 | + $bCount += $dataSets[$i][1] != null ? 1 : 0; |
|
611 | + $cCount += $dataSets[$i][2] != null ? 1 : 0; |
|
612 | + } |
|
613 | + |
|
614 | + $this->assertEquals(3, $aCount); |
|
615 | + $this->assertEquals(3, $bCount); |
|
616 | + $this->assertEquals(3, $cCount); |
|
617 | + } |
|
618 | + |
|
619 | + public function testWithVariousIterableDataProviders() |
|
620 | + { |
|
621 | + $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'test'); |
|
622 | + |
|
623 | + $this->assertEquals([ |
|
624 | + ['A'], |
|
625 | + ['B'], |
|
626 | + ['C'], |
|
627 | + ['D'], |
|
628 | + ['E'], |
|
629 | + ['F'], |
|
630 | + ['G'], |
|
631 | + ['H'], |
|
632 | + ['I'], |
|
633 | + ], $dataSets); |
|
634 | + } |
|
635 | + |
|
636 | + public function testTestWithEmptyAnnotation() |
|
637 | + { |
|
638 | + $result = Test::getDataFromTestWithAnnotation("/**\n * @anotherAnnotation\n */"); |
|
639 | + $this->assertNull($result); |
|
640 | + } |
|
641 | + |
|
642 | + public function testTestWithSimpleCase() |
|
643 | + { |
|
644 | + $result = Test::getDataFromTestWithAnnotation('/** |
|
645 | 645 | * @testWith [1] |
646 | 646 | */'); |
647 | - $this->assertEquals([[1]], $result); |
|
648 | - } |
|
647 | + $this->assertEquals([[1]], $result); |
|
648 | + } |
|
649 | 649 | |
650 | - public function testTestWithMultiLineMultiParameterCase() |
|
651 | - { |
|
652 | - $result = Test::getDataFromTestWithAnnotation('/** |
|
650 | + public function testTestWithMultiLineMultiParameterCase() |
|
651 | + { |
|
652 | + $result = Test::getDataFromTestWithAnnotation('/** |
|
653 | 653 | * @testWith [1, 2] |
654 | 654 | * [3, 4] |
655 | 655 | */'); |
656 | - $this->assertEquals([[1, 2], [3, 4]], $result); |
|
657 | - } |
|
656 | + $this->assertEquals([[1, 2], [3, 4]], $result); |
|
657 | + } |
|
658 | 658 | |
659 | - public function testTestWithVariousTypes() |
|
660 | - { |
|
661 | - $result = Test::getDataFromTestWithAnnotation('/** |
|
659 | + public function testTestWithVariousTypes() |
|
660 | + { |
|
661 | + $result = Test::getDataFromTestWithAnnotation('/** |
|
662 | 662 | * @testWith ["ab"] |
663 | 663 | * [true] |
664 | 664 | * [null] |
665 | 665 | */'); |
666 | - $this->assertEquals([['ab'], [true], [null]], $result); |
|
667 | - } |
|
666 | + $this->assertEquals([['ab'], [true], [null]], $result); |
|
667 | + } |
|
668 | 668 | |
669 | - public function testTestWithAnnotationAfter() |
|
670 | - { |
|
671 | - $result = Test::getDataFromTestWithAnnotation('/** |
|
669 | + public function testTestWithAnnotationAfter() |
|
670 | + { |
|
671 | + $result = Test::getDataFromTestWithAnnotation('/** |
|
672 | 672 | * @testWith [1] |
673 | 673 | * [2] |
674 | 674 | * @annotation |
675 | 675 | */'); |
676 | - $this->assertEquals([[1], [2]], $result); |
|
677 | - } |
|
676 | + $this->assertEquals([[1], [2]], $result); |
|
677 | + } |
|
678 | 678 | |
679 | - public function testTestWithSimpleTextAfter() |
|
680 | - { |
|
681 | - $result = Test::getDataFromTestWithAnnotation('/** |
|
679 | + public function testTestWithSimpleTextAfter() |
|
680 | + { |
|
681 | + $result = Test::getDataFromTestWithAnnotation('/** |
|
682 | 682 | * @testWith [1] |
683 | 683 | * [2] |
684 | 684 | * blah blah |
685 | 685 | */'); |
686 | - $this->assertEquals([[1], [2]], $result); |
|
687 | - } |
|
686 | + $this->assertEquals([[1], [2]], $result); |
|
687 | + } |
|
688 | 688 | |
689 | - public function testTestWithCharacterEscape() |
|
690 | - { |
|
691 | - $result = Test::getDataFromTestWithAnnotation('/** |
|
689 | + public function testTestWithCharacterEscape() |
|
690 | + { |
|
691 | + $result = Test::getDataFromTestWithAnnotation('/** |
|
692 | 692 | * @testWith ["\"", "\""] |
693 | 693 | */'); |
694 | - $this->assertEquals([['"', '"']], $result); |
|
695 | - } |
|
694 | + $this->assertEquals([['"', '"']], $result); |
|
695 | + } |
|
696 | 696 | |
697 | - public function testTestWithThrowsProperExceptionIfDatasetCannotBeParsed() |
|
698 | - { |
|
699 | - $this->expectException(Exception::class); |
|
700 | - $this->expectExceptionMessageRegExp('/^The dataset for the @testWith annotation cannot be parsed:/'); |
|
697 | + public function testTestWithThrowsProperExceptionIfDatasetCannotBeParsed() |
|
698 | + { |
|
699 | + $this->expectException(Exception::class); |
|
700 | + $this->expectExceptionMessageRegExp('/^The dataset for the @testWith annotation cannot be parsed:/'); |
|
701 | 701 | |
702 | - Test::getDataFromTestWithAnnotation('/** |
|
702 | + Test::getDataFromTestWithAnnotation('/** |
|
703 | 703 | * @testWith [s] |
704 | 704 | */'); |
705 | - } |
|
705 | + } |
|
706 | 706 | |
707 | - public function testTestWithThrowsProperExceptionIfMultiLineDatasetCannotBeParsed() |
|
708 | - { |
|
709 | - $this->expectException(Exception::class); |
|
710 | - $this->expectExceptionMessageRegExp('/^The dataset for the @testWith annotation cannot be parsed:/'); |
|
707 | + public function testTestWithThrowsProperExceptionIfMultiLineDatasetCannotBeParsed() |
|
708 | + { |
|
709 | + $this->expectException(Exception::class); |
|
710 | + $this->expectExceptionMessageRegExp('/^The dataset for the @testWith annotation cannot be parsed:/'); |
|
711 | 711 | |
712 | - Test::getDataFromTestWithAnnotation('/** |
|
712 | + Test::getDataFromTestWithAnnotation('/** |
|
713 | 713 | * @testWith ["valid"] |
714 | 714 | * [invalid] |
715 | 715 | */'); |
716 | - } |
|
717 | - |
|
718 | - /** |
|
719 | - * @todo Not sure what this test tests (name is misleading at least) |
|
720 | - */ |
|
721 | - public function testParseAnnotation() |
|
722 | - { |
|
723 | - $this->assertEquals( |
|
724 | - ['Foo', 'ほげ'], |
|
725 | - Test::getDependencies(\get_class($this), 'methodForTestParseAnnotation') |
|
726 | - ); |
|
727 | - } |
|
728 | - |
|
729 | - /** |
|
730 | - * @depends Foo |
|
731 | - * @depends ほげ |
|
732 | - * |
|
733 | - * @todo Remove fixture from test class |
|
734 | - */ |
|
735 | - public function methodForTestParseAnnotation() |
|
736 | - { |
|
737 | - } |
|
738 | - |
|
739 | - public function testParseAnnotationThatIsOnlyOneLine() |
|
740 | - { |
|
741 | - $this->assertEquals( |
|
742 | - ['Bar'], |
|
743 | - Test::getDependencies(\get_class($this), 'methodForTestParseAnnotationThatIsOnlyOneLine') |
|
744 | - ); |
|
745 | - } |
|
746 | - |
|
747 | - /** @depends Bar */ |
|
748 | - public function methodForTestParseAnnotationThatIsOnlyOneLine() |
|
749 | - { |
|
750 | - // TODO Remove fixture from test class |
|
751 | - } |
|
752 | - |
|
753 | - /** |
|
754 | - * @dataProvider getLinesToBeCoveredProvider |
|
755 | - */ |
|
756 | - public function testGetLinesToBeCovered($test, $lines) |
|
757 | - { |
|
758 | - if (\strpos($test, 'Namespace') === 0) { |
|
759 | - $expected = [ |
|
760 | - TEST_FILES_PATH . 'NamespaceCoveredClass.php' => $lines |
|
761 | - ]; |
|
762 | - } elseif ($test === 'CoverageNoneTest') { |
|
763 | - $expected = []; |
|
764 | - } elseif ($test === 'CoverageNothingTest') { |
|
765 | - $expected = false; |
|
766 | - } elseif ($test === 'CoverageFunctionTest') { |
|
767 | - $expected = [ |
|
768 | - TEST_FILES_PATH . 'CoveredFunction.php' => $lines |
|
769 | - ]; |
|
770 | - } else { |
|
771 | - $expected = [TEST_FILES_PATH . 'CoveredClass.php' => $lines]; |
|
772 | - } |
|
773 | - |
|
774 | - $this->assertEquals( |
|
775 | - $expected, |
|
776 | - Test::getLinesToBeCovered( |
|
777 | - $test, |
|
778 | - 'testSomething' |
|
779 | - ) |
|
780 | - ); |
|
781 | - } |
|
782 | - |
|
783 | - public function testGetLinesToBeCovered2() |
|
784 | - { |
|
785 | - $this->expectException(CodeCoverageException::class); |
|
786 | - |
|
787 | - Test::getLinesToBeCovered( |
|
788 | - 'NotExistingCoveredElementTest', |
|
789 | - 'testOne' |
|
790 | - ); |
|
791 | - } |
|
792 | - |
|
793 | - public function testGetLinesToBeCovered3() |
|
794 | - { |
|
795 | - $this->expectException(CodeCoverageException::class); |
|
796 | - |
|
797 | - Test::getLinesToBeCovered( |
|
798 | - 'NotExistingCoveredElementTest', |
|
799 | - 'testTwo' |
|
800 | - ); |
|
801 | - } |
|
802 | - |
|
803 | - public function testGetLinesToBeCovered4() |
|
804 | - { |
|
805 | - $this->expectException(CodeCoverageException::class); |
|
806 | - |
|
807 | - Test::getLinesToBeCovered( |
|
808 | - 'NotExistingCoveredElementTest', |
|
809 | - 'testThree' |
|
810 | - ); |
|
811 | - } |
|
812 | - |
|
813 | - public function testGetLinesToBeCoveredSkipsNonExistentMethods() |
|
814 | - { |
|
815 | - $this->assertSame( |
|
816 | - [], |
|
817 | - Test::getLinesToBeCovered( |
|
818 | - 'NotExistingCoveredElementTest', |
|
819 | - 'methodDoesNotExist' |
|
820 | - ) |
|
821 | - ); |
|
822 | - } |
|
823 | - |
|
824 | - public function testTwoCoversDefaultClassAnnoationsAreNotAllowed() |
|
825 | - { |
|
826 | - $this->expectException(CodeCoverageException::class); |
|
827 | - |
|
828 | - Test::getLinesToBeCovered( |
|
829 | - 'CoverageTwoDefaultClassAnnotations', |
|
830 | - 'testSomething' |
|
831 | - ); |
|
832 | - } |
|
833 | - |
|
834 | - public function testFunctionParenthesesAreAllowed() |
|
835 | - { |
|
836 | - $this->assertSame( |
|
837 | - [TEST_FILES_PATH . 'CoveredFunction.php' => \range(2, 4)], |
|
838 | - Test::getLinesToBeCovered( |
|
839 | - 'CoverageFunctionParenthesesTest', |
|
840 | - 'testSomething' |
|
841 | - ) |
|
842 | - ); |
|
843 | - } |
|
844 | - |
|
845 | - public function testFunctionParenthesesAreAllowedWithWhitespace() |
|
846 | - { |
|
847 | - $this->assertSame( |
|
848 | - [TEST_FILES_PATH . 'CoveredFunction.php' => \range(2, 4)], |
|
849 | - Test::getLinesToBeCovered( |
|
850 | - 'CoverageFunctionParenthesesWhitespaceTest', |
|
851 | - 'testSomething' |
|
852 | - ) |
|
853 | - ); |
|
854 | - } |
|
855 | - |
|
856 | - public function testMethodParenthesesAreAllowed() |
|
857 | - { |
|
858 | - $this->assertSame( |
|
859 | - [TEST_FILES_PATH . 'CoveredClass.php' => \range(31, 35)], |
|
860 | - Test::getLinesToBeCovered( |
|
861 | - 'CoverageMethodParenthesesTest', |
|
862 | - 'testSomething' |
|
863 | - ) |
|
864 | - ); |
|
865 | - } |
|
866 | - |
|
867 | - public function testMethodParenthesesAreAllowedWithWhitespace() |
|
868 | - { |
|
869 | - $this->assertSame( |
|
870 | - [TEST_FILES_PATH . 'CoveredClass.php' => \range(31, 35)], |
|
871 | - Test::getLinesToBeCovered( |
|
872 | - 'CoverageMethodParenthesesWhitespaceTest', |
|
873 | - 'testSomething' |
|
874 | - ) |
|
875 | - ); |
|
876 | - } |
|
877 | - |
|
878 | - public function testNamespacedFunctionCanBeCoveredOrUsed() |
|
879 | - { |
|
880 | - $this->assertEquals( |
|
881 | - [ |
|
882 | - TEST_FILES_PATH . 'NamespaceCoveredFunction.php' => \range(4, 7) |
|
883 | - ], |
|
884 | - Test::getLinesToBeCovered( |
|
885 | - \CoverageNamespacedFunctionTest::class, |
|
886 | - 'testFunc' |
|
887 | - ) |
|
888 | - ); |
|
889 | - } |
|
890 | - |
|
891 | - public function getLinesToBeCoveredProvider() |
|
892 | - { |
|
893 | - return [ |
|
894 | - [ |
|
895 | - 'CoverageNoneTest', |
|
896 | - [] |
|
897 | - ], |
|
898 | - [ |
|
899 | - 'CoverageClassExtendedTest', |
|
900 | - \array_merge(\range(19, 36), \range(2, 17)) |
|
901 | - ], |
|
902 | - [ |
|
903 | - 'CoverageClassTest', |
|
904 | - \range(19, 36) |
|
905 | - ], |
|
906 | - [ |
|
907 | - 'CoverageMethodTest', |
|
908 | - \range(31, 35) |
|
909 | - ], |
|
910 | - [ |
|
911 | - 'CoverageMethodOneLineAnnotationTest', |
|
912 | - \range(31, 35) |
|
913 | - ], |
|
914 | - [ |
|
915 | - 'CoverageNotPrivateTest', |
|
916 | - \array_merge(\range(25, 29), \range(31, 35)) |
|
917 | - ], |
|
918 | - [ |
|
919 | - 'CoverageNotProtectedTest', |
|
920 | - \array_merge(\range(21, 23), \range(31, 35)) |
|
921 | - ], |
|
922 | - [ |
|
923 | - 'CoverageNotPublicTest', |
|
924 | - \array_merge(\range(21, 23), \range(25, 29)) |
|
925 | - ], |
|
926 | - [ |
|
927 | - 'CoveragePrivateTest', |
|
928 | - \range(21, 23) |
|
929 | - ], |
|
930 | - [ |
|
931 | - 'CoverageProtectedTest', |
|
932 | - \range(25, 29) |
|
933 | - ], |
|
934 | - [ |
|
935 | - 'CoveragePublicTest', |
|
936 | - \range(31, 35) |
|
937 | - ], |
|
938 | - [ |
|
939 | - 'CoverageFunctionTest', |
|
940 | - \range(2, 4) |
|
941 | - ], |
|
942 | - [ |
|
943 | - 'NamespaceCoverageClassExtendedTest', |
|
944 | - \array_merge(\range(21, 38), \range(4, 19)) |
|
945 | - ], |
|
946 | - [ |
|
947 | - 'NamespaceCoverageClassTest', |
|
948 | - \range(21, 38) |
|
949 | - ], |
|
950 | - [ |
|
951 | - 'NamespaceCoverageMethodTest', |
|
952 | - \range(33, 37) |
|
953 | - ], |
|
954 | - [ |
|
955 | - 'NamespaceCoverageNotPrivateTest', |
|
956 | - \array_merge(\range(27, 31), \range(33, 37)) |
|
957 | - ], |
|
958 | - [ |
|
959 | - 'NamespaceCoverageNotProtectedTest', |
|
960 | - \array_merge(\range(23, 25), \range(33, 37)) |
|
961 | - ], |
|
962 | - [ |
|
963 | - 'NamespaceCoverageNotPublicTest', |
|
964 | - \array_merge(\range(23, 25), \range(27, 31)) |
|
965 | - ], |
|
966 | - [ |
|
967 | - 'NamespaceCoveragePrivateTest', |
|
968 | - \range(23, 25) |
|
969 | - ], |
|
970 | - [ |
|
971 | - 'NamespaceCoverageProtectedTest', |
|
972 | - \range(27, 31) |
|
973 | - ], |
|
974 | - [ |
|
975 | - 'NamespaceCoveragePublicTest', |
|
976 | - \range(33, 37) |
|
977 | - ], |
|
978 | - [ |
|
979 | - 'NamespaceCoverageCoversClassTest', |
|
980 | - \array_merge(\range(23, 25), \range(27, 31), \range(33, 37), \range(6, 8), \range(10, 13), \range(15, 18)) |
|
981 | - ], |
|
982 | - [ |
|
983 | - 'NamespaceCoverageCoversClassPublicTest', |
|
984 | - \range(33, 37) |
|
985 | - ], |
|
986 | - [ |
|
987 | - 'CoverageNothingTest', |
|
988 | - false |
|
989 | - ] |
|
990 | - ]; |
|
991 | - } |
|
992 | - |
|
993 | - public function testParseTestMethodAnnotationsIncorporatesTraits() |
|
994 | - { |
|
995 | - $result = Test::parseTestMethodAnnotations(\ParseTestMethodAnnotationsMock::class); |
|
996 | - |
|
997 | - $this->assertArrayHasKey('class', $result); |
|
998 | - $this->assertArrayHasKey('method', $result); |
|
999 | - $this->assertArrayHasKey('theClassAnnotation', $result['class']); |
|
1000 | - $this->assertArrayHasKey('theTraitAnnotation', $result['class']); |
|
1001 | - } |
|
716 | + } |
|
717 | + |
|
718 | + /** |
|
719 | + * @todo Not sure what this test tests (name is misleading at least) |
|
720 | + */ |
|
721 | + public function testParseAnnotation() |
|
722 | + { |
|
723 | + $this->assertEquals( |
|
724 | + ['Foo', 'ほげ'], |
|
725 | + Test::getDependencies(\get_class($this), 'methodForTestParseAnnotation') |
|
726 | + ); |
|
727 | + } |
|
728 | + |
|
729 | + /** |
|
730 | + * @depends Foo |
|
731 | + * @depends ほげ |
|
732 | + * |
|
733 | + * @todo Remove fixture from test class |
|
734 | + */ |
|
735 | + public function methodForTestParseAnnotation() |
|
736 | + { |
|
737 | + } |
|
738 | + |
|
739 | + public function testParseAnnotationThatIsOnlyOneLine() |
|
740 | + { |
|
741 | + $this->assertEquals( |
|
742 | + ['Bar'], |
|
743 | + Test::getDependencies(\get_class($this), 'methodForTestParseAnnotationThatIsOnlyOneLine') |
|
744 | + ); |
|
745 | + } |
|
746 | + |
|
747 | + /** @depends Bar */ |
|
748 | + public function methodForTestParseAnnotationThatIsOnlyOneLine() |
|
749 | + { |
|
750 | + // TODO Remove fixture from test class |
|
751 | + } |
|
752 | + |
|
753 | + /** |
|
754 | + * @dataProvider getLinesToBeCoveredProvider |
|
755 | + */ |
|
756 | + public function testGetLinesToBeCovered($test, $lines) |
|
757 | + { |
|
758 | + if (\strpos($test, 'Namespace') === 0) { |
|
759 | + $expected = [ |
|
760 | + TEST_FILES_PATH . 'NamespaceCoveredClass.php' => $lines |
|
761 | + ]; |
|
762 | + } elseif ($test === 'CoverageNoneTest') { |
|
763 | + $expected = []; |
|
764 | + } elseif ($test === 'CoverageNothingTest') { |
|
765 | + $expected = false; |
|
766 | + } elseif ($test === 'CoverageFunctionTest') { |
|
767 | + $expected = [ |
|
768 | + TEST_FILES_PATH . 'CoveredFunction.php' => $lines |
|
769 | + ]; |
|
770 | + } else { |
|
771 | + $expected = [TEST_FILES_PATH . 'CoveredClass.php' => $lines]; |
|
772 | + } |
|
773 | + |
|
774 | + $this->assertEquals( |
|
775 | + $expected, |
|
776 | + Test::getLinesToBeCovered( |
|
777 | + $test, |
|
778 | + 'testSomething' |
|
779 | + ) |
|
780 | + ); |
|
781 | + } |
|
782 | + |
|
783 | + public function testGetLinesToBeCovered2() |
|
784 | + { |
|
785 | + $this->expectException(CodeCoverageException::class); |
|
786 | + |
|
787 | + Test::getLinesToBeCovered( |
|
788 | + 'NotExistingCoveredElementTest', |
|
789 | + 'testOne' |
|
790 | + ); |
|
791 | + } |
|
792 | + |
|
793 | + public function testGetLinesToBeCovered3() |
|
794 | + { |
|
795 | + $this->expectException(CodeCoverageException::class); |
|
796 | + |
|
797 | + Test::getLinesToBeCovered( |
|
798 | + 'NotExistingCoveredElementTest', |
|
799 | + 'testTwo' |
|
800 | + ); |
|
801 | + } |
|
802 | + |
|
803 | + public function testGetLinesToBeCovered4() |
|
804 | + { |
|
805 | + $this->expectException(CodeCoverageException::class); |
|
806 | + |
|
807 | + Test::getLinesToBeCovered( |
|
808 | + 'NotExistingCoveredElementTest', |
|
809 | + 'testThree' |
|
810 | + ); |
|
811 | + } |
|
812 | + |
|
813 | + public function testGetLinesToBeCoveredSkipsNonExistentMethods() |
|
814 | + { |
|
815 | + $this->assertSame( |
|
816 | + [], |
|
817 | + Test::getLinesToBeCovered( |
|
818 | + 'NotExistingCoveredElementTest', |
|
819 | + 'methodDoesNotExist' |
|
820 | + ) |
|
821 | + ); |
|
822 | + } |
|
823 | + |
|
824 | + public function testTwoCoversDefaultClassAnnoationsAreNotAllowed() |
|
825 | + { |
|
826 | + $this->expectException(CodeCoverageException::class); |
|
827 | + |
|
828 | + Test::getLinesToBeCovered( |
|
829 | + 'CoverageTwoDefaultClassAnnotations', |
|
830 | + 'testSomething' |
|
831 | + ); |
|
832 | + } |
|
833 | + |
|
834 | + public function testFunctionParenthesesAreAllowed() |
|
835 | + { |
|
836 | + $this->assertSame( |
|
837 | + [TEST_FILES_PATH . 'CoveredFunction.php' => \range(2, 4)], |
|
838 | + Test::getLinesToBeCovered( |
|
839 | + 'CoverageFunctionParenthesesTest', |
|
840 | + 'testSomething' |
|
841 | + ) |
|
842 | + ); |
|
843 | + } |
|
844 | + |
|
845 | + public function testFunctionParenthesesAreAllowedWithWhitespace() |
|
846 | + { |
|
847 | + $this->assertSame( |
|
848 | + [TEST_FILES_PATH . 'CoveredFunction.php' => \range(2, 4)], |
|
849 | + Test::getLinesToBeCovered( |
|
850 | + 'CoverageFunctionParenthesesWhitespaceTest', |
|
851 | + 'testSomething' |
|
852 | + ) |
|
853 | + ); |
|
854 | + } |
|
855 | + |
|
856 | + public function testMethodParenthesesAreAllowed() |
|
857 | + { |
|
858 | + $this->assertSame( |
|
859 | + [TEST_FILES_PATH . 'CoveredClass.php' => \range(31, 35)], |
|
860 | + Test::getLinesToBeCovered( |
|
861 | + 'CoverageMethodParenthesesTest', |
|
862 | + 'testSomething' |
|
863 | + ) |
|
864 | + ); |
|
865 | + } |
|
866 | + |
|
867 | + public function testMethodParenthesesAreAllowedWithWhitespace() |
|
868 | + { |
|
869 | + $this->assertSame( |
|
870 | + [TEST_FILES_PATH . 'CoveredClass.php' => \range(31, 35)], |
|
871 | + Test::getLinesToBeCovered( |
|
872 | + 'CoverageMethodParenthesesWhitespaceTest', |
|
873 | + 'testSomething' |
|
874 | + ) |
|
875 | + ); |
|
876 | + } |
|
877 | + |
|
878 | + public function testNamespacedFunctionCanBeCoveredOrUsed() |
|
879 | + { |
|
880 | + $this->assertEquals( |
|
881 | + [ |
|
882 | + TEST_FILES_PATH . 'NamespaceCoveredFunction.php' => \range(4, 7) |
|
883 | + ], |
|
884 | + Test::getLinesToBeCovered( |
|
885 | + \CoverageNamespacedFunctionTest::class, |
|
886 | + 'testFunc' |
|
887 | + ) |
|
888 | + ); |
|
889 | + } |
|
890 | + |
|
891 | + public function getLinesToBeCoveredProvider() |
|
892 | + { |
|
893 | + return [ |
|
894 | + [ |
|
895 | + 'CoverageNoneTest', |
|
896 | + [] |
|
897 | + ], |
|
898 | + [ |
|
899 | + 'CoverageClassExtendedTest', |
|
900 | + \array_merge(\range(19, 36), \range(2, 17)) |
|
901 | + ], |
|
902 | + [ |
|
903 | + 'CoverageClassTest', |
|
904 | + \range(19, 36) |
|
905 | + ], |
|
906 | + [ |
|
907 | + 'CoverageMethodTest', |
|
908 | + \range(31, 35) |
|
909 | + ], |
|
910 | + [ |
|
911 | + 'CoverageMethodOneLineAnnotationTest', |
|
912 | + \range(31, 35) |
|
913 | + ], |
|
914 | + [ |
|
915 | + 'CoverageNotPrivateTest', |
|
916 | + \array_merge(\range(25, 29), \range(31, 35)) |
|
917 | + ], |
|
918 | + [ |
|
919 | + 'CoverageNotProtectedTest', |
|
920 | + \array_merge(\range(21, 23), \range(31, 35)) |
|
921 | + ], |
|
922 | + [ |
|
923 | + 'CoverageNotPublicTest', |
|
924 | + \array_merge(\range(21, 23), \range(25, 29)) |
|
925 | + ], |
|
926 | + [ |
|
927 | + 'CoveragePrivateTest', |
|
928 | + \range(21, 23) |
|
929 | + ], |
|
930 | + [ |
|
931 | + 'CoverageProtectedTest', |
|
932 | + \range(25, 29) |
|
933 | + ], |
|
934 | + [ |
|
935 | + 'CoveragePublicTest', |
|
936 | + \range(31, 35) |
|
937 | + ], |
|
938 | + [ |
|
939 | + 'CoverageFunctionTest', |
|
940 | + \range(2, 4) |
|
941 | + ], |
|
942 | + [ |
|
943 | + 'NamespaceCoverageClassExtendedTest', |
|
944 | + \array_merge(\range(21, 38), \range(4, 19)) |
|
945 | + ], |
|
946 | + [ |
|
947 | + 'NamespaceCoverageClassTest', |
|
948 | + \range(21, 38) |
|
949 | + ], |
|
950 | + [ |
|
951 | + 'NamespaceCoverageMethodTest', |
|
952 | + \range(33, 37) |
|
953 | + ], |
|
954 | + [ |
|
955 | + 'NamespaceCoverageNotPrivateTest', |
|
956 | + \array_merge(\range(27, 31), \range(33, 37)) |
|
957 | + ], |
|
958 | + [ |
|
959 | + 'NamespaceCoverageNotProtectedTest', |
|
960 | + \array_merge(\range(23, 25), \range(33, 37)) |
|
961 | + ], |
|
962 | + [ |
|
963 | + 'NamespaceCoverageNotPublicTest', |
|
964 | + \array_merge(\range(23, 25), \range(27, 31)) |
|
965 | + ], |
|
966 | + [ |
|
967 | + 'NamespaceCoveragePrivateTest', |
|
968 | + \range(23, 25) |
|
969 | + ], |
|
970 | + [ |
|
971 | + 'NamespaceCoverageProtectedTest', |
|
972 | + \range(27, 31) |
|
973 | + ], |
|
974 | + [ |
|
975 | + 'NamespaceCoveragePublicTest', |
|
976 | + \range(33, 37) |
|
977 | + ], |
|
978 | + [ |
|
979 | + 'NamespaceCoverageCoversClassTest', |
|
980 | + \array_merge(\range(23, 25), \range(27, 31), \range(33, 37), \range(6, 8), \range(10, 13), \range(15, 18)) |
|
981 | + ], |
|
982 | + [ |
|
983 | + 'NamespaceCoverageCoversClassPublicTest', |
|
984 | + \range(33, 37) |
|
985 | + ], |
|
986 | + [ |
|
987 | + 'CoverageNothingTest', |
|
988 | + false |
|
989 | + ] |
|
990 | + ]; |
|
991 | + } |
|
992 | + |
|
993 | + public function testParseTestMethodAnnotationsIncorporatesTraits() |
|
994 | + { |
|
995 | + $result = Test::parseTestMethodAnnotations(\ParseTestMethodAnnotationsMock::class); |
|
996 | + |
|
997 | + $this->assertArrayHasKey('class', $result); |
|
998 | + $this->assertArrayHasKey('method', $result); |
|
999 | + $this->assertArrayHasKey('theClassAnnotation', $result['class']); |
|
1000 | + $this->assertArrayHasKey('theTraitAnnotation', $result['class']); |
|
1001 | + } |
|
1002 | 1002 | } |
@@ -122,19 +122,19 @@ discard block |
||
122 | 122 | public function requirementsProvider() |
123 | 123 | { |
124 | 124 | return [ |
125 | - ['testOne', []], |
|
126 | - ['testTwo', ['PHPUnit' => ['version' => '1.0', 'operator' => '']]], |
|
127 | - ['testThree', ['PHP' => ['version' => '2.0', 'operator' => '']]], |
|
128 | - ['testFour', [ |
|
125 | + ['testOne', []], |
|
126 | + ['testTwo', ['PHPUnit' => ['version' => '1.0', 'operator' => '']]], |
|
127 | + ['testThree', ['PHP' => ['version' => '2.0', 'operator' => '']]], |
|
128 | + ['testFour', [ |
|
129 | 129 | 'PHPUnit' => ['version' => '2.0', 'operator' => ''], |
130 | 130 | 'PHP' => ['version' => '1.0', 'operator' => ''], |
131 | 131 | ]], |
132 | - ['testFive', ['PHP' => ['version' => '5.4.0RC6', 'operator' => '']]], |
|
133 | - ['testSix', ['PHP' => ['version' => '5.4.0-alpha1', 'operator' => '']]], |
|
134 | - ['testSeven', ['PHP' => ['version' => '5.4.0beta2', 'operator' => '']]], |
|
135 | - ['testEight', ['PHP' => ['version' => '5.4-dev', 'operator' => '']]], |
|
136 | - ['testNine', ['functions' => ['testFunc']]], |
|
137 | - ['testTen', ['extensions' => ['testExt']]], |
|
132 | + ['testFive', ['PHP' => ['version' => '5.4.0RC6', 'operator' => '']]], |
|
133 | + ['testSix', ['PHP' => ['version' => '5.4.0-alpha1', 'operator' => '']]], |
|
134 | + ['testSeven', ['PHP' => ['version' => '5.4.0beta2', 'operator' => '']]], |
|
135 | + ['testEight', ['PHP' => ['version' => '5.4-dev', 'operator' => '']]], |
|
136 | + ['testNine', ['functions' => ['testFunc']]], |
|
137 | + ['testTen', ['extensions' => ['testExt']]], |
|
138 | 138 | ['testEleven', [ |
139 | 139 | 'OS' => 'SunOS', |
140 | 140 | 'OSFAMILY' => 'Solaris', |
@@ -497,12 +497,12 @@ discard block |
||
497 | 497 | public function missingRequirementsProvider() |
498 | 498 | { |
499 | 499 | return [ |
500 | - ['testOne', []], |
|
501 | - ['testNine', ['Function testFunc is required.']], |
|
502 | - ['testTen', ['Extension testExt is required.']], |
|
503 | - ['testAlwaysSkip', ['PHPUnit >= 1111111 is required.']], |
|
504 | - ['testAlwaysSkip2', ['PHP >= 9999999 is required.']], |
|
505 | - ['testAlwaysSkip3', ['Operating system matching /DOESNOTEXIST/i is required.']], |
|
500 | + ['testOne', []], |
|
501 | + ['testNine', ['Function testFunc is required.']], |
|
502 | + ['testTen', ['Extension testExt is required.']], |
|
503 | + ['testAlwaysSkip', ['PHPUnit >= 1111111 is required.']], |
|
504 | + ['testAlwaysSkip2', ['PHP >= 9999999 is required.']], |
|
505 | + ['testAlwaysSkip3', ['Operating system matching /DOESNOTEXIST/i is required.']], |
|
506 | 506 | ['testAllPossibleRequirements', [ |
507 | 507 | 'PHP >= 99-dev is required.', |
508 | 508 | 'PHPUnit >= 9-dev is required.', |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | { |
758 | 758 | if (\strpos($test, 'Namespace') === 0) { |
759 | 759 | $expected = [ |
760 | - TEST_FILES_PATH . 'NamespaceCoveredClass.php' => $lines |
|
760 | + TEST_FILES_PATH.'NamespaceCoveredClass.php' => $lines |
|
761 | 761 | ]; |
762 | 762 | } elseif ($test === 'CoverageNoneTest') { |
763 | 763 | $expected = []; |
@@ -765,10 +765,10 @@ discard block |
||
765 | 765 | $expected = false; |
766 | 766 | } elseif ($test === 'CoverageFunctionTest') { |
767 | 767 | $expected = [ |
768 | - TEST_FILES_PATH . 'CoveredFunction.php' => $lines |
|
768 | + TEST_FILES_PATH.'CoveredFunction.php' => $lines |
|
769 | 769 | ]; |
770 | 770 | } else { |
771 | - $expected = [TEST_FILES_PATH . 'CoveredClass.php' => $lines]; |
|
771 | + $expected = [TEST_FILES_PATH.'CoveredClass.php' => $lines]; |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | $this->assertEquals( |
@@ -834,7 +834,7 @@ discard block |
||
834 | 834 | public function testFunctionParenthesesAreAllowed() |
835 | 835 | { |
836 | 836 | $this->assertSame( |
837 | - [TEST_FILES_PATH . 'CoveredFunction.php' => \range(2, 4)], |
|
837 | + [TEST_FILES_PATH.'CoveredFunction.php' => \range(2, 4)], |
|
838 | 838 | Test::getLinesToBeCovered( |
839 | 839 | 'CoverageFunctionParenthesesTest', |
840 | 840 | 'testSomething' |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | public function testFunctionParenthesesAreAllowedWithWhitespace() |
846 | 846 | { |
847 | 847 | $this->assertSame( |
848 | - [TEST_FILES_PATH . 'CoveredFunction.php' => \range(2, 4)], |
|
848 | + [TEST_FILES_PATH.'CoveredFunction.php' => \range(2, 4)], |
|
849 | 849 | Test::getLinesToBeCovered( |
850 | 850 | 'CoverageFunctionParenthesesWhitespaceTest', |
851 | 851 | 'testSomething' |
@@ -856,7 +856,7 @@ discard block |
||
856 | 856 | public function testMethodParenthesesAreAllowed() |
857 | 857 | { |
858 | 858 | $this->assertSame( |
859 | - [TEST_FILES_PATH . 'CoveredClass.php' => \range(31, 35)], |
|
859 | + [TEST_FILES_PATH.'CoveredClass.php' => \range(31, 35)], |
|
860 | 860 | Test::getLinesToBeCovered( |
861 | 861 | 'CoverageMethodParenthesesTest', |
862 | 862 | 'testSomething' |
@@ -867,7 +867,7 @@ discard block |
||
867 | 867 | public function testMethodParenthesesAreAllowedWithWhitespace() |
868 | 868 | { |
869 | 869 | $this->assertSame( |
870 | - [TEST_FILES_PATH . 'CoveredClass.php' => \range(31, 35)], |
|
870 | + [TEST_FILES_PATH.'CoveredClass.php' => \range(31, 35)], |
|
871 | 871 | Test::getLinesToBeCovered( |
872 | 872 | 'CoverageMethodParenthesesWhitespaceTest', |
873 | 873 | 'testSomething' |
@@ -879,7 +879,7 @@ discard block |
||
879 | 879 | { |
880 | 880 | $this->assertEquals( |
881 | 881 | [ |
882 | - TEST_FILES_PATH . 'NamespaceCoveredFunction.php' => \range(4, 7) |
|
882 | + TEST_FILES_PATH.'NamespaceCoveredFunction.php' => \range(4, 7) |
|
883 | 883 | ], |
884 | 884 | Test::getLinesToBeCovered( |
885 | 885 | \CoverageNamespacedFunctionTest::class, |
@@ -15,103 +15,103 @@ |
||
15 | 15 | |
16 | 16 | class XmlTest extends TestCase |
17 | 17 | { |
18 | - /** |
|
19 | - * @dataProvider charProvider |
|
20 | - */ |
|
21 | - public function testPrepareString($char) |
|
22 | - { |
|
23 | - $e = null; |
|
24 | - |
|
25 | - $escapedString = Xml::prepareString($char); |
|
26 | - $xml = "<?xml version='1.0' encoding='UTF-8' ?><tag>$escapedString</tag>"; |
|
27 | - $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
28 | - |
|
29 | - try { |
|
30 | - $dom->loadXML($xml); |
|
31 | - } catch (Exception $e) { |
|
32 | - } |
|
33 | - |
|
34 | - $this->assertNull($e, \sprintf( |
|
35 | - 'PHPUnit_Util_XML::prepareString("\x%02x") should not crash DomDocument', |
|
36 | - \ord($char) |
|
37 | - )); |
|
38 | - } |
|
39 | - |
|
40 | - public function charProvider() |
|
41 | - { |
|
42 | - $data = []; |
|
43 | - |
|
44 | - for ($i = 0; $i < 256; $i++) { |
|
45 | - $data[] = [\chr($i)]; |
|
46 | - } |
|
47 | - |
|
48 | - return $data; |
|
49 | - } |
|
50 | - |
|
51 | - public function testLoadEmptyString() |
|
52 | - { |
|
53 | - $this->expectException(Exception::class); |
|
54 | - $this->expectExceptionMessage('Could not load XML from empty string'); |
|
55 | - |
|
56 | - Xml::load(''); |
|
57 | - } |
|
58 | - |
|
59 | - public function testLoadArray() |
|
60 | - { |
|
61 | - $this->expectException(Exception::class); |
|
62 | - $this->expectExceptionMessage('Could not load XML from array'); |
|
63 | - |
|
64 | - Xml::load([1, 2, 3]); |
|
65 | - } |
|
66 | - |
|
67 | - public function testLoadBoolean() |
|
68 | - { |
|
69 | - $this->expectException(Exception::class); |
|
70 | - $this->expectExceptionMessage('Could not load XML from boolean'); |
|
71 | - |
|
72 | - Xml::load(false); |
|
73 | - } |
|
74 | - |
|
75 | - public function testNestedXmlToVariable() |
|
76 | - { |
|
77 | - $xml = '<array><element key="a"><array><element key="b"><string>foo</string></element></array></element><element key="c"><string>bar</string></element></array>'; |
|
78 | - $dom = new \DOMDocument; |
|
79 | - $dom->loadXML($xml); |
|
80 | - |
|
81 | - $expected = [ |
|
82 | - 'a' => [ |
|
83 | - 'b' => 'foo', |
|
84 | - ], |
|
85 | - 'c' => 'bar', |
|
86 | - ]; |
|
87 | - |
|
88 | - $actual = Xml::xmlToVariable($dom->documentElement); |
|
89 | - |
|
90 | - $this->assertSame($expected, $actual); |
|
91 | - } |
|
92 | - |
|
93 | - public function testXmlToVariableCanHandleMultipleOfTheSameArgumentType() |
|
94 | - { |
|
95 | - $xml = '<object class="SampleClass"><arguments><string>a</string><string>b</string><string>c</string></arguments></object>'; |
|
96 | - $dom = new \DOMDocument(); |
|
97 | - $dom->loadXML($xml); |
|
98 | - |
|
99 | - $expected = ['a' => 'a', 'b' => 'b', 'c' => 'c']; |
|
100 | - |
|
101 | - $actual = Xml::xmlToVariable($dom->documentElement); |
|
102 | - |
|
103 | - $this->assertSame($expected, (array) $actual); |
|
104 | - } |
|
105 | - |
|
106 | - public function testXmlToVariableCanConstructObjectsWithConstructorArgumentsRecursively() |
|
107 | - { |
|
108 | - $xml = '<object class="Exception"><arguments><string>one</string><integer>0</integer><object class="Exception"><arguments><string>two</string></arguments></object></arguments></object>'; |
|
109 | - $dom = new \DOMDocument(); |
|
110 | - $dom->loadXML($xml); |
|
111 | - |
|
112 | - $actual = Xml::xmlToVariable($dom->documentElement); |
|
113 | - |
|
114 | - $this->assertEquals('one', $actual->getMessage()); |
|
115 | - $this->assertEquals('two', $actual->getPrevious()->getMessage()); |
|
116 | - } |
|
18 | + /** |
|
19 | + * @dataProvider charProvider |
|
20 | + */ |
|
21 | + public function testPrepareString($char) |
|
22 | + { |
|
23 | + $e = null; |
|
24 | + |
|
25 | + $escapedString = Xml::prepareString($char); |
|
26 | + $xml = "<?xml version='1.0' encoding='UTF-8' ?><tag>$escapedString</tag>"; |
|
27 | + $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
28 | + |
|
29 | + try { |
|
30 | + $dom->loadXML($xml); |
|
31 | + } catch (Exception $e) { |
|
32 | + } |
|
33 | + |
|
34 | + $this->assertNull($e, \sprintf( |
|
35 | + 'PHPUnit_Util_XML::prepareString("\x%02x") should not crash DomDocument', |
|
36 | + \ord($char) |
|
37 | + )); |
|
38 | + } |
|
39 | + |
|
40 | + public function charProvider() |
|
41 | + { |
|
42 | + $data = []; |
|
43 | + |
|
44 | + for ($i = 0; $i < 256; $i++) { |
|
45 | + $data[] = [\chr($i)]; |
|
46 | + } |
|
47 | + |
|
48 | + return $data; |
|
49 | + } |
|
50 | + |
|
51 | + public function testLoadEmptyString() |
|
52 | + { |
|
53 | + $this->expectException(Exception::class); |
|
54 | + $this->expectExceptionMessage('Could not load XML from empty string'); |
|
55 | + |
|
56 | + Xml::load(''); |
|
57 | + } |
|
58 | + |
|
59 | + public function testLoadArray() |
|
60 | + { |
|
61 | + $this->expectException(Exception::class); |
|
62 | + $this->expectExceptionMessage('Could not load XML from array'); |
|
63 | + |
|
64 | + Xml::load([1, 2, 3]); |
|
65 | + } |
|
66 | + |
|
67 | + public function testLoadBoolean() |
|
68 | + { |
|
69 | + $this->expectException(Exception::class); |
|
70 | + $this->expectExceptionMessage('Could not load XML from boolean'); |
|
71 | + |
|
72 | + Xml::load(false); |
|
73 | + } |
|
74 | + |
|
75 | + public function testNestedXmlToVariable() |
|
76 | + { |
|
77 | + $xml = '<array><element key="a"><array><element key="b"><string>foo</string></element></array></element><element key="c"><string>bar</string></element></array>'; |
|
78 | + $dom = new \DOMDocument; |
|
79 | + $dom->loadXML($xml); |
|
80 | + |
|
81 | + $expected = [ |
|
82 | + 'a' => [ |
|
83 | + 'b' => 'foo', |
|
84 | + ], |
|
85 | + 'c' => 'bar', |
|
86 | + ]; |
|
87 | + |
|
88 | + $actual = Xml::xmlToVariable($dom->documentElement); |
|
89 | + |
|
90 | + $this->assertSame($expected, $actual); |
|
91 | + } |
|
92 | + |
|
93 | + public function testXmlToVariableCanHandleMultipleOfTheSameArgumentType() |
|
94 | + { |
|
95 | + $xml = '<object class="SampleClass"><arguments><string>a</string><string>b</string><string>c</string></arguments></object>'; |
|
96 | + $dom = new \DOMDocument(); |
|
97 | + $dom->loadXML($xml); |
|
98 | + |
|
99 | + $expected = ['a' => 'a', 'b' => 'b', 'c' => 'c']; |
|
100 | + |
|
101 | + $actual = Xml::xmlToVariable($dom->documentElement); |
|
102 | + |
|
103 | + $this->assertSame($expected, (array) $actual); |
|
104 | + } |
|
105 | + |
|
106 | + public function testXmlToVariableCanConstructObjectsWithConstructorArgumentsRecursively() |
|
107 | + { |
|
108 | + $xml = '<object class="Exception"><arguments><string>one</string><integer>0</integer><object class="Exception"><arguments><string>two</string></arguments></object></arguments></object>'; |
|
109 | + $dom = new \DOMDocument(); |
|
110 | + $dom->loadXML($xml); |
|
111 | + |
|
112 | + $actual = Xml::xmlToVariable($dom->documentElement); |
|
113 | + |
|
114 | + $this->assertEquals('one', $actual->getMessage()); |
|
115 | + $this->assertEquals('two', $actual->getPrevious()->getMessage()); |
|
116 | + } |
|
117 | 117 | } |
@@ -15,110 +15,110 @@ |
||
15 | 15 | |
16 | 16 | class AbstractPhpProcessTest extends TestCase |
17 | 17 | { |
18 | - /** |
|
19 | - * @var AbstractPhpProcess|\PHPUnit_Framework_MockObject_MockObject |
|
20 | - */ |
|
21 | - private $phpProcess; |
|
18 | + /** |
|
19 | + * @var AbstractPhpProcess|\PHPUnit_Framework_MockObject_MockObject |
|
20 | + */ |
|
21 | + private $phpProcess; |
|
22 | 22 | |
23 | - protected function setUp() |
|
24 | - { |
|
25 | - $this->phpProcess = $this->getMockForAbstractClass(AbstractPhpProcess::class); |
|
26 | - } |
|
23 | + protected function setUp() |
|
24 | + { |
|
25 | + $this->phpProcess = $this->getMockForAbstractClass(AbstractPhpProcess::class); |
|
26 | + } |
|
27 | 27 | |
28 | - public function testShouldNotUseStderrRedirectionByDefault() |
|
29 | - { |
|
30 | - $this->assertFalse($this->phpProcess->useStderrRedirection()); |
|
31 | - } |
|
28 | + public function testShouldNotUseStderrRedirectionByDefault() |
|
29 | + { |
|
30 | + $this->assertFalse($this->phpProcess->useStderrRedirection()); |
|
31 | + } |
|
32 | 32 | |
33 | - public function testShouldDefinedIfUseStderrRedirection() |
|
34 | - { |
|
35 | - $this->phpProcess->setUseStderrRedirection(true); |
|
33 | + public function testShouldDefinedIfUseStderrRedirection() |
|
34 | + { |
|
35 | + $this->phpProcess->setUseStderrRedirection(true); |
|
36 | 36 | |
37 | - $this->assertTrue($this->phpProcess->useStderrRedirection()); |
|
38 | - } |
|
37 | + $this->assertTrue($this->phpProcess->useStderrRedirection()); |
|
38 | + } |
|
39 | 39 | |
40 | - public function testShouldDefinedIfDoNotUseStderrRedirection() |
|
41 | - { |
|
42 | - $this->phpProcess->setUseStderrRedirection(false); |
|
40 | + public function testShouldDefinedIfDoNotUseStderrRedirection() |
|
41 | + { |
|
42 | + $this->phpProcess->setUseStderrRedirection(false); |
|
43 | 43 | |
44 | - $this->assertFalse($this->phpProcess->useStderrRedirection()); |
|
45 | - } |
|
44 | + $this->assertFalse($this->phpProcess->useStderrRedirection()); |
|
45 | + } |
|
46 | 46 | |
47 | - public function testShouldThrowsExceptionWhenStderrRedirectionVariableIsNotABoolean() |
|
48 | - { |
|
49 | - $this->expectException(Exception::class); |
|
47 | + public function testShouldThrowsExceptionWhenStderrRedirectionVariableIsNotABoolean() |
|
48 | + { |
|
49 | + $this->expectException(Exception::class); |
|
50 | 50 | |
51 | - $this->phpProcess->setUseStderrRedirection(null); |
|
52 | - } |
|
51 | + $this->phpProcess->setUseStderrRedirection(null); |
|
52 | + } |
|
53 | 53 | |
54 | - public function testShouldUseGivenSettingsToCreateCommand() |
|
55 | - { |
|
56 | - $settings = [ |
|
57 | - 'allow_url_fopen=1', |
|
58 | - 'auto_append_file=', |
|
59 | - 'display_errors=1', |
|
60 | - ]; |
|
54 | + public function testShouldUseGivenSettingsToCreateCommand() |
|
55 | + { |
|
56 | + $settings = [ |
|
57 | + 'allow_url_fopen=1', |
|
58 | + 'auto_append_file=', |
|
59 | + 'display_errors=1', |
|
60 | + ]; |
|
61 | 61 | |
62 | - $expectedCommandFormat = '%s -d allow_url_fopen=1 -d auto_append_file= -d display_errors=1'; |
|
63 | - $actualCommand = $this->phpProcess->getCommand($settings); |
|
62 | + $expectedCommandFormat = '%s -d allow_url_fopen=1 -d auto_append_file= -d display_errors=1'; |
|
63 | + $actualCommand = $this->phpProcess->getCommand($settings); |
|
64 | 64 | |
65 | - $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand); |
|
66 | - } |
|
65 | + $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand); |
|
66 | + } |
|
67 | 67 | |
68 | - public function testShouldRedirectStderrToStdoutWhenDefined() |
|
69 | - { |
|
70 | - $this->phpProcess->setUseStderrRedirection(true); |
|
68 | + public function testShouldRedirectStderrToStdoutWhenDefined() |
|
69 | + { |
|
70 | + $this->phpProcess->setUseStderrRedirection(true); |
|
71 | 71 | |
72 | - $expectedCommandFormat = '%s 2>&1'; |
|
73 | - $actualCommand = $this->phpProcess->getCommand([]); |
|
72 | + $expectedCommandFormat = '%s 2>&1'; |
|
73 | + $actualCommand = $this->phpProcess->getCommand([]); |
|
74 | 74 | |
75 | - $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand); |
|
76 | - } |
|
75 | + $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand); |
|
76 | + } |
|
77 | 77 | |
78 | - public function testShouldUseArgsToCreateCommand() |
|
79 | - { |
|
80 | - $this->phpProcess->setArgs('foo=bar'); |
|
78 | + public function testShouldUseArgsToCreateCommand() |
|
79 | + { |
|
80 | + $this->phpProcess->setArgs('foo=bar'); |
|
81 | 81 | |
82 | - $expectedCommandFormat = '%s -- foo=bar'; |
|
83 | - $actualCommand = $this->phpProcess->getCommand([]); |
|
82 | + $expectedCommandFormat = '%s -- foo=bar'; |
|
83 | + $actualCommand = $this->phpProcess->getCommand([]); |
|
84 | 84 | |
85 | - $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand); |
|
86 | - } |
|
85 | + $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand); |
|
86 | + } |
|
87 | 87 | |
88 | - public function testShouldHaveFileToCreateCommand() |
|
89 | - { |
|
90 | - $argumentEscapingCharacter = DIRECTORY_SEPARATOR === '\\' ? '"' : '\''; |
|
91 | - $expectedCommandFormat = \sprintf('%%s -%%c %1$sfile.php%1$s', $argumentEscapingCharacter); |
|
92 | - $actualCommand = $this->phpProcess->getCommand([], 'file.php'); |
|
88 | + public function testShouldHaveFileToCreateCommand() |
|
89 | + { |
|
90 | + $argumentEscapingCharacter = DIRECTORY_SEPARATOR === '\\' ? '"' : '\''; |
|
91 | + $expectedCommandFormat = \sprintf('%%s -%%c %1$sfile.php%1$s', $argumentEscapingCharacter); |
|
92 | + $actualCommand = $this->phpProcess->getCommand([], 'file.php'); |
|
93 | 93 | |
94 | - $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand); |
|
95 | - } |
|
94 | + $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand); |
|
95 | + } |
|
96 | 96 | |
97 | - public function testStdinGetterAndSetter() |
|
98 | - { |
|
99 | - $this->phpProcess->setStdin('foo'); |
|
97 | + public function testStdinGetterAndSetter() |
|
98 | + { |
|
99 | + $this->phpProcess->setStdin('foo'); |
|
100 | 100 | |
101 | - $this->assertEquals('foo', $this->phpProcess->getStdin()); |
|
102 | - } |
|
101 | + $this->assertEquals('foo', $this->phpProcess->getStdin()); |
|
102 | + } |
|
103 | 103 | |
104 | - public function testArgsGetterAndSetter() |
|
105 | - { |
|
106 | - $this->phpProcess->setArgs('foo=bar'); |
|
104 | + public function testArgsGetterAndSetter() |
|
105 | + { |
|
106 | + $this->phpProcess->setArgs('foo=bar'); |
|
107 | 107 | |
108 | - $this->assertEquals('foo=bar', $this->phpProcess->getArgs()); |
|
109 | - } |
|
108 | + $this->assertEquals('foo=bar', $this->phpProcess->getArgs()); |
|
109 | + } |
|
110 | 110 | |
111 | - public function testEnvGetterAndSetter() |
|
112 | - { |
|
113 | - $this->phpProcess->setEnv(['foo' => 'bar']); |
|
111 | + public function testEnvGetterAndSetter() |
|
112 | + { |
|
113 | + $this->phpProcess->setEnv(['foo' => 'bar']); |
|
114 | 114 | |
115 | - $this->assertEquals(['foo' => 'bar'], $this->phpProcess->getEnv()); |
|
116 | - } |
|
115 | + $this->assertEquals(['foo' => 'bar'], $this->phpProcess->getEnv()); |
|
116 | + } |
|
117 | 117 | |
118 | - public function testTimeoutGetterAndSetter() |
|
119 | - { |
|
120 | - $this->phpProcess->setTimeout(30); |
|
118 | + public function testTimeoutGetterAndSetter() |
|
119 | + { |
|
120 | + $this->phpProcess->setTimeout(30); |
|
121 | 121 | |
122 | - $this->assertEquals(30, $this->phpProcess->getTimeout()); |
|
123 | - } |
|
122 | + $this->assertEquals(30, $this->phpProcess->getTimeout()); |
|
123 | + } |
|
124 | 124 | } |