DependencyInjectionTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 57
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assertDICDefinitionClass() 0 6 1
A assertDICConstructorArguments() 0 9 1
A assertDICDefinitionMethodCallAt() 0 21 3
1
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Alawar\NginxPushStreamBundle\Tests\DependencyInjection;
13
14
15
use Symfony\Component\DependencyInjection\Definition;
16
17
abstract class DependencyInjectionTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * Assertion on the Class of a DIC Service Definition.
21
     *
22
     * @param Definition $definition
23
     * @param string $expectedClass
24
     */
25
    protected function assertDICDefinitionClass($definition, $expectedClass)
26
    {
27
        $this->assertEquals($expectedClass, $definition->getClass(),
28
            "Expected Class of the DIC Container Service Definition is wrong."
29
        );
30
    }
31
32
    /**
33
     * @param Definition $definition
34
     * @param array $args
35
     */
36
    protected function assertDICConstructorArguments($definition, $args)
37
    {
38
        $this->assertEquals(
39
            $args,
40
            $definition->getArguments(),
41
            "Expected and actual DIC Service constructor arguments of definition '"
42
            .$definition->getClass()."' don't match."
43
        );
44
    }
45
46
    /**
47
     * @param int $pos
48
     * @param Definition $definition
49
     * @param string $methodName
50
     * @param array $params
51
     */
52
    protected function assertDICDefinitionMethodCallAt($pos, $definition, $methodName, array $params = null)
53
    {
54
        $calls = $definition->getMethodCalls();
55
        if (isset($calls[$pos][0])) {
56
            $this->assertEquals(
57
                $methodName,
58
                $calls[$pos][0],
59
                "Method '".$methodName."' is expected to be called at position $pos."
60
            );
61
62
            if ($params !== null) {
63
                $this->assertEquals(
64
                    $params,
65
                    $calls[$pos][1],
66
                    "Expected parameters to methods '".$methodName."' do not match the actual parameters."
67
                );
68
            }
69
        } else {
70
            $this->fail("Method '".$methodName."' is expected to be called at position $pos.");
71
        }
72
    }
73
}
74