-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more mixed-type bool subtraction tests
- Loading branch information
1 parent
975486e
commit a72f752
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php // lint >= 8.0 | ||
|
||
namespace SubtractMixed; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
/** | ||
* @param int|0.0|''|'0'|array{}|false|null $moreThenFalsy | ||
*/ | ||
function subtract(mixed $m, $moreThenFalsy) { | ||
if ($m !== true) { | ||
assertType("mixed~true", $m); | ||
assertType('bool', (bool) $m); // mixed could still contain something truthy | ||
} | ||
if ($m !== false) { | ||
assertType("mixed~false", $m); | ||
assertType('bool', (bool) $m); // mixed could still contain something falsy | ||
} | ||
if (!is_bool($m)) { | ||
assertType('mixed~bool', $m); | ||
assertType('bool', (bool) $m); | ||
} | ||
if (!is_array($m)) { | ||
assertType('mixed~array', $m); | ||
assertType('bool', (bool) $m); | ||
} | ||
|
||
if ($m) { | ||
assertType("mixed~(0|0.0|''|'0'|array{}|false|null)", $m); | ||
assertType('true', (bool) $m); | ||
} | ||
if (!$m) { | ||
assertType("0|0.0|''|'0'|array{}|false|null", $m); | ||
assertType('false', (bool) $m); | ||
} | ||
if (!$m) { | ||
if (!is_int($m)) { | ||
assertType("0.0|''|'0'|array{}|false|null", $m); | ||
assertType('false', (bool)$m); | ||
} | ||
if (!is_bool($m)) { | ||
assertType("0|0.0|''|'0'|array{}|null", $m); | ||
assertType('false', (bool)$m); | ||
} | ||
} | ||
|
||
if (!$m || is_int($m)) { | ||
assertType("0.0|''|'0'|array{}|int|false|null", $m); | ||
assertType('bool', (bool) $m); | ||
} | ||
|
||
if ($m !== $moreThenFalsy) { | ||
assertType('mixed', $m); | ||
assertType('bool', (bool) $m); // could be true | ||
} | ||
} |