DoLLdapExtensionTest   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 65
c 1
b 0
f 0
dl 0
loc 139
rs 10
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A assertAlias() 0 3 1
A testLoadFullConfiguration() 0 13 1
A testTlsConfiguration() 0 13 1
A testSslTlsExclusiveConfiguration() 0 10 1
A tearDown() 0 3 1
A testSslConfiguration() 0 13 1
A assertParameter() 0 3 1
A testLoadDriverConfiguration() 0 13 1
A assertHasDefinition() 0 3 2
A testLoadMinimalConfiguration() 0 30 1
A testConfigurationNamespace() 0 5 1
1
<?php
2
3
namespace DoL\LdapBundle\Tests\DependencyInjection;
4
5
use DoL\LdapBundle\DependencyInjection\DoLLdapExtension;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
class DoLLdapExtensionTest extends \PHPUnit_Framework_TestCase
9
{
10
    use ConfigurationTrait;
11
12
    /** @var ContainerBuilder */
13
    public $container;
14
15
    public function testConfigurationNamespace()
16
    {
17
        $this->container = new ContainerBuilder();
18
        $this->container->registerExtension(new DoLLdapExtension());
19
        self::assertTrue($this->container->hasExtension('dol_ldap'));
20
    }
21
22
    public function testLoadMinimalConfiguration()
23
    {
24
        $minRequiredConfig = [
25
            'domains' => [
26
                'server1' => [
27
                    'driver' => [
28
                        'host' => 'ldap.hostname.local',
29
                    ],
30
                    'user' => [
31
                        'baseDn' => 'ou=Persons,dc=example,dc=com',
32
                    ],
33
                ],
34
            ],
35
        ];
36
37
        $defaultConfig = $this->getDefaultConfig();
38
39
        $this->container = new ContainerBuilder();
40
        $extension = new DoLLdapExtension();
41
42
        $extension->load([$minRequiredConfig], $this->container);
43
44
        self::assertHasDefinition('dol_ldap.ldap_driver');
0 ignored issues
show
Bug Best Practice introduced by
The method DoL\LdapBundle\Tests\Dep...::assertHasDefinition() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        self::/** @scrutinizer ignore-call */ 
45
              assertHasDefinition('dol_ldap.ldap_driver');
Loading history...
45
        self::assertHasDefinition('dol_ldap.ldap_manager.default');
46
47
        self::assertParameter($defaultConfig['domains'], 'dol_ldap.domains.parameters');
0 ignored issues
show
Bug Best Practice introduced by
The method DoL\LdapBundle\Tests\Dep...Test::assertParameter() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        self::/** @scrutinizer ignore-call */ 
48
              assertParameter($defaultConfig['domains'], 'dol_ldap.domains.parameters');
Loading history...
48
49
        self::assertAlias('dol_ldap.user_hydrator.default', 'dol_ldap.user_hydrator');
0 ignored issues
show
Bug Best Practice introduced by
The method DoL\LdapBundle\Tests\Dep...sionTest::assertAlias() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
        self::/** @scrutinizer ignore-call */ 
50
              assertAlias('dol_ldap.user_hydrator.default', 'dol_ldap.user_hydrator');
Loading history...
50
        self::assertAlias('dol_ldap.ldap_manager.default', 'dol_ldap.ldap_manager');
51
        self::assertAlias('dol_ldap.ldap_driver.zend', 'dol_ldap.ldap_driver');
52
    }
53
54
    public function testLoadFullConfiguration()
55
    {
56
        $config = $this->getDefaultConfig();
57
        $config['domains']['server1']['driver']['username'] = null;
58
        $config['domains']['server1']['driver']['password'] = null;
59
        $config['domains']['server1']['driver']['optReferrals'] = false;
60
61
        $this->container = new ContainerBuilder();
62
        $extension = new DoLLdapExtension();
63
64
        $extension->load([$config], $this->container);
65
66
        self::assertEquals($config['domains'], $this->container->getParameter('dol_ldap.domains.parameters'));
67
    }
68
69
    public function testLoadDriverConfiguration()
70
    {
71
        $config = $this->getDefaultConfig();
72
        $config['domains']['server1']['driver']['accountFilterFormat'] = '(%(uid=%s))';
73
74
        $this->container = new ContainerBuilder();
75
        $extension = new DoLLdapExtension();
76
77
        $extension->load([$config], $this->container);
78
79
        $loadedConfig = $this->container->getParameter('dol_ldap.domains.parameters');
80
        self::assertEquals($config['domains']['server1']['driver'], $loadedConfig['server1']['driver']);
81
        self::assertEquals($config['domains']['server1']['user'], $loadedConfig['server1']['user']);
82
    }
83
84
    public function testSslConfiguration()
85
    {
86
        $config = $this->getDefaultConfig();
87
        $config['domains']['server1']['driver']['useSsl'] = true;
88
        $config['domains']['server1']['driver']['useStartTls'] = false;
89
90
        $this->container = new ContainerBuilder();
91
        $extension = new DoLLdapExtension();
92
93
        $extension->load([$config], $this->container);
94
95
        $loadedConfig = $this->container->getParameter('dol_ldap.domains.parameters');
96
        self::assertEquals($config['domains']['server1']['driver'], $loadedConfig['server1']['driver']);
97
    }
98
99
    public function testTlsConfiguration()
100
    {
101
        $config = $this->getDefaultConfig();
102
        $config['domains']['server1']['driver']['useSsl'] = false;
103
        $config['domains']['server1']['driver']['useStartTls'] = true;
104
105
        $this->container = new ContainerBuilder();
106
        $extension = new DoLLdapExtension();
107
108
        $extension->load([$config], $this->container);
109
110
        $loadedConfig = $this->container->getParameter('dol_ldap.domains.parameters');
111
        self::assertEquals($config['domains']['server1']['driver'], $loadedConfig['server1']['driver']);
112
    }
113
114
    /**
115
     * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
116
     */
117
    public function testSslTlsExclusiveConfiguration()
118
    {
119
        $config = $this->getDefaultConfig();
120
        $config['domains']['server1']['driver']['useSsl'] = true;
121
        $config['domains']['server1']['driver']['useStartTls'] = true;
122
123
        $this->container = new ContainerBuilder();
124
        $extension = new DoLLdapExtension();
125
126
        $extension->load([$config], $this->container);
127
    }
128
129
    private function assertAlias($value, $key)
130
    {
131
        self::assertEquals($value, (string) $this->container->getAlias($key), sprintf('%s alias is not correct', $key));
132
    }
133
134
    private function assertParameter($value, $key)
135
    {
136
        self::assertEquals($value, $this->container->getParameter($key), sprintf('%s parameter is not correct', $key));
137
    }
138
139
    private function assertHasDefinition($id)
140
    {
141
        self::assertTrue(($this->container->hasDefinition($id) ?: $this->container->hasAlias($id)), sprintf('%s definition is not set', $id));
142
    }
143
144
    protected function tearDown()
145
    {
146
        unset($this->container);
147
    }
148
}
149