Download the PHP package christopheraue/phpspy without Composer
On this page you can find all versions of the php package christopheraue/phpspy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download christopheraue/phpspy
More information about christopheraue/phpspy
Files in christopheraue/phpspy
Package phpspy
Short Description A test spy tracking calls to methods.
License MIT
Homepage https://github.com/christopheraue/phpspy
Informations about the package phpspy
PHP Spy
Track arguments and return values of calls to functions and methods when you cannot use PHPUnit Mocks. Spies do not interfere with the behavior of the code and delegate calls to the actual implementation of the spied on function by default. But, they can be configured to delegate calls to another function.
Requirements
- PHP > 5.3
- runkit
Installation
Via Composer
Add to your composer.json:
Usage
Spying
On functions
On methods
On static methods
Stubbing
Calls can be intercepted by giving the spy a substitute to execute instead. They are still tracked in this case. It works for functions and methods alike.
All callables qualify as valid substitute. Anonymous functions are executed in the context of the methods they are replacing. This means
- access to the scope resolution operator (
::
) usingparent
,self
andstatic
. - For objects,
$this
is defined and is pointing to the instance.
Complete API
Constructor
To spy on
- (static) methods:
new \christopheraue\phpspy\Spy($className, $methodName)
- functions:
new \christopheraue\phpspy\Spy($functionName)
Interface of a spy:
getCallCount()
: Returns the number of recorded calls.getCall($n)
: Returns the nth recorded call. Negative $n get calls from the back of the list.reset()
: Resets the spy by deleting all recorded calls.actAs($callable)
: Delegates calls to a spied on function to another callable.actNaturally()
: Delegates calls to the actual implementation of the spied on function (again).callOriginal($args = array(), $instance = null)
: Calls the original function without tracking the call. Arguments can be passed to the original function by passing an array with them as first argument. If the original function is a non-static method the second argument must carry the instance in which context it will be called.kill()
: Deletes all recorded calls, stops recording further calls and kills the spy.
Interface of a call:
getArgCount()
: Returns the number of recorded argumentsgetArg($n)
: Returns the nth argument of the call. Negative $n get arguments from the back of the list.getResult()
: Returns the return value of the call.getContext()
: Returnsnull
for functions, an reference to the object for methods and the class name for static methods.
All versions of phpspy with dependencies
ext-runkit Version *