phpunit
phpunit copied to clipboard
Constraints cannot be implemented without using internal class ExpectationFailedException
It is currently impossible to implement a custom Constraint without triggering a static analysis error:
------ --------------------------------------------------------------------------------------------------------------------------------------
Line test/unit/Domain/Chat/MessageConstraint.php
------ --------------------------------------------------------------------------------------------------------------------------------------
26 Call to method __construct() of internal class PHPUnit\Framework\ExpectationFailedException from outside its root namespace PHPUnit.
🪪 method.internalClass
26 Instantiation of internal class PHPUnit\Framework\ExpectationFailedException.
🪪 new.internalClass
39 Call to method __construct() of internal class PHPUnit\Framework\ExpectationFailedException from outside its root namespace PHPUnit.
🪪 method.internalClass
39 Instantiation of internal class PHPUnit\Framework\ExpectationFailedException.
🪪 new.internalClass
------ --------------------------------------------------------------------------------------------------------------------------------------
Expected behavior
ExpectationFailedException should not be marked as internal, or Constraint should allow throwing other kind of exceptions.
Does it suffice to remove @internal from ExpectationFailedException or must its parent classes not not be internal?
I tested and removing @internal from ExpectationFailedException is enough to make PHPStan happy.