10
10
use Enqueue \Null \NullContext ;
11
11
use Enqueue \Null \Symfony \NullTransportFactory ;
12
12
use Enqueue \Symfony \DefaultTransportFactory ;
13
+ use Enqueue \Symfony \TransportFactoryInterface ;
13
14
use Enqueue \Test \ClassExtensionTrait ;
14
15
use PHPUnit \Framework \TestCase ;
15
16
use Symfony \Component \DependencyInjection \ContainerBuilder ;
@@ -30,6 +31,25 @@ public function testCouldBeConstructedWithoutAnyArguments()
30
31
new EnqueueExtension ();
31
32
}
32
33
34
+ public function testShouldRegisterDefaultAndNullTransportFactoriesInConstructor ()
35
+ {
36
+ $ extension = new EnqueueExtension ();
37
+
38
+ /** @var TransportFactoryInterface[] $factories */
39
+ $ factories = $ this ->readAttribute ($ extension , 'factories ' );
40
+
41
+ $ this ->assertInternalType ('array ' , $ factories );
42
+ $ this ->assertCount (2 , $ factories );
43
+
44
+ $ this ->assertArrayHasKey ('default ' , $ factories );
45
+ $ this ->assertInstanceOf (DefaultTransportFactory::class, $ factories ['default ' ]);
46
+ $ this ->assertEquals ('default ' , $ factories ['default ' ]->getName ());
47
+
48
+ $ this ->assertArrayHasKey ('null ' , $ factories );
49
+ $ this ->assertInstanceOf (NullTransportFactory::class, $ factories ['null ' ]);
50
+ $ this ->assertEquals ('null ' , $ factories ['null ' ]->getName ());
51
+ }
52
+
33
53
public function testThrowIfTransportFactoryNameEmpty ()
34
54
{
35
55
$ extension = new EnqueueExtension ();
@@ -52,31 +72,32 @@ public function testThrowIfTransportFactoryWithSameNameAlreadyAdded()
52
72
$ extension ->addTransportFactory (new FooTransportFactory ('foo ' ));
53
73
}
54
74
55
- public function testShouldConfigureNullTransport ()
75
+ public function testShouldEnabledNullTransportAndSetItAsDefault ()
56
76
{
57
77
$ container = new ContainerBuilder ();
58
78
59
79
$ extension = new EnqueueExtension ();
60
- $ extension ->addTransportFactory (new NullTransportFactory ());
61
80
62
81
$ extension ->load ([[
63
82
'transport ' => [
83
+ 'default ' => 'null ' ,
64
84
'null ' => true ,
65
85
],
66
86
]], $ container );
67
87
88
+ self ::assertTrue ($ container ->hasAlias ('enqueue.transport.default.context ' ));
89
+ self ::assertEquals ('enqueue.transport.null.context ' , (string ) $ container ->getAlias ('enqueue.transport.default.context ' ));
90
+
68
91
self ::assertTrue ($ container ->hasDefinition ('enqueue.transport.null.context ' ));
69
92
$ context = $ container ->getDefinition ('enqueue.transport.null.context ' );
70
93
self ::assertEquals (NullContext::class, $ context ->getClass ());
71
94
}
72
95
73
- public function testShouldUseNullTransportAsDefault ()
96
+ public function testShouldUseNullTransportAsDefaultWhenExplicitlyConfigured ()
74
97
{
75
98
$ container = new ContainerBuilder ();
76
99
77
100
$ extension = new EnqueueExtension ();
78
- $ extension ->addTransportFactory (new NullTransportFactory ());
79
- $ extension ->addTransportFactory (new DefaultTransportFactory ());
80
101
81
102
$ extension ->load ([[
82
103
'transport ' => [
@@ -95,30 +116,6 @@ public function testShouldUseNullTransportAsDefault()
95
116
);
96
117
}
97
118
98
- public function testShouldUseNullTransportAsDefaultConfiguredViaDSN ()
99
- {
100
- $ container = new ContainerBuilder ();
101
-
102
- $ extension = new EnqueueExtension ();
103
- $ extension ->addTransportFactory (new NullTransportFactory ());
104
- $ extension ->addTransportFactory (new DefaultTransportFactory ());
105
-
106
- $ extension ->load ([[
107
- 'transport ' => [
108
- 'default ' => 'null:// ' ,
109
- ],
110
- ]], $ container );
111
-
112
- self ::assertEquals (
113
- 'enqueue.transport.default.context ' ,
114
- (string ) $ container ->getAlias ('enqueue.transport.context ' )
115
- );
116
- self ::assertEquals (
117
- 'enqueue.transport.default_null.context ' ,
118
- (string ) $ container ->getAlias ('enqueue.transport.default.context ' )
119
- );
120
- }
121
-
122
119
public function testShouldConfigureFooTransport ()
123
120
{
124
121
$ container = new ContainerBuilder ();
@@ -144,7 +141,6 @@ public function testShouldUseFooTransportAsDefault()
144
141
145
142
$ extension = new EnqueueExtension ();
146
143
$ extension ->addTransportFactory (new FooTransportFactory ());
147
- $ extension ->addTransportFactory (new DefaultTransportFactory ());
148
144
149
145
$ extension ->load ([[
150
146
'transport ' => [
@@ -168,7 +164,6 @@ public function testShouldLoadClientServicesWhenEnabled()
168
164
$ container = new ContainerBuilder ();
169
165
170
166
$ extension = new EnqueueExtension ();
171
- $ extension ->addTransportFactory (new DefaultTransportFactory ());
172
167
$ extension ->addTransportFactory (new FooTransportFactory ());
173
168
174
169
$ extension ->load ([[
@@ -191,7 +186,6 @@ public function testShouldUseProducerByDefault()
191
186
$ container ->setParameter ('kernel.debug ' , false );
192
187
193
188
$ extension = new EnqueueExtension ();
194
- $ extension ->addTransportFactory (new DefaultTransportFactory ());
195
189
$ extension ->addTransportFactory (new FooTransportFactory ());
196
190
197
191
$ extension ->load ([[
@@ -214,7 +208,6 @@ public function testShouldUseMessageProducerIfTraceableProducerOptionSetToFalseE
214
208
$ container ->setParameter ('kernel.debug ' , false );
215
209
216
210
$ extension = new EnqueueExtension ();
217
- $ extension ->addTransportFactory (new DefaultTransportFactory ());
218
211
$ extension ->addTransportFactory (new FooTransportFactory ());
219
212
220
213
$ extension ->load ([[
@@ -239,7 +232,6 @@ public function testShouldUseTraceableMessageProducerIfTraceableProducerOptionSe
239
232
$ container ->setParameter ('kernel.debug ' , true );
240
233
241
234
$ extension = new EnqueueExtension ();
242
- $ extension ->addTransportFactory (new DefaultTransportFactory ());
243
235
$ extension ->addTransportFactory (new FooTransportFactory ());
244
236
245
237
$ extension ->load ([[
@@ -274,7 +266,6 @@ public function testShouldLoadDelayRedeliveredMessageExtensionIfRedeliveredDelay
274
266
$ container ->setParameter ('kernel.debug ' , true );
275
267
276
268
$ extension = new EnqueueExtension ();
277
- $ extension ->addTransportFactory (new DefaultTransportFactory ());
278
269
$ extension ->addTransportFactory (new FooTransportFactory ());
279
270
280
271
$ extension ->load ([[
@@ -300,7 +291,6 @@ public function testShouldNotLoadDelayRedeliveredMessageExtensionIfRedeliveredDe
300
291
$ container ->setParameter ('kernel.debug ' , true );
301
292
302
293
$ extension = new EnqueueExtension ();
303
- $ extension ->addTransportFactory (new DefaultTransportFactory ());
304
294
$ extension ->addTransportFactory (new FooTransportFactory ());
305
295
306
296
$ extension ->load ([[
0 commit comments