RegisterClientsPassTest::testWithOneClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 12
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[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 Xabbuh\XApi\ClientBundle\Tests\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Definition;
15
use Symfony\Component\DependencyInjection\Reference;
16
use Xabbuh\XApi\Bundle\ClientBundle\DependencyInjection\Compiler\RegisterClientsPass;
17
18
/**
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
class RegisterClientsPassTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var RegisterClientsPass
25
     */
26
    private $compilerPass;
27
28
    /**
29
     * @var Definition
30
     */
31
    private $clientManager;
32
33
    /**
34
     * @var \Symfony\Component\DependencyInjection\ContainerBuilder
35
     */
36
    private $containerBuilder;
37
38
    protected function setUp()
39
    {
40
        $this->compilerPass = new RegisterClientsPass();
41
        $this->clientManager = $this->createClientManagerDefinition();
42
        $this->containerBuilder = $this->createContainerBuilder($this->clientManager);
43
    }
44
45
    public function testWithoutClients()
46
    {
47
        $this->setClientsParameter($this->containerBuilder, array());
48
        $this->compilerPass->process($this->containerBuilder);
49
50
        $this->assertEquals(array(), $this->clientManager->getArgument(0));
51
    }
52
53
    public function testWithOneClient()
54
    {
55
        $this->setClientsParameter($this->containerBuilder, array(
56
                'foo' => 'xabbuh_xapi_client.clients.foo'
57
        ));
58
        $this->compilerPass->process($this->containerBuilder);
59
60
        $this->assertEquals(
61
            array('foo' => new Reference('xabbuh_xapi_client.clients.foo')),
62
            $this->clientManager->getArgument(0)
63
        );
64
    }
65
66
    public function testWithMultipleClients()
67
    {
68
        $this->setClientsParameter($this->containerBuilder, array(
69
            'foo' => 'xabbuh_xapi_client.clients.foo',
70
            'bar' => 'xabbuh_xapi_client.clients.bar',
71
        ));
72
        $this->compilerPass->process($this->containerBuilder);
73
74
        $this->assertEquals(
75
            array(
76
                'foo' => new Reference('xabbuh_xapi_client.clients.foo'),
77
                'bar' => new Reference('xabbuh_xapi_client.clients.bar'),
78
            ),
79
            $this->clientManager->getArgument(0)
80
        );
81
    }
82
83
    private function createClientManagerDefinition()
84
    {
85
        return new Definition('\Xabbuh\XApi\ClientBundle\Manager\ClientManager');
86
    }
87
88
    private function createContainerBuilder($clientManager)
89
    {
90
        $containerBuilder = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerBuilder')
91
            ->setMethods(array('getDefinition', 'getParameter'))
92
            ->getMock();
93
        $containerBuilder->expects($this->any())
94
            ->method('getDefinition')
95
            ->with('xabbuh_xapi_client.client_manager')
96
            ->will($this->returnValue($clientManager));
97
98
        return $containerBuilder;
99
    }
100
101
    private function setClientsParameter($containerBuilder, array $clients)
102
    {
103
        $containerBuilder->expects($this->any())
104
            ->method('getParameter')
105
            ->with('xabbuh_xapi_client.clients')
106
            ->will($this->returnValue($clients));
107
    }
108
}
109