6
6
7
7
use InvalidArgumentException ;
8
8
use Iter8 \Bundle \LdapRecordBundle \DependencyInjection \Iter8LdapRecordExtension ;
9
- use PHPUnit \Framework \TestCase ;
9
+ use Iter8 \Bundle \LdapRecordBundle \Tests \TestCase ;
10
+ use LdapRecord \Connection ;
11
+ use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
10
12
use Symfony \Component \DependencyInjection \ContainerBuilder ;
13
+ use Symfony \Component \DependencyInjection \ParameterBag \ParameterBag ;
11
14
12
15
class Iter8LdapRecordExtensionTest extends TestCase
13
16
{
@@ -22,14 +25,80 @@ public function test_cannot_configure_tls_and_ssl_for_connection(): void
22
25
$ extension ->load ([array_merge ($ this ->baseConfig (), ['use_ssl ' => true , 'use_tls ' => true ])], $ container );
23
26
}
24
27
28
+ public function test_load_empty_configuration (): void
29
+ {
30
+ $ this ->expectException (InvalidConfigurationException::class);
31
+
32
+ $ container = $ this ->createContainer ();
33
+ $ container ->registerExtension (new Iter8LdapRecordExtension ());
34
+ $ container ->loadFromExtension ('iter8_ldap_record ' );
35
+ $ container ->compile ();
36
+ }
37
+
38
+ public function test_load_valid_configuration (): void
39
+ {
40
+ $ container = $ this ->createContainer ();
41
+ $ container ->registerExtension (new Iter8LdapRecordExtension ());
42
+ $ container ->loadFromExtension ('iter8_ldap_record ' , $ this ->baseConfig ());
43
+ $ container ->compile ();
44
+
45
+ self ::assertTrue ($ container ->getDefinition ('iter8_ldap_record.connection ' )->isPublic ());
46
+ }
47
+
48
+ public function test_is_connected_with_auto_connect_disabled (): void
49
+ {
50
+ $ this ->getLdapConfig ();
51
+
52
+ $ container = $ this ->createContainer ();
53
+ $ container ->registerExtension (new Iter8LdapRecordExtension ());
54
+ $ container ->loadFromExtension ('iter8_ldap_record ' , $ this ->baseConfig ());
55
+ $ container ->compile ();
56
+
57
+ /** @var Connection $connection */
58
+ $ connection = $ container ->get ('iter8_ldap_record.connection ' );
59
+
60
+ self ::assertFalse ($ connection ->isConnected ());
61
+ }
62
+
63
+ public function test_is_connected_with_auto_connect_enabled (): void
64
+ {
65
+ $ this ->getLdapConfig ();
66
+
67
+ $ config = array_merge (
68
+ $ this ->baseConfig (),
69
+ ['auto_connect ' => true ]
70
+ );
71
+
72
+ $ container = $ this ->createContainer ();
73
+ $ container ->registerExtension (new Iter8LdapRecordExtension ());
74
+ $ container ->loadFromExtension ('iter8_ldap_record ' , $ config );
75
+ $ container ->compile ();
76
+
77
+ /** @var Connection $connection */
78
+ $ connection = $ container ->get ('iter8_ldap_record.connection ' );
79
+
80
+ self ::assertTrue ($ connection ->isConnected ());
81
+ }
82
+
25
83
private function baseConfig (): array
26
84
{
27
85
return [
28
- 'hosts ' => ['example_host.local ' ],
86
+ 'hosts ' => ['localhost ' ],
29
87
'base_dn ' => 'dc=local,dc=com ' ,
30
88
'username ' => 'cn=admin,dc=local,dc=com ' ,
31
89
'password ' => 'a_great_password ' ,
32
- 'auto_connect ' => true ,
90
+ 'port ' => 3389 ,
33
91
];
34
92
}
93
+
94
+ private function createContainer (): ContainerBuilder
95
+ {
96
+ return new ContainerBuilder (new ParameterBag ([
97
+ 'kernel.cache_dir ' => __DIR__ ,
98
+ 'kernel.project_dir ' => __DIR__ ,
99
+ 'kernel.charset ' => 'UTF-8 ' ,
100
+ 'kernel.debug ' => false ,
101
+ 'kernel.bundles ' => ['Iter8LdapRecordBundle ' => true ],
102
+ ]));
103
+ }
35
104
}
0 commit comments