PHP Class phpmock\spy\Spy

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);
Author: Markus Malkusch ([email protected])
Inheritance: extends phpmock\Mock
Show file Open project: php-mock/php-mock Class Usage Examples

Public Methods

Method Description
__construct ( string $namespace, string $name, callable $function = null ) Initializes the spy.
call ( array $arguments )
getInvocations ( ) : Invocation[] Returns the recorded function calls and its arguments.

Method Details

__construct() public method

If no function is specified it will use the existing function.
public __construct ( string $namespace, string $name, callable $function = null )
$namespace string The namespace for the mock function.
$name string The function name of the mocked function.
$function callable The mock function, or null for using the existing function.

call() public method

public call ( array $arguments )
$arguments array

getInvocations() public method

Returns the recorded function calls and its arguments.
public getInvocations ( ) : Invocation[]
return Invocation[] The recorded function arguments.