3
3
namespace ShiftOneLabs \LaravelSqsFifoQueue \Tests ;
4
4
5
5
use InvalidArgumentException ;
6
+ use ShiftOneLabs \LaravelSqsFifoQueue \Support \Arr ;
6
7
use ShiftOneLabs \LaravelSqsFifoQueue \SqsFifoQueue ;
7
8
use ShiftOneLabs \LaravelSqsFifoQueue \Queue \Connectors \SqsFifoConnector ;
8
9
@@ -27,4 +28,211 @@ public function test_sqs_fifo_driver_throws_exception_with_invalid_queue_name()
27
28
28
29
$ connector ->connect ($ config );
29
30
}
31
+
32
+ public function test_sqs_fifo_driver_creates_queue_with_missing_prefix ()
33
+ {
34
+ $ config = $ this ->getConfig ([], ['prefix ' ]);
35
+ $ connector = new SqsFifoConnector ();
36
+
37
+ $ queue = $ connector ->connect ($ config );
38
+
39
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
40
+
41
+ if (property_exists ($ queue , 'prefix ' )) {
42
+ $ this ->assertEquals ('' , $ this ->getRestrictedValue ($ queue , 'prefix ' ));
43
+ }
44
+ }
45
+
46
+ public function test_sqs_fifo_driver_creates_queue_with_empty_prefix ()
47
+ {
48
+ $ config = $ this ->getConfig (['prefix ' => '' ]);
49
+ $ connector = new SqsFifoConnector ();
50
+
51
+ $ queue = $ connector ->connect ($ config );
52
+
53
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
54
+
55
+ if (property_exists ($ queue , 'prefix ' )) {
56
+ $ this ->assertEquals ('' , $ this ->getRestrictedValue ($ queue , 'prefix ' ));
57
+ }
58
+ }
59
+
60
+ public function test_sqs_fifo_driver_creates_queue_with_valid_prefix ()
61
+ {
62
+ $ config = $ this ->getConfig ();
63
+ $ connector = new SqsFifoConnector ();
64
+
65
+ $ queue = $ connector ->connect ($ config );
66
+
67
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
68
+
69
+ if (property_exists ($ queue , 'prefix ' )) {
70
+ $ this ->assertNotEmpty ($ config ['prefix ' ]);
71
+ $ this ->assertEquals ($ config ['prefix ' ], $ this ->getRestrictedValue ($ queue , 'prefix ' ));
72
+ }
73
+ }
74
+
75
+ public function test_sqs_fifo_driver_creates_queue_with_missing_suffix ()
76
+ {
77
+ $ config = $ this ->getConfig ([], ['suffix ' ]);
78
+ $ connector = new SqsFifoConnector ();
79
+
80
+ $ queue = $ connector ->connect ($ config );
81
+
82
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
83
+ $ this ->assertEquals ('' , $ this ->getRestrictedValue ($ queue , 'suffix ' ));
84
+ }
85
+
86
+ public function test_sqs_fifo_driver_creates_queue_with_empty_suffix ()
87
+ {
88
+ $ config = $ this ->getConfig (['suffix ' => '' ]);
89
+ $ connector = new SqsFifoConnector ();
90
+
91
+ $ queue = $ connector ->connect ($ config );
92
+
93
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
94
+ $ this ->assertEquals ('' , $ this ->getRestrictedValue ($ queue , 'suffix ' ));
95
+ }
96
+
97
+ public function test_sqs_fifo_driver_creates_queue_with_valid_suffix ()
98
+ {
99
+ $ config = $ this ->getConfig ();
100
+ $ connector = new SqsFifoConnector ();
101
+
102
+ $ queue = $ connector ->connect ($ config );
103
+
104
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
105
+ $ this ->assertNotEmpty ($ config ['suffix ' ]);
106
+ $ this ->assertEquals ($ config ['suffix ' ], $ this ->getRestrictedValue ($ queue , 'suffix ' ));
107
+ }
108
+
109
+ public function test_sqs_fifo_driver_creates_queue_with_default_group_when_missing_group ()
110
+ {
111
+ $ config = $ this ->getConfig ([], ['group ' ]);
112
+ $ connector = new SqsFifoConnector ();
113
+
114
+ $ queue = $ connector ->connect ($ config );
115
+
116
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
117
+ $ this ->assertEquals ('default ' , $ this ->getRestrictedValue ($ queue , 'group ' ));
118
+ }
119
+
120
+ public function test_sqs_fifo_driver_creates_queue_with_empty_group ()
121
+ {
122
+ $ config = $ this ->getConfig (['group ' => '' ]);
123
+ $ connector = new SqsFifoConnector ();
124
+
125
+ $ queue = $ connector ->connect ($ config );
126
+
127
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
128
+ $ this ->assertEquals ('' , $ this ->getRestrictedValue ($ queue , 'group ' ));
129
+ }
130
+
131
+ public function test_sqs_fifo_driver_creates_queue_with_valid_group ()
132
+ {
133
+ $ config = $ this ->getConfig ();
134
+ $ connector = new SqsFifoConnector ();
135
+
136
+ $ queue = $ connector ->connect ($ config );
137
+
138
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
139
+ $ this ->assertNotEmpty ($ config ['group ' ]);
140
+ $ this ->assertEquals ($ config ['group ' ], $ this ->getRestrictedValue ($ queue , 'group ' ));
141
+ }
142
+
143
+ public function test_sqs_fifo_driver_creates_queue_with_default_deduplicator_when_missing_deduplicator ()
144
+ {
145
+ $ config = $ this ->getConfig ([], ['deduplicator ' ]);
146
+ $ connector = new SqsFifoConnector ();
147
+
148
+ $ queue = $ connector ->connect ($ config );
149
+
150
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
151
+ $ this ->assertEquals ('unique ' , $ this ->getRestrictedValue ($ queue , 'deduplicator ' ));
152
+ }
153
+
154
+ public function test_sqs_fifo_driver_creates_queue_with_empty_deduplicator ()
155
+ {
156
+ $ config = $ this ->getConfig (['deduplicator ' => '' ]);
157
+ $ connector = new SqsFifoConnector ();
158
+
159
+ $ queue = $ connector ->connect ($ config );
160
+
161
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
162
+ $ this ->assertEquals ('' , $ this ->getRestrictedValue ($ queue , 'deduplicator ' ));
163
+ }
164
+
165
+ public function test_sqs_fifo_driver_creates_queue_with_valid_deduplicator ()
166
+ {
167
+ $ config = $ this ->getConfig ();
168
+ $ connector = new SqsFifoConnector ();
169
+
170
+ $ queue = $ connector ->connect ($ config );
171
+
172
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
173
+ $ this ->assertNotEmpty ($ config ['deduplicator ' ]);
174
+ $ this ->assertEquals ($ config ['deduplicator ' ], $ this ->getRestrictedValue ($ queue , 'deduplicator ' ));
175
+ }
176
+
177
+ public function test_sqs_fifo_driver_creates_queue_with_default_allow_delay_when_missing_allow_delay ()
178
+ {
179
+ $ config = $ this ->getConfig ([], ['allow_delay ' ]);
180
+ $ connector = new SqsFifoConnector ();
181
+
182
+ $ queue = $ connector ->connect ($ config );
183
+
184
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
185
+ $ this ->assertEquals (false , $ this ->getRestrictedValue ($ queue , 'allowDelay ' ));
186
+ }
187
+
188
+ public function test_sqs_fifo_driver_creates_queue_with_empty_allow_delay ()
189
+ {
190
+ $ config = $ this ->getConfig (['allow_delay ' => '' ]);
191
+ $ connector = new SqsFifoConnector ();
192
+
193
+ $ queue = $ connector ->connect ($ config );
194
+
195
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
196
+ $ this ->assertEquals (false , $ this ->getRestrictedValue ($ queue , 'allowDelay ' ));
197
+ }
198
+
199
+ public function test_sqs_fifo_driver_creates_queue_with_valid_allow_delay_as_false ()
200
+ {
201
+ $ config = $ this ->getConfig (['allow_delay ' => false ]);
202
+ $ connector = new SqsFifoConnector ();
203
+
204
+ $ queue = $ connector ->connect ($ config );
205
+
206
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
207
+ $ this ->assertFalse ($ config ['allow_delay ' ]);
208
+ $ this ->assertEquals ($ config ['allow_delay ' ], $ this ->getRestrictedValue ($ queue , 'allowDelay ' ));
209
+ }
210
+
211
+ public function test_sqs_fifo_driver_creates_queue_with_valid_allow_delay_as_true ()
212
+ {
213
+ $ config = $ this ->getConfig (['allow_delay ' => true ]);
214
+ $ connector = new SqsFifoConnector ();
215
+
216
+ $ queue = $ connector ->connect ($ config );
217
+
218
+ $ this ->assertInstanceOf (SqsFifoQueue::class, $ queue );
219
+ $ this ->assertTrue ($ config ['allow_delay ' ]);
220
+ $ this ->assertEquals ($ config ['allow_delay ' ], $ this ->getRestrictedValue ($ queue , 'allowDelay ' ));
221
+ }
222
+
223
+ protected function getConfig ($ overrides = [], $ except = [])
224
+ {
225
+ return Arr::except (array_merge ([
226
+ 'driver ' => 'sqs-fifo ' ,
227
+ 'key ' => 'ABCDEFGHIJKLMNOPQRST ' ,
228
+ 'secret ' => '1a23bc/deFgHijKl4mNOp5qrS6TUVwXyz7ABCDef ' ,
229
+ 'prefix ' => 'https://sqs.us-east-1.amazonaws.com/123456789012 ' ,
230
+ 'suffix ' => '-staging ' ,
231
+ 'queue ' => 'queuename.fifo ' ,
232
+ 'region ' => 'us-east-1 ' ,
233
+ 'group ' => 'default ' ,
234
+ 'deduplicator ' => 'unique ' ,
235
+ 'allow_delay ' => false ,
236
+ ], $ overrides ), $ except );
237
+ }
30
238
}
0 commit comments