Releases: sirbrillig/spies
v1.5
v1.4.3
- Update array_clone to better avoid namespaces
- Silence warnings generated by array_map in resolve_delayed_expectations
v1.4.2
- Update array_clone to better avoid namespaces
v1.4.1
If an argument passed to a Spy
is an object, it will be passed by reference and stored as a reference in the SpyCall
. Before it can be checked by the assertion, it could be mutated by changing another reference to the object.
This release deeply clones function arguments before saving them to prevent possible mutations.
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!
v1.3.0
Add PHPUnit Custom Assertions
Add Custom assertions for PHPUnit if you subclass \Spies\TestCase
: https://github.com/sirbrillig/spies/blob/master/API.md#phpunit-custom-assertions
class MyTest extends \Spies\TestCase {
function test_spy_is_called_correctly() {
$spy = \Spies\make_spy();
$spy( 'hello', 'world', 7 );
$spy( 'hello', 'world', 8 );
$this->assertSpyWasCalledWith( 'hello', 'world', \Spies\any() );
}
}
These can be used in place of Expectations if you want a more pure PHPUnit test experience. You should still call \Spies\finish_spying();
though in your tearDown
method to clear all existing spies and mocks.
v1.2.0
Add Spy->was_called_when
to allow arbitrary argument matching.
Also adds matching Expectation->when
.
v1.1.3
Prevent accidentally ending an Expectation with once
or twice
(rather than the correct once()
or twice()
). This could cause breaking behavior, but any tests that break as a result of this fix were broken to begin with.
v1.1.2
Fix a bug wherein conditional returns could not be falsy (eg: an empty array). Now they can be whatever they want except for null.
v1.1.1
Fix glaring (but somehow hidden) bug which caused unconditional returns on stubs to be overwritten by conditional returns that were defined afterward.