1 | <?php |
||
11 | class CIPHPUnitTestDouble |
||
12 | { |
||
13 | protected $testCase; |
||
14 | |||
15 | public function __construct(PHPUnit_Framework_TestCase $testCase) |
||
19 | |||
20 | /** |
||
21 | * Get Mock Object |
||
22 | * |
||
23 | * $email = $this->getMockBuilder('CI_Email') |
||
24 | * ->disableOriginalConstructor() |
||
25 | * ->setMethods(['send']) |
||
26 | * ->getMock(); |
||
27 | * $email->method('send')->willReturn(TRUE); |
||
28 | * |
||
29 | * will be |
||
30 | * |
||
31 | * $email = $this->getDouble('CI_Email', ['send' => TRUE]); |
||
32 | * |
||
33 | * @param string $classname |
||
34 | * @param array $params [method_name => return_value] |
||
35 | * @param mixed $constructor_params false: disable constructor, array: constructor params |
||
36 | * |
||
37 | * @return mixed PHPUnit mock object |
||
38 | */ |
||
39 | public function getDouble($classname, $params, $constructor_params = false) |
||
97 | |||
98 | protected function _verify($mock, $method, $params = null, $expects, $with) |
||
109 | |||
110 | /** |
||
111 | * Verifies that method was called exactly $times times |
||
112 | * |
||
113 | * $loader->expects($this->exactly(2)) |
||
114 | * ->method('view') |
||
115 | * ->withConsecutive( |
||
116 | * ['shop_confirm', $this->anything(), TRUE], |
||
117 | * ['shop_tmpl_checkout', $this->anything()] |
||
118 | * ); |
||
119 | * |
||
120 | * will be |
||
121 | * |
||
122 | * $this->verifyInvokedMultipleTimes( |
||
123 | * $loader, |
||
124 | * 'view', |
||
125 | * 2, |
||
126 | * [ |
||
127 | * ['shop_confirm', $this->anything(), TRUE], |
||
128 | * ['shop_tmpl_checkout', $this->anything()] |
||
129 | * ] |
||
130 | * ); |
||
131 | * |
||
132 | * @param mixed $mock PHPUnit mock object |
||
133 | * @param string $method |
||
134 | * @param int $times |
||
135 | * @param array $params arguments |
||
136 | */ |
||
137 | public function verifyInvokedMultipleTimes($mock, $method, $times, $params = null) |
||
143 | |||
144 | /** |
||
145 | * Verifies a method was invoked at least once |
||
146 | * |
||
147 | * @param mixed $mock PHPUnit mock object |
||
148 | * @param string $method |
||
149 | * @param array $params arguments |
||
150 | */ |
||
151 | public function verifyInvoked($mock, $method, $params = null) |
||
157 | |||
158 | /** |
||
159 | * Verifies that method was invoked only once |
||
160 | * |
||
161 | * @param mixed $mock PHPUnit mock object |
||
162 | * @param string $method |
||
163 | * @param array $params arguments |
||
164 | */ |
||
165 | public function verifyInvokedOnce($mock, $method, $params = null) |
||
171 | |||
172 | /** |
||
173 | * Verifies that method was not called |
||
174 | * |
||
175 | * @param mixed $mock PHPUnit mock object |
||
176 | * @param string $method |
||
177 | * @param array $params arguments |
||
178 | */ |
||
179 | public function verifyNeverInvoked($mock, $method, $params = null) |
||
185 | } |
||
186 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.