@@ -28,41 +28,133 @@ public function testCouldBeConstructedWithDebugAsArgument()
28
28
new Configuration (true );
29
29
}
30
30
31
- public function testShouldUseDefaultConfigurationIfNothingIsConfiguredAtAll ()
31
+ public function testShouldProcessNullAsDefaultNullTransport ()
32
32
{
33
33
$ configuration = new Configuration (true );
34
34
35
35
$ processor = new Processor ();
36
- $ config = $ processor ->processConfiguration ($ configuration , [[] ]);
36
+ $ config = $ processor ->processConfiguration ($ configuration , [null ]);
37
37
38
- $ this ->assertEquals ([
39
- 'transport ' => ['dsn ' => 'null: ' ],
40
- 'consumption ' => [
41
- 'receive_timeout ' => 10000 ,
38
+ $ this ->assertConfigEquals ([
39
+ 'transport ' => [
40
+ 'default ' => ['dsn ' => 'null: ' ],
42
41
],
43
- 'job ' => false ,
44
- 'async_events ' => ['enabled ' => false ],
45
- 'async_commands ' => ['enabled ' => false ],
46
- 'extensions ' => [
47
- 'doctrine_ping_connection_extension ' => false ,
48
- 'doctrine_clear_identity_map_extension ' => false ,
49
- 'signal_extension ' => function_exists ('pcntl_signal_dispatch ' ),
50
- 'reply_extension ' => true ,
42
+ ], $ config );
43
+ }
44
+
45
+ public function testShouldProcessStringAsDefaultDsnTransport ()
46
+ {
47
+ $ configuration = new Configuration (true );
48
+
49
+ $ processor = new Processor ();
50
+ $ config = $ processor ->processConfiguration ($ configuration , ['foo://bar?option=val ' ]);
51
+
52
+ $ this ->assertConfigEquals ([
53
+ 'transport ' => [
54
+ 'default ' => ['dsn ' => 'foo://bar?option=val ' ],
55
+ ],
56
+ ], $ config );
57
+ }
58
+
59
+ public function testShouldProcessEmptyArrayAsDefaultNullTransport ()
60
+ {
61
+ $ configuration = new Configuration (true );
62
+
63
+ $ processor = new Processor ();
64
+ $ config = $ processor ->processConfiguration ($ configuration , ['foo://bar?option=val ' ]);
65
+
66
+ $ this ->assertConfigEquals ([
67
+ 'transport ' => [
68
+ 'default ' => ['dsn ' => 'foo://bar?option=val ' ],
69
+ ],
70
+ ], $ config );
71
+ }
72
+
73
+ public function testShouldProcessSingleTransportAsDefault ()
74
+ {
75
+ $ configuration = new Configuration (true );
76
+
77
+ $ processor = new Processor ();
78
+ $ config = $ processor ->processConfiguration ($ configuration , [[
79
+ 'transport ' => 'foo://bar?option=val ' ,
80
+ ]]);
81
+
82
+ $ this ->assertConfigEquals ([
83
+ 'transport ' => [
84
+ 'default ' => ['dsn ' => 'foo://bar?option=val ' ],
85
+ ],
86
+ ], $ config );
87
+ }
88
+
89
+ public function testShouldProcessTransportWithDsnKeyAsDefault ()
90
+ {
91
+ $ configuration = new Configuration (true );
92
+
93
+ $ processor = new Processor ();
94
+ $ config = $ processor ->processConfiguration ($ configuration , [[
95
+ 'transport ' => [
96
+ 'dsn ' => 'foo://bar?option=val ' ,
97
+ ],
98
+ ]]);
99
+
100
+ $ this ->assertConfigEquals ([
101
+ 'transport ' => [
102
+ 'default ' => ['dsn ' => 'foo://bar?option=val ' ],
51
103
],
52
104
], $ config );
53
105
}
54
106
55
- public function testShouldUseDefaultTransportIfIfTransportIsConfiguredAtAll ()
107
+ public function testShouldProcessSeveralTransports ()
56
108
{
57
109
$ configuration = new Configuration (true );
58
110
59
111
$ processor = new Processor ();
60
112
$ config = $ processor ->processConfiguration ($ configuration , [[
61
- 'transport ' => null ,
113
+ 'transport ' => [
114
+ 'default ' => ['dsn ' => 'default: ' ],
115
+ 'foo ' => ['dsn ' => 'foo: ' ],
116
+ 'bar ' => ['dsn ' => 'bar: ' ],
117
+ ],
62
118
]]);
63
119
120
+ $ this ->assertConfigEquals ([
121
+ 'transport ' => [
122
+ 'default ' => ['dsn ' => 'default: ' ],
123
+ 'foo ' => ['dsn ' => 'foo: ' ],
124
+ 'bar ' => ['dsn ' => 'bar: ' ],
125
+ ],
126
+ ], $ config );
127
+ }
128
+
129
+ public function testTransportFactoryShouldValidateEachTransportAccordingToItsRules ()
130
+ {
131
+ $ configuration = new Configuration (true );
132
+
133
+ $ processor = new Processor ();
134
+
135
+ $ this ->expectException (\LogicException::class);
136
+ $ this ->expectExceptionMessage ('Both options factory_class and factory_service are set. Please choose one. ' );
137
+ $ processor ->processConfiguration ($ configuration , [
138
+ [
139
+ 'transport ' => [
140
+ 'default ' => [
141
+ 'factory_class ' => 'aClass ' ,
142
+ 'factory_service ' => 'aService ' ,
143
+ ],
144
+ ],
145
+ ],
146
+ ]);
147
+ }
148
+
149
+ public function testShouldUseDefaultConfigurationIfNothingIsConfiguredAtAll ()
150
+ {
151
+ $ configuration = new Configuration (true );
152
+
153
+ $ processor = new Processor ();
154
+ $ config = $ processor ->processConfiguration ($ configuration , [[]]);
155
+
64
156
$ this ->assertEquals ([
65
- 'transport ' => ['dsn ' => 'null: ' ],
157
+ 'transport ' => ['default ' => [ ' dsn ' => 'null: ' ] ],
66
158
'consumption ' => [
67
159
'receive_timeout ' => 10000 ,
68
160
],
@@ -88,8 +180,7 @@ public function testShouldSetDefaultConfigurationForClient()
88
180
'client ' => null ,
89
181
]]);
90
182
91
- $ this ->assertArraySubset ([
92
- 'transport ' => ['dsn ' => 'null: ' ],
183
+ $ this ->assertConfigEquals ([
93
184
'client ' => [
94
185
'prefix ' => 'enqueue ' ,
95
186
'app_name ' => 'app ' ,
@@ -403,4 +494,9 @@ public function testShouldAllowConfigureConsumption()
403
494
],
404
495
], $ config );
405
496
}
497
+
498
+ private function assertConfigEquals (array $ expected , array $ actual ): void
499
+ {
500
+ $ this ->assertArraySubset ($ expected , $ actual , false , var_export ($ actual , true ));
501
+ }
406
502
}
0 commit comments