4
4
5
5
use PHPStan \Rules \Rule ;
6
6
use PHPStan \Testing \RuleTestCase ;
7
+ use PHPStan \Type \Php \RegexExpressionHelper ;
7
8
use function sprintf ;
8
9
use const PHP_VERSION_ID ;
9
10
@@ -15,7 +16,9 @@ class RegularExpressionPatternRuleTest extends RuleTestCase
15
16
16
17
protected function getRule (): Rule
17
18
{
18
- return new RegularExpressionPatternRule ();
19
+ return new RegularExpressionPatternRule (
20
+ self ::getContainer ()->getByType (RegexExpressionHelper::class),
21
+ );
19
22
}
20
23
21
24
public function testValidRegexPatternBefore73 (): void
@@ -115,6 +118,30 @@ public function testValidRegexPatternBefore73(): void
115
118
'Regex pattern is invalid: Compilation failed: missing ) at offset 1 in pattern: ~(~ ' ,
116
119
43 ,
117
120
],
121
+ [
122
+ 'Regex pattern is invalid: Delimiter must not be alphanumeric, backslash, or NUL in pattern: nok ' ,
123
+ 57 ,
124
+ ],
125
+ [
126
+ 'Regex pattern is invalid: Delimiter must not be alphanumeric, backslash, or NUL in pattern: nok ' ,
127
+ 58 ,
128
+ ],
129
+ [
130
+ 'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1 in pattern: ~(~ ' ,
131
+ 59 ,
132
+ ],
133
+ [
134
+ 'Regex pattern is invalid: Delimiter must not be alphanumeric, backslash, or NUL in pattern: noknono ' ,
135
+ 61 ,
136
+ ],
137
+ [
138
+ 'Regex pattern is invalid: Delimiter must not be alphanumeric, backslash, or NUL in pattern: noknope ' ,
139
+ 62 ,
140
+ ],
141
+ [
142
+ 'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1 in pattern: ~(~ ' ,
143
+ 63 ,
144
+ ],
118
145
],
119
146
);
120
147
}
@@ -221,6 +248,30 @@ public function testValidRegexPatternAfter73(): void
221
248
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1 in pattern: ~(~ ' ,
222
249
43 ,
223
250
],
251
+ [
252
+ sprintf ('Regex pattern is invalid: Delimiter must not be %s in pattern: nok ' , $ messagePart ),
253
+ 57 ,
254
+ ],
255
+ [
256
+ sprintf ('Regex pattern is invalid: Delimiter must not be %s in pattern: nok ' , $ messagePart ),
257
+ 58 ,
258
+ ],
259
+ [
260
+ 'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1 in pattern: ~(~ ' ,
261
+ 59 ,
262
+ ],
263
+ [
264
+ sprintf ('Regex pattern is invalid: Delimiter must not be %s in pattern: noknono ' , $ messagePart ),
265
+ 61 ,
266
+ ],
267
+ [
268
+ sprintf ('Regex pattern is invalid: Delimiter must not be %s in pattern: noknope ' , $ messagePart ),
269
+ 62 ,
270
+ ],
271
+ [
272
+ 'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1 in pattern: ~(~ ' ,
273
+ 63 ,
274
+ ],
224
275
],
225
276
);
226
277
}
0 commit comments