You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PHPUnit generates invalid mock code when the type false is used in a union e.g. false|int.
Current behavior
The following code is generated:
declare(strict_types=1);
class false|int
{
}
class Mock_false|int_189b4275 extends false|int implementsPHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\Api;
use \PHPUnit\Framework\MockObject\Method;
use \PHPUnit\Framework\MockObject\MockedCloneMethod;
}
How to reproduce
Here's an example class:
<?phpnamespaceDummy;
class Sample
{
publicfunctiondoSomething(): false|int
{
returnfalse;
}
}
Using bool|int fixes the issue, but it changes the meaning of the function, because it will never return true. Besides, false|int is a valid unit type.
The text was updated successfully, but these errors were encountered:
Thank you for reporting this. This only happens when you create a test double and then do not configure a return value for a method that returns *|false.
Summary
PHPUnit generates invalid mock code when the type
false
is used in a union e.g.false|int
.Current behavior
The following code is generated:
How to reproduce
Here's an example class:
Here's an example test:
Expected behavior
The code for the mock is generated correctly.
Note
Using
bool|int
fixes the issue, but it changes the meaning of the function, because it will never returntrue
. Besides,false|int
is a valid unit type.The text was updated successfully, but these errors were encountered: