File tree 3 files changed +23
-0
lines changed
tests/Type/WebMozartAssert/data
3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ This extension specifies types of values passed to:
34
34
* ` Assert::stringNotEmpty `
35
35
* ` Assert::float `
36
36
* ` Assert::numeric `
37
+ * ` Assert::natural `
37
38
* ` Assert::integerish `
38
39
* ` Assert::boolean `
39
40
* ` Assert::scalar `
Original file line number Diff line number Diff line change @@ -225,6 +225,18 @@ private static function getExpressionResolvers(): array
225
225
[$ value ]
226
226
);
227
227
},
228
+ 'natural ' => function (Scope $ scope , Arg $ value ): \PhpParser \Node \Expr {
229
+ return new \PhpParser \Node \Expr \BinaryOp \BooleanAnd (
230
+ new \PhpParser \Node \Expr \FuncCall (
231
+ new \PhpParser \Node \Name ('is_int ' ),
232
+ [$ value ]
233
+ ),
234
+ new \PhpParser \Node \Expr \BinaryOp \GreaterOrEqual (
235
+ $ value ->value ,
236
+ new \PhpParser \Node \Scalar \LNumber (0 )
237
+ )
238
+ );
239
+ },
228
240
'boolean ' => function (Scope $ scope , Arg $ value ): \PhpParser \Node \Expr {
229
241
return new \PhpParser \Node \Expr \FuncCall (
230
242
new \PhpParser \Node \Name ('is_bool ' ),
Original file line number Diff line number Diff line change @@ -18,4 +18,14 @@ public function positiveInteger($a): void
18
18
Assert::positiveInteger ($ b );
19
19
\PHPStan \Testing \assertType ('*NEVER* ' , $ b );
20
20
}
21
+
22
+ public function natural ($ a ): void
23
+ {
24
+ Assert::natural ($ a );
25
+ \PHPStan \Testing \assertType ('int<0, max> ' , $ a );
26
+
27
+ $ b = -1 ;
28
+ Assert::natural ($ b );
29
+ \PHPStan \Testing \assertType ('*NEVER* ' , $ b );
30
+ }
21
31
}
You can’t perform that action at this time.
0 commit comments