You are here

public function MethodProphecy::shouldHave in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Prophecy/MethodProphecy.php \Prophecy\Prophecy\MethodProphecy::shouldHave()

Checks provided prediction immediately.

Parameters

callable|Prediction\PredictionInterface $prediction:

Return value

$this

Throws

\Prophecy\Exception\InvalidArgumentException

4 calls to MethodProphecy::shouldHave()
MethodProphecy::checkPrediction in vendor/phpspec/prophecy/src/Prophecy/Prophecy/MethodProphecy.php
Checks currently registered [with should(...)] prediction.
MethodProphecy::shouldHaveBeenCalled in vendor/phpspec/prophecy/src/Prophecy/Prophecy/MethodProphecy.php
Checks call prediction.
MethodProphecy::shouldHaveBeenCalledTimes in vendor/phpspec/prophecy/src/Prophecy/Prophecy/MethodProphecy.php
Checks call times prediction.
MethodProphecy::shouldNotHaveBeenCalled in vendor/phpspec/prophecy/src/Prophecy/Prophecy/MethodProphecy.php
Checks no calls prediction.

File

vendor/phpspec/prophecy/src/Prophecy/Prophecy/MethodProphecy.php, line 271

Class

MethodProphecy
Method prophecy.

Namespace

Prophecy\Prophecy

Code

public function shouldHave($prediction) {
  if (is_callable($prediction)) {
    $prediction = new Prediction\CallbackPrediction($prediction);
  }
  if (!$prediction instanceof Prediction\PredictionInterface) {
    throw new InvalidArgumentException(sprintf('Expected callable or instance of PredictionInterface, but got %s.', gettype($prediction)));
  }
  if (null === $this->promise) {
    $this
      ->willReturn();
  }
  $calls = $this
    ->getObjectProphecy()
    ->findProphecyMethodCalls($this
    ->getMethodName(), $this
    ->getArgumentsWildcard());
  try {
    $prediction
      ->check($calls, $this
      ->getObjectProphecy(), $this);
    $this->checkedPredictions[] = $prediction;
  } catch (\Exception $e) {
    $this->checkedPredictions[] = $prediction;
    throw $e;
  }
  return $this;
}