class CallbackPrediction
Executes preset callback.
@author Konstantin Kudryashov <ever.zet@gmail.com>
Hierarchy
- class \Prophecy\Prediction\CallbackPrediction implements \Prophecy\Prediction\PredictionInterface
Expanded class hierarchy of CallbackPrediction
File
-
vendor/
phpspec/ prophecy/ src/ Prophecy/ Prediction/ CallbackPrediction.php, line 26
Namespace
Prophecy\PredictionView source
class CallbackPrediction implements PredictionInterface {
private $callback;
/**
* @param callable $callback Custom callback
*
* @throws \Prophecy\Exception\InvalidArgumentException
*/
public function __construct($callback) {
if (!is_callable($callback)) {
throw new InvalidArgumentException(sprintf('Callable expected as an argument to CallbackPrediction, but got %s.', gettype($callback)));
}
$this->callback = $callback;
}
public function check(array $calls, ObjectProphecy $object, MethodProphecy $method) {
$callback = $this->callback;
if ($callback instanceof Closure && method_exists('Closure', 'bind') && (new ReflectionFunction($callback))->getClosureThis() !== null) {
$callback = Closure::bind($callback, $object) ?? $this->callback;
}
call_user_func($callback, $calls, $object, $method);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
CallbackPrediction::$callback | private | property | ||
CallbackPrediction::check | public | function | Tests that double fulfilled prediction. | Overrides PredictionInterface::check |
CallbackPrediction::__construct | public | function |