Skip to content

Commit a72f752

Browse files
staabmondrejmirtes
authored andcommitted
Add more mixed-type bool subtraction tests
1 parent 975486e commit a72f752

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php // lint >= 8.0
2+
3+
namespace SubtractMixed;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param int|0.0|''|'0'|array{}|false|null $moreThenFalsy
9+
*/
10+
function subtract(mixed $m, $moreThenFalsy) {
11+
if ($m !== true) {
12+
assertType("mixed~true", $m);
13+
assertType('bool', (bool) $m); // mixed could still contain something truthy
14+
}
15+
if ($m !== false) {
16+
assertType("mixed~false", $m);
17+
assertType('bool', (bool) $m); // mixed could still contain something falsy
18+
}
19+
if (!is_bool($m)) {
20+
assertType('mixed~bool', $m);
21+
assertType('bool', (bool) $m);
22+
}
23+
if (!is_array($m)) {
24+
assertType('mixed~array', $m);
25+
assertType('bool', (bool) $m);
26+
}
27+
28+
if ($m) {
29+
assertType("mixed~(0|0.0|''|'0'|array{}|false|null)", $m);
30+
assertType('true', (bool) $m);
31+
}
32+
if (!$m) {
33+
assertType("0|0.0|''|'0'|array{}|false|null", $m);
34+
assertType('false', (bool) $m);
35+
}
36+
if (!$m) {
37+
if (!is_int($m)) {
38+
assertType("0.0|''|'0'|array{}|false|null", $m);
39+
assertType('false', (bool)$m);
40+
}
41+
if (!is_bool($m)) {
42+
assertType("0|0.0|''|'0'|array{}|null", $m);
43+
assertType('false', (bool)$m);
44+
}
45+
}
46+
47+
if (!$m || is_int($m)) {
48+
assertType("0.0|''|'0'|array{}|int|false|null", $m);
49+
assertType('bool', (bool) $m);
50+
}
51+
52+
if ($m !== $moreThenFalsy) {
53+
assertType('mixed', $m);
54+
assertType('bool', (bool) $m); // could be true
55+
}
56+
}

0 commit comments

Comments
 (0)