You are here

class CallPrediction in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Prediction/CallPrediction.php \Prophecy\Prediction\CallPrediction

Call prediction.

@author Konstantin Kudryashov <ever.zet@gmail.com>

Hierarchy

Expanded class hierarchy of CallPrediction

File

vendor/phpspec/prophecy/src/Prophecy/Prediction/CallPrediction.php, line 27

Namespace

Prophecy\Prediction
View source
class CallPrediction implements PredictionInterface {
  private $util;

  /**
   * Initializes prediction.
   *
   * @param StringUtil $util
   */
  public function __construct(StringUtil $util = null) {
    $this->util = $util ?: new StringUtil();
  }

  /**
   * Tests that there was at least one call.
   *
   * @param Call[]         $calls
   * @param ObjectProphecy $object
   * @param MethodProphecy $method
   *
   * @throws \Prophecy\Exception\Prediction\NoCallsException
   */
  public function check(array $calls, ObjectProphecy $object, MethodProphecy $method) {
    if (count($calls)) {
      return;
    }
    $methodCalls = $object
      ->findProphecyMethodCalls($method
      ->getMethodName(), new ArgumentsWildcard(array(
      new AnyValuesToken(),
    )));
    if (count($methodCalls)) {
      throw new NoCallsException(sprintf("No calls have been made that match:\n" . "  %s->%s(%s)\n" . "but expected at least one.\n" . "Recorded `%s(...)` calls:\n%s", get_class($object
        ->reveal()), $method
        ->getMethodName(), $method
        ->getArgumentsWildcard(), $method
        ->getMethodName(), $this->util
        ->stringifyCalls($methodCalls)), $method);
    }
    throw new NoCallsException(sprintf("No calls have been made that match:\n" . "  %s->%s(%s)\n" . "but expected at least one.", get_class($object
      ->reveal()), $method
      ->getMethodName(), $method
      ->getArgumentsWildcard()), $method);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CallPrediction::$util private property
CallPrediction::check public function Tests that there was at least one call. Overrides PredictionInterface::check
CallPrediction::__construct public function Initializes prediction.