v1.4.0
Better Expectation errors
Modifies Expectation errors to use the new failure message generators in the constraints.
Test:
$spy = \Spies\make_spy();
$expectation = \Spies\expect_spy( $spy )->to_have_been_called->with( 'foo', 'bar' );
$spy( 'foo', 'baz' );
$expectation->verify();
Error Before:
Expected "a spy" to be called with ["foo","bar"] but instead it was called with ["foo","baz"]
Failed asserting that false is true.
Error After:
Failed asserting that a spy is called with arguments: ( "foo", "bar" ).
a spy was actually called with:
1. arguments: ( "foo", "baz" )
Add was_called_times_with
This adds a new Spy method, $spy->was_called_times_with( $count, $arg1, $arg2 )
which can be used to test if a method was called a number of times with specific arguments.
This was already possible using Expectations expect_spy( $spy )->to_have_been_called->with( $arg1, $arg2 )->times( $count )
but it's now backed by the Spy itself rather than implementing the test in the Expectation.
There's a matching assertSpyWasCalledTimesWith( $spy, $count, $args_array )
method also for the PHPUnit custom assertions.
Remove undocumented throw_exceptions
There used to be an undocumented parameter on Expectations called throw_exceptions
which would cause verify()
to throw an Exception instead of using an assertion. That flag has been removed.
Undocumented silent_failures
now returns a boolean
The other undocumented switch on Expectations is silent_failures
, which used to cause verify()
to return a string version of the error, but now causes it to return a boolean instead. If you rely on this feature, beware that it is in flux and may change in the future!