Completed
Pull Request — master (#152)
by Iltar
12:20
created

LiipMonitorBundleTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 4
Bugs 2 Features 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 61
rs 10
c 4
b 2
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testBuildWithCompilerPasses() 0 33 3
A setUp() 0 8 1
1
<?php
2
3
namespace Liip\MonitorBundle\Tests;
4
5
use Liip\MonitorBundle\LiipMonitorBundle;
6
use Symfony\Component\DependencyInjection\ChildDefinition;
7
8
/**
9
 * Liip\MonitorBundle\Tests\LiipMonitorBundleTest.
10
 */
11
class LiipMonitorBundleTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @var \PHPUnit_Framework_MockObject_MockObject
15
     */
16
    protected $container;
17
18
    /**
19
     * @var LiipMonitorBundle
20
     */
21
    protected $bundle;
22
23
    /**
24
     * Test bundle build to add all required compiler passes.
25
     */
26
    public function testBuildWithCompilerPasses()
27
    {
28
        $compilerPasses = array(
29
            'Liip\MonitorBundle\DependencyInjection\Compiler\AddGroupsCompilerPass' => true,
30
            'Liip\MonitorBundle\DependencyInjection\Compiler\GroupRunnersCompilerPass' => true,
31
            'Liip\MonitorBundle\DependencyInjection\Compiler\CheckTagCompilerPass' => true,
32
            'Liip\MonitorBundle\DependencyInjection\Compiler\CheckCollectionTagCompilerPass' => true,
33
            'Liip\MonitorBundle\DependencyInjection\Compiler\AdditionalReporterCompilerPass' => true,
34
        );
35
36
        $this->container->expects($this->exactly(count($compilerPasses)))
37
            ->method('addCompilerPass')
38
            ->with($this->isInstanceOf('Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface'))
39
            ->willReturnCallback(
40
                function ($compilerPass) use (&$compilerPasses) {
41
                    $class = get_class($compilerPass);
42
                    unset($compilerPasses[$class]);
43
                }
44
            );
45
46
        $definition = null;
47
48
        if (method_exists('Symfony\Component\DependencyInjection\ContainerBuilder', 'registerForAutoconfiguration')) {
49
            $this->container->method('registerForAutoconfiguration')->willReturn($definition = new ChildDefinition(''));
50
        }
51
52
        $this->bundle->build($this->container);
53
        $this->assertEmpty($compilerPasses);
54
55
        if ($definition) {
56
            $this->assertTrue($definition->hasTag('liip_monitor.check'));
57
        }
58
    }
59
60
    /**
61
     * Sets up test.
62
     */
63
    protected function setUp()
64
    {
65
        $this->container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
66
            ->disableOriginalConstructor()
67
            ->getMock();
68
69
        $this->bundle = new LiipMonitorBundle();
70
    }
71
}
72