4 * This file is part of the Prophecy.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6 * Marcello Duarte <marcello.duarte@gmail.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Prophecy\Prediction;
14 use Prophecy\Call\Call;
15 use Prophecy\Prophecy\ObjectProphecy;
16 use Prophecy\Prophecy\MethodProphecy;
17 use Prophecy\Argument\ArgumentsWildcard;
18 use Prophecy\Argument\Token\AnyValuesToken;
19 use Prophecy\Util\StringUtil;
20 use Prophecy\Exception\Prediction\NoCallsException;
25 * @author Konstantin Kudryashov <ever.zet@gmail.com>
27 class CallPrediction implements PredictionInterface
32 * Initializes prediction.
34 * @param StringUtil $util
36 public function __construct(StringUtil $util = null)
38 $this->util = $util ?: new StringUtil;
42 * Tests that there was at least one call.
44 * @param Call[] $calls
45 * @param ObjectProphecy $object
46 * @param MethodProphecy $method
48 * @throws \Prophecy\Exception\Prediction\NoCallsException
50 public function check(array $calls, ObjectProphecy $object, MethodProphecy $method)
56 $methodCalls = $object->findProphecyMethodCalls(
57 $method->getMethodName(),
58 new ArgumentsWildcard(array(new AnyValuesToken))
61 if (count($methodCalls)) {
62 throw new NoCallsException(sprintf(
63 "No calls have been made that match:\n".
65 "but expected at least one.\n".
66 "Recorded `%s(...)` calls:\n%s",
68 get_class($object->reveal()),
69 $method->getMethodName(),
70 $method->getArgumentsWildcard(),
71 $method->getMethodName(),
72 $this->util->stringifyCalls($methodCalls)
76 throw new NoCallsException(sprintf(
77 "No calls have been made that match:\n".
79 "but expected at least one.",
81 get_class($object->reveal()),
82 $method->getMethodName(),
83 $method->getArgumentsWildcard()