Pull merge.
[yaffs-website] / vendor / phpspec / prophecy / src / Prophecy / Prediction / NoCallsPrediction.php
1 <?php
2
3 /*
4  * This file is part of the Prophecy.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *     Marcello Duarte <marcello.duarte@gmail.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Prophecy\Prediction;
13
14 use Prophecy\Call\Call;
15 use Prophecy\Prophecy\ObjectProphecy;
16 use Prophecy\Prophecy\MethodProphecy;
17 use Prophecy\Util\StringUtil;
18 use Prophecy\Exception\Prediction\UnexpectedCallsException;
19
20 /**
21  * No calls prediction.
22  *
23  * @author Konstantin Kudryashov <ever.zet@gmail.com>
24  */
25 class NoCallsPrediction implements PredictionInterface
26 {
27     private $util;
28
29     /**
30      * Initializes prediction.
31      *
32      * @param null|StringUtil $util
33      */
34     public function __construct(StringUtil $util = null)
35     {
36         $this->util = $util ?: new StringUtil;
37     }
38
39     /**
40      * Tests that there were no calls made.
41      *
42      * @param Call[]         $calls
43      * @param ObjectProphecy $object
44      * @param MethodProphecy $method
45      *
46      * @throws \Prophecy\Exception\Prediction\UnexpectedCallsException
47      */
48     public function check(array $calls, ObjectProphecy $object, MethodProphecy $method)
49     {
50         if (!count($calls)) {
51             return;
52         }
53
54         $verb = count($calls) === 1 ? 'was' : 'were';
55
56         throw new UnexpectedCallsException(sprintf(
57             "No calls expected that match:\n".
58             "  %s->%s(%s)\n".
59             "but %d %s made:\n%s",
60             get_class($object->reveal()),
61             $method->getMethodName(),
62             $method->getArgumentsWildcard(),
63             count($calls),
64             $verb,
65             $this->util->stringifyCalls($calls)
66         ), $method, $calls);
67     }
68 }