marcelerz/php-callable-spy

用于测试 PHP 可调用对象的间谍库

1.0.0 2014-07-24 06:51 UTC

This package is not auto-updated.

Last update: 2024-09-24 05:39:53 UTC


README

PHP Callable Spy

示例

// 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

更多示例,请查看上方的 examples 文件夹!此外,测试文件夹中还有更多作为测试的示例。