library php-callable-spy
Spy library for testing php callables
marcelerz/php-callable-spy
Spy library for testing php callables
- Thursday, July 24, 2014
- by marcelerz
- Repository
- 1 Watchers
- 0 Stars
- 9 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 2 Versions
- 29 % Grown
php-callable-spy
PHP Callable Spy, (*1)
Example:, (*2)
// Closure to be spied on
$fn = function ($a, $b) {
return $a + $b;
};
// Replace closure with a spy
$fn = new \Callable\Spy($fn);
echo $fn(5, 3); // Output: 8 (through spy proxy)
// Gets last call made through spy proxy
$lastCall = $fn->getLastCall();
$timestamp = $lastCall->getDate(); // Timestamp of call
$stackTrace = $lastCall->getStackTrace(); // Full stack-trace of call
print_r($lastCall->getArgs()); // Output: [5, 3]
print_r($lastCall->getResult()); // Output: 8
For more examples, have a look in the examples folder above!
Also, there are a lot more examples as tests in the test folder., (*3)