1: <?php
2:
3: namespace Mockery;
4:
5: class VerificationDirector
6: {
7: private $receivedMethodCalls;
8: private $expectation;
9:
10: public function __construct(ReceivedMethodCalls $receivedMethodCalls, VerificationExpectation $expectation)
11: {
12: $this->receivedMethodCalls = $receivedMethodCalls;
13: $this->expectation = $expectation;
14: }
15:
16: public function verify()
17: {
18: return $this->receivedMethodCalls->verify($this->expectation);
19: }
20:
21: public function with()
22: {
23: return $this->cloneApplyAndVerify("with", func_get_args());
24: }
25:
26: public function withArgs(array $args)
27: {
28: return $this->cloneApplyAndVerify("withArgs", array($args));
29: }
30:
31: public function withNoArgs()
32: {
33: return $this->cloneApplyAndVerify("withNoArgs", array());
34: }
35:
36: public function withAnyArgs()
37: {
38: return $this->cloneApplyAndVerify("withAnyArgs", array());
39: }
40:
41: public function times($limit = null)
42: {
43: return $this->cloneWithoutCountValidatorsApplyAndVerify("times", array($limit));
44: }
45:
46: public function once()
47: {
48: return $this->cloneWithoutCountValidatorsApplyAndVerify("once", array());
49: }
50:
51: public function twice()
52: {
53: return $this->cloneWithoutCountValidatorsApplyAndVerify("twice", array());
54: }
55:
56: public function atLeast()
57: {
58: return $this->cloneWithoutCountValidatorsApplyAndVerify("atLeast", array());
59: }
60:
61: public function atMost()
62: {
63: return $this->cloneWithoutCountValidatorsApplyAndVerify("atMost", array());
64: }
65:
66: public function between($minimum, $maximum)
67: {
68: return $this->cloneWithoutCountValidatorsApplyAndVerify("between", array($minimum, $maximum));
69: }
70:
71: protected function cloneWithoutCountValidatorsApplyAndVerify($method, $args)
72: {
73: $expectation = clone $this->expectation;
74: $expectation->clearCountValidators();
75: call_user_func_array(array($expectation, $method), $args);
76: $director = new VerificationDirector($this->receivedMethodCalls, $expectation);
77: $director->verify();
78: return $director;
79: }
80:
81: protected function cloneApplyAndVerify($method, $args)
82: {
83: $expectation = clone $this->expectation;
84: call_user_func_array(array($expectation, $method), $args);
85: $director = new VerificationDirector($this->receivedMethodCalls, $expectation);
86: $director->verify();
87: return $director;
88: }
89: }
90: