1 : <?php
2 : /**
3 : * Mockery
4 : *
5 : * LICENSE
6 : *
7 : * This source file is subject to the new BSD license that is bundled
8 : * with this package in the file LICENSE.txt.
9 : * It is also available through the world-wide-web at this URL:
10 : * http://github.com/padraic/mockery/blob/master/LICENSE
11 : * If you did not receive a copy of the license and are unable to
12 : * obtain it through the world-wide-web, please send an email
13 : * to padraic@php.net so we can send you a copy immediately.
14 : *
15 : * @category Mockery
16 : * @package Mockery
17 : * @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com)
18 : * @license http://github.com/padraic/mockery/blob/master/LICENSE New BSD License
19 : */
20 :
21 : namespace Mockery;
22 :
23 : class CompositeExpectation
24 : {
25 :
26 : /**
27 : * Stores an array of all expectations for this composite
28 : *
29 : * @var array
30 : */
31 : protected $_expectations = array();
32 :
33 : /**
34 : * Add an expectation to the composite
35 : *
36 : * @param \Mockery\Expectation|\Mockery\CompositeExpectation $expectation
37 : * @return void
38 : */
39 : public function add($expectation)
40 : {
41 26 : $this->_expectations[] = $expectation;
42 26 : }
43 :
44 : /**
45 : * Intercept any expectation calls and direct against all expectations
46 : *
47 : * @param string $method
48 : * @param array $args
49 : * @return self
50 : */
51 : public function __call($method, array $args)
52 : {
53 26 : foreach ($this->_expectations as $expectation) {
54 26 : call_user_func_array(array($expectation, $method), $args);
55 26 : }
56 26 : return $this;
57 : }
58 :
59 : /**
60 : * Return order number of the first expectation
61 : *
62 : * @return int
63 : */
64 : public function getOrderNumber()
65 : {
66 0 : reset($this->_expectations);
67 0 : $first = current($this->_expectations);
68 0 : return $first->getOrderNumber();
69 : }
70 :
71 : /**
72 : * Return the parent mock of the first expectation
73 : *
74 : * @return \Mockery\MockInterface
75 : */
76 : public function getMock()
77 : {
78 0 : reset($this->_expectations);
79 0 : $first = current($this->_expectations);
80 0 : return $first->getMock();
81 : }
82 :
83 : /**
84 : * Mockery API alias to getMock
85 : *
86 : * @return \Mockery\MockInterface
87 : */
88 : public function mock()
89 : {
90 0 : return $this->getMock();
91 : }
92 :
93 : /**
94 : * Starts a new expectation addition on the first mock which is the primary
95 : * target outside of a demeter chain
96 : *
97 : * @return \Mockery\Expectation
98 : */
99 : public function shouldReceive()
100 : {
101 0 : $args = func_get_args();
102 0 : reset($this->_expectations);
103 0 : $first = current($this->_expectations);
104 0 : return call_user_func_array(array($first->getMock(), 'shouldReceive'), $args);
105 : }
106 :
107 : /**
108 : * Return the string summary of this composite expectation
109 : *
110 : * @return string
111 : */
112 : public function __toString()
113 : {
114 0 : $return = '[';
115 0 : $parts = array();
116 0 : foreach ($this->_expectations as $exp) {
117 0 : $parts[] = (string) $exp;
118 0 : }
119 0 : $return .= implode(', ', $parts) . ']';
120 0 : return $return;
121 : }
122 :
123 : }
|