Skip to content

Constraints cannot be implemented without using internal class ExpectationFailedException #6243

@nreynis

Description

@nreynis

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.

Metadata

Metadata

Labels

type/bugSomething is brokenversion/10Something affects PHPUnit 10version/11Something affects PHPUnit 11version/12Something affects PHPUnit 12

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions