| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 28.57% covered (danger) | 28.57% | 2 / 7 | CRAP | 25.00% covered (danger) | 25.00% | 6 / 24
CompositeExpectation | 0.00% covered (danger) | 0.00% | 0 / 1 | 28.57% covered (danger) | 28.57% | 2 / 7 | 43.17 | 25.00% covered (danger) | 25.00% | 6 / 24
add($expectation) | 100.00% covered (success) | 100.00% | 1 / 1 | 1 | 100.00% covered (success) | 100.00% | 2 / 2
__call($method, array $args) | 100.00% covered (success) | 100.00% | 1 / 1 | 2 | 100.00% covered (success) | 100.00% | 4 / 4
getOrderNumber() | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 | 0.00% covered (danger) | 0.00% | 0 / 3
getMock() | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 | 0.00% covered (danger) | 0.00% | 0 / 3
mock() | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 | 0.00% covered (danger) | 0.00% | 0 / 1
shouldReceive() | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 | 0.00% covered (danger) | 0.00% | 0 / 4
__toString() | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 | 0.00% covered (danger) | 0.00% | 0 / 7

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-2014 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 | $this->_expectations[] = $expectation;
42 | }
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 | foreach ($this->_expectations as $expectation) {
54 | call_user_func_array(array($expectation, $method), $args);
55 | }
56 | return $this;
57 | }
58 |
59 | /**
60 | * Return order number of the first expectation
61 | *
62 | * @return int
63 | */
64 | public function getOrderNumber()
65 | {
66 | reset($this->_expectations);
67 | $first = current($this->_expectations);
68 | 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 | reset($this->_expectations);
79 | $first = current($this->_expectations);
80 | return $first->getMock();
81 | }
82 |
83 | /**
84 | * Mockery API alias to getMock
85 | *
86 | * @return \Mockery\MockInterface
87 | */
88 | public function mock()
89 | {
90 | 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 | $args = func_get_args();
102 | reset($this->_expectations);
103 | $first = current($this->_expectations);
104 | 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 | $return = '[';
115 | $parts = array();
116 | foreach ($this->_expectations as $exp) {
117 | $parts[] = (string) $exp;
118 | }
119 | $return .= implode(', ', $parts) . ']';
120 | return $return;
121 | }
122 |
123 | }