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

LiipMonitorBundleTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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