XabbuhXApiClientExtensionTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
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\Bundle\ClientBundle\Tests\DependencyInjection;
13
14
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
15
use Xabbuh\XApi\Bundle\ClientBundle\DependencyInjection\XabbuhXApiClientExtension;
16
17
/**
18
 * @author Christian Flothmann <[email protected]>
19
 */
20
class XabbuhXApiClientExtensionTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @var XabbuhXApiClientExtension
24
     */
25
    private $extension;
26
27
    /**
28
     * @var \PHPUnit_Framework_MockObject_MockObject
29
     */
30
    private $containerBuilder;
31
32
    protected function setUp()
33
    {
34
        $this->extension = new XabbuhXApiClientExtension();
35
        $this->containerBuilder = $this->createContainerBuilderMock();
36
    }
37
38
    public function testHasClientManagerDefinition()
39
    {
40
        $this->containerBuilder
41
            ->expects($this->once())
42
            ->method('setDefinition')
43
            ->with('xabbuh_xapi_client.client_manager', $this->anything());
44
45
        $this->loadConfiguration(array());
46
    }
47
48
    public function testClientsParameterWithoutClients()
49
    {
50
        $this->containerBuilder
51
            ->expects($this->once())
52
            ->method('setParameter')
53
            ->with('xabbuh_xapi_client.clients', array());
54
55
        $this->loadConfiguration(array());
56
    }
57
58
    public function testClientsParameterWithOneClient()
59
    {
60
        $this->containerBuilder
61
            ->expects($this->once())
62
            ->method('setParameter')
63
            ->with(
64
                'xabbuh_xapi_client.clients',
65
                array('foo' => 'xabbuh_xapi_client.client.foo')
66
            );
67
68
        $this->loadConfiguration(array(
69
            'clients' => array(
70
                'foo' => array(
71
                    'base_url' => 'http://example.com/xapi',
72
                ),
73
            ),
74
        ));
75
    }
76
77
    public function testClientsParameterWithMultipleClients()
78
    {
79
        $this->containerBuilder
80
            ->expects($this->once())
81
            ->method('setParameter')
82
            ->with(
83
                'xabbuh_xapi_client.clients',
84
                array(
85
                    'foo' => 'xabbuh_xapi_client.client.foo',
86
                    'bar' => 'xabbuh_xapi_client.client.bar',
87
                )
88
            );
89
90
        $this->loadConfiguration(array(
91
            'clients' => array(
92
                'foo' => array(
93
                    'base_url' => 'http://example.com/xapi',
94
                ),
95
                'bar' => array(
96
                    'base_url' => 'http://example.com/xapi',
97
                ),
98
            ),
99
        ));
100
    }
101
102
    public function testBundleAlias()
103
    {
104
        $this->assertEquals('xabbuh_xapi_client', $this->extension->getAlias());
105
    }
106
107
    private function createContainerBuilderMock()
108
    {
109
        $containerBuilder = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerBuilder')
110
            ->setMethods(array('getParameterBag', 'setParameter', 'setDefinition'))
111
            ->getMock();
112
        $containerBuilder->expects($this->any())
113
            ->method('getParameterBag')
114
            ->will($this->returnValue(new ParameterBag()));
115
116
        return $containerBuilder;
117
    }
118
119
    private function loadConfiguration($config)
120
    {
121
        $this->extension->load(array($config), $this->containerBuilder);
122
    }
123
}
124