phpunit-psr7-assert icon indicating copy to clipboard operation
phpunit-psr7-assert copied to clipboard

Missing typehints and incorrect usage description

Open SvenRtbg opened this issue 7 years ago • 1 comments

The usage description reads:

assertMessageBodyMatches($message, $constraint) / bodyMatches($constraint)

Asserts that the message body matches the constraint $constraint. If $constraint is a primitive value, the assertion will pass when the message body is equal to the constraint. If $constraint is an instance of the PHPUnit\Framework\Constraint\Constraint class, the constraint will be evaluated as-is.

The trait definition has no type declaration for the $constraint parameter (https://github.com/martin-helmich/phpunit-psr7-assert/blob/master/src/Psr7Assertions.php#L41), however if I pass anything other than a PHPUnit Constraint object, I get a fatal error because the inner call static::bodyMatches($constraint) calls a function that requires a Constraint object.

The same is true for the function definition (https://github.com/martin-helmich/phpunit-psr7-assert/blob/master/src/Functions.php#L91) which passes the parameter straight to the constructor of Constraint\BodyMatchesConstraint, which requires the same object type and does not allow a primitive value.

The problem seems to be spread out over more than this example, but this was the one I stepped on right now.

The easy fix would be to add the type declaration - however passing a primitive value is much more useful.

SvenRtbg avatar Sep 19 '18 15:09 SvenRtbg

I'm facing the same issue.

martinssipenko avatar May 18 '19 10:05 martinssipenko