Mercurial > hg > isophonics-drupal-site
comparison vendor/phpunit/phpunit-mock-objects/src/Matcher/InvokedAtIndex.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php | |
2 /* | |
3 * This file is part of the phpunit-mock-objects package. | |
4 * | |
5 * (c) Sebastian Bergmann <sebastian@phpunit.de> | |
6 * | |
7 * For the full copyright and license information, please view the LICENSE | |
8 * file that was distributed with this source code. | |
9 */ | |
10 namespace PHPUnit\Framework\MockObject\Matcher; | |
11 | |
12 use PHPUnit\Framework\ExpectationFailedException; | |
13 use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; | |
14 | |
15 /** | |
16 * Invocation matcher which checks if a method was invoked at a certain index. | |
17 * | |
18 * If the expected index number does not match the current invocation index it | |
19 * will not match which means it skips all method and parameter matching. Only | |
20 * once the index is reached will the method and parameter start matching and | |
21 * verifying. | |
22 * | |
23 * If the index is never reached it will throw an exception in index. | |
24 */ | |
25 class InvokedAtIndex implements Invocation | |
26 { | |
27 /** | |
28 * @var int | |
29 */ | |
30 private $sequenceIndex; | |
31 | |
32 /** | |
33 * @var int | |
34 */ | |
35 private $currentIndex = -1; | |
36 | |
37 /** | |
38 * @param int $sequenceIndex | |
39 */ | |
40 public function __construct($sequenceIndex) | |
41 { | |
42 $this->sequenceIndex = $sequenceIndex; | |
43 } | |
44 | |
45 /** | |
46 * @return string | |
47 */ | |
48 public function toString() | |
49 { | |
50 return 'invoked at sequence index ' . $this->sequenceIndex; | |
51 } | |
52 | |
53 /** | |
54 * @param BaseInvocation $invocation | |
55 * | |
56 * @return bool | |
57 */ | |
58 public function matches(BaseInvocation $invocation) | |
59 { | |
60 $this->currentIndex++; | |
61 | |
62 return $this->currentIndex == $this->sequenceIndex; | |
63 } | |
64 | |
65 /** | |
66 * @param BaseInvocation $invocation | |
67 */ | |
68 public function invoked(BaseInvocation $invocation) | |
69 { | |
70 } | |
71 | |
72 /** | |
73 * Verifies that the current expectation is valid. If everything is OK the | |
74 * code should just return, if not it must throw an exception. | |
75 * | |
76 * @throws ExpectationFailedException | |
77 */ | |
78 public function verify() | |
79 { | |
80 if ($this->currentIndex < $this->sequenceIndex) { | |
81 throw new ExpectationFailedException( | |
82 \sprintf( | |
83 'The expected invocation at index %s was never reached.', | |
84 $this->sequenceIndex | |
85 ) | |
86 ); | |
87 } | |
88 } | |
89 } |