Class Spy
A spy records the arguments and results of function calls.
If you create a Spy without a mock function, it will use the existing function.
Example:
namespace foo; use phpmock\spy\Spy; function bar($min, $max) { return rand($min, $max) + 3; } $spy = new Spy(__NAMESPACE__, "rand"); $spy->enable(); $result = bar(1, 2); assert ([1, 2] == $spy->getInvocations()[0]->getArguments()); assert ($result == $spy->getInvocations()[0]->getReturn() + 3);
- phpmock\Mock implements phpmock\Deactivatable
- Extended by phpmock\spy\Spy
Namespace: phpmock\spy
License: WTFPL
Author: Markus Malkusch markus@malkusch.de
Link: Donations
Located at spy/Spy.php
Methods summary
License: WTFPL
Author: Markus Malkusch markus@malkusch.de
Link: Donations
Located at spy/Spy.php
public
#
__construct( string $namespace, string $name, callable $function = null )
Initializes the spy.
Initializes the spy.
If no function is specified it will use the existing function.
Parameters
- $namespace
- The namespace for the mock function.
- $name
- The function name of the mocked function.
- $function
- The mock function, or null for using the existing function.
Overrides
public
phpmock\spy\Invocation[]
#
The recorded function arguments.
getInvocations( )
Returns the recorded function calls and its arguments.
Returns the recorded function calls and its arguments.
Returns
phpmock\spy\Invocation[]The recorded function arguments.