Completed
Push — master ( 0708d4...99f0e4 )
by Rafał
02:36
created

testLoadWhenClientIdIsRequiredAndCannotBeEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Bridge for the Content API.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace SWP\Bundle\BridgeBundle\Tests\DependencyInjection;
15
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use SWP\Bundle\BridgeBundle\DependencyInjection\SWPBridgeExtension;
18
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
19
20
class SWPBridgeExtensionTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @covers SWP\Bundle\BridgeBundle\SWPBridgeBundle
24
     * @covers SWP\Bundle\BridgeBundle\DependencyInjection\SWPBridgeExtension::load
25
     * @covers SWP\Bundle\BridgeBundle\DependencyInjection\Configuration::getConfigTreeBuilder
26
     */
27
    public function testLoad()
28
    {
29
        $data = array(
30
            'swp_bridge.api.host' => 'example.com',
31
            'swp_bridge.api.port' => 8000,
32
            'swp_bridge.api.protocol' => 'http',
33
            'swp_bridge.auth.client_id' => 'my_client_id',
34
            'swp_bridge.auth.username' => 'my_username',
35
            'swp_bridge.auth.password' => 'my_password',
36
            'swp_bridge.options' => array('curl' => 'dummy'),
37
        );
38
39
        $container = $this->createContainer($data);
40
        $loader = $this->createLoader();
41
        $config = $this->getConfig();
42
43
        $loader->load(array($config), $container);
44
45
        foreach ($data as $key => $value) {
46
            $this->assertEquals($value, $container->getParameter($key));
47
        }
48
    }
49
50
    /**
51
     * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
52
     */
53 View Code Duplication
    public function testLoadWhenHostIsRequiredAndCannotBeEmpty()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $container = $this->createContainer();
56
        $loader = $this->createLoader();
57
58
        $config = array(
59
            'swp_bridge.api.host' => '',
60
        );
61
62
        $loader->load(array($config), $container);
63
    }
64
65
    /**
66
     * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
67
     */
68 View Code Duplication
    public function testLoadWhenClientIdIsRequiredAndCannotBeEmpty()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $container = $this->createContainer();
71
        $loader = $this->createLoader();
72
73
        $config = array(
74
            'swp_bridge.auth.client_id' => '',
75
        );
76
77
        $loader->load(array($config), $container);
78
    }
79
80
    /**
81
     * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
82
     */
83 View Code Duplication
    public function testLoadWhenUsernameIsRequiredAndCannotBeEmpty()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        $container = $this->createContainer();
86
        $loader = $this->createLoader();
87
88
        $config = array(
89
            'swp_bridge.auth.username' => '',
90
        );
91
92
        $loader->load(array($config), $container);
93
    }
94
95
    /**
96
     * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
97
     */
98 View Code Duplication
    public function testLoadWhenPasswordIsRequiredAndCannotBeEmpty()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100
        $container = $this->createContainer();
101
        $loader = $this->createLoader();
102
103
        $config = array(
104
            'swp_bridge.auth.password' => '',
105
        );
106
107
        $loader->load(array($config), $container);
108
    }
109
110
    protected function createLoader()
111
    {
112
        return new SWPBridgeExtension();
113
    }
114
115
    protected function getConfig()
116
    {
117
        return array(
118
            'api' => array(
119
                'host' => 'example.com',
120
                'port' => 8000,
121
                'protocol' => 'http',
122
            ),
123
            'auth' => array(
124
                'client_id' => 'my_client_id',
125
                'username' => 'my_username',
126
                'password' => 'my_password',
127
            ),
128
            'options' => array(
129
                'curl' => 'dummy',
130
            ),
131
        );
132
    }
133
134
    protected function createContainer(array $data = array())
135
    {
136
        return new ContainerBuilder(new ParameterBag($data));
137
    }
138
}
139