1 | <?php |
||
8 | class DependencyInjectorTest extends \PHPUnit_Framework_TestCase |
||
9 | { |
||
10 | /** |
||
11 | * @var DependencyInjector |
||
12 | */ |
||
13 | protected $object; |
||
14 | |||
15 | /** |
||
16 | * Sets up the fixture, for example, opens a network connection. |
||
17 | * This method is called before a test is executed. |
||
18 | */ |
||
19 | protected function setUp() |
||
23 | |||
24 | /** |
||
25 | * Tears down the fixture, for example, closes a network connection. |
||
26 | * This method is called after a test is executed. |
||
27 | */ |
||
28 | protected function tearDown() |
||
32 | |||
33 | /** |
||
34 | * @covers Koch\DI\DependencyInjector::register |
||
35 | * @covers Koch\DI\DependencyInjector::instantiate |
||
36 | * @covers Koch\DI\DependencyInjector::register |
||
37 | */ |
||
38 | public function testRegister() |
||
49 | |||
50 | /** |
||
51 | * @covers Koch\DI\DependencyInjector::forVariable |
||
52 | * @covers Koch\DI\DependencyInjector::register |
||
53 | * @covers Koch\DI\DependencyInjector::instantiate |
||
54 | * @covers Koch\DI\Engine\Variable::willUse |
||
55 | */ |
||
56 | public function testForVariable() |
||
71 | |||
72 | /** |
||
73 | * @covers Koch\DI\DependencyInjector::whenCreating |
||
74 | * @covers Koch\DI\Engine\Context::wrapWith |
||
75 | * @covers Koch\DI\DependencyInjector::instantiate |
||
76 | */ |
||
77 | public function testWhenCreating() |
||
90 | |||
91 | /** |
||
92 | * @covers Koch\DI\DependencyInjector::forType |
||
93 | * @covers Koch\DI\Engine\Type::call |
||
94 | * @covers Koch\DI\DependencyInjector::instantiate |
||
95 | */ |
||
96 | public function testForType() |
||
109 | |||
110 | /** |
||
111 | * @covers Koch\DI\DependencyInjector::fill |
||
112 | * @covers Koch\DI\DependencyInjector::with |
||
113 | * @covers Koch\DI\DependencyInjector::instantiate |
||
114 | */ |
||
115 | public function testFill() |
||
125 | |||
126 | /** |
||
127 | * @covers Koch\DI\DependencyInjector::with |
||
128 | * @covers Koch\DI\DependencyInjector::fill |
||
129 | * @covers Koch\DI\DependencyInjector::instantiate |
||
130 | */ |
||
131 | public function testWith() |
||
147 | |||
148 | /** |
||
149 | * @covers Koch\DI\DependencyInjector::instantiate |
||
150 | * @covers Koch\DI\DependencyInjector::instantiate |
||
151 | * @covers Koch\DI\DependencyInjector::register |
||
152 | * @covers Koch\DI\DependencyInjector::forVariable |
||
153 | * @covers Koch\DI\DependencyInjector::forType |
||
154 | * @covers Koch\DI\Engine\Type::call |
||
155 | * @covers Koch\DI\Engine\Variable::willUse |
||
156 | */ |
||
157 | public function testCreate() |
||
248 | |||
249 | /** |
||
250 | * @covers Koch\DI\DependencyInjector::instantiate |
||
251 | * @expectedException Koch\DI\Exception\CannotFindImplementation |
||
252 | * @expectedExceptionMessage InterfaceWithManyImplementations |
||
253 | */ |
||
254 | public function testCreateCreatingInterfaceWithManyImplementationsThrowsException() |
||
260 | |||
261 | /** |
||
262 | * @covers Koch\DI\DependencyInjector::instantiate |
||
263 | * @expectedException Koch\DI\Exception\CannotFindImplementation |
||
264 | * @expectedExceptionMessage NonExistingClass |
||
265 | */ |
||
266 | public function testCreateCreatingNonExistingClassThrowsException() |
||
270 | |||
271 | /** |
||
272 | * @covers Koch\DI\DependencyInjector::pickFactory |
||
273 | * @expectedException \Koch\DI\Exception\CannotDetermineImplementation |
||
274 | */ |
||
275 | public function testPickFactory() |
||
281 | |||
282 | /** |
||
283 | * @covers Koch\DI\DependencyInjector::settersFor |
||
284 | */ |
||
285 | public function testSettersFor() |
||
290 | |||
291 | /** |
||
292 | * @covers Koch\DI\DependencyInjector::wrappersFor |
||
293 | */ |
||
294 | public function testWrappersFor() |
||
299 | |||
300 | /** |
||
301 | * @covers Koch\DI\DependencyInjector::useParameters |
||
302 | */ |
||
303 | public function testUseParameters() |
||
309 | |||
310 | /** |
||
311 | * @covers Koch\DI\DependencyInjector::instantiateParameter |
||
312 | */ |
||
313 | public function testInstantiateParameter() |
||
314 | { |
||
315 | // prepare param 1 |
||
316 | $parameter = $this->getMock('parameter', ['getName']); |
||
317 | // Calling $parameter->getName() will now return 'name'. |
||
318 | $parameter->expects($this->any())->method('getName')->will($this->returnValue('name')); |
||
319 | // prepare param 2 |
||
320 | $nesting = ''; |
||
321 | // prepare class |
||
322 | $this->object->named_parameters['name'] = 'someValue'; |
||
323 | |||
324 | $erv = $this->object->instantiateParameter($parameter, $nesting); |
||
325 | |||
326 | $this->assertEquals('someValue', $erv); |
||
327 | } |
||
328 | |||
329 | /** |
||
330 | * @covers Koch\DI\DependencyInjector::instantiateParameter |
||
331 | * @expectedException Koch\DI\Exception\MissingDependency |
||
332 | * @expectedExceptionMessage theMissingDependency |
||
333 | */ |
||
334 | public function testInstantiateParameterThrowsException() |
||
335 | { |
||
336 | // prepare param 1 |
||
337 | $parameter = $this->getMock('parameter', ['getName']); |
||
338 | // Calling $parameter->getName() will now return 'name'. |
||
339 | $parameter->expects($this->any())->method('getName')->will($this->returnValue('theMissingDependency')); |
||
340 | // prepare param 2 |
||
341 | $nesting = ''; |
||
342 | |||
343 | $erv = $this->object->instantiateParameter($parameter, $nesting); |
||
344 | |||
345 | $this->assertEquals('someValue', $erv); |
||
346 | } |
||
347 | |||
348 | /** |
||
349 | * @covers Koch\DI\DependencyInjector::repository |
||
350 | */ |
||
351 | public function testRepository() |
||
355 | } |
||
356 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.