1212use Interop \Queue \PsrContext ;
1313use Interop \Queue \PsrMessage ;
1414use Interop \Queue \PsrQueue ;
15+ use Interop \Queue \PurgeQueueNotSupportedException ;
1516use Symfony \Component \Console \Tester \CommandTester ;
1617use Symfony \Component \Filesystem \Filesystem ;
1718use Symfony \Component \HttpKernel \Kernel ;
@@ -76,7 +77,7 @@ public function provideEnqueueConfigs()
7677
7778 yield 'rabbitmq_stomp ' => [[
7879 'transport ' => [
79- 'dsn ' => getenv ('STOMP_DSN ' ),
80+ 'dsn ' => getenv ('RABITMQ_STOMP_DSN ' ),
8081 'lazy ' => false ,
8182 'management_plugin_installed ' => true ,
8283 ],
@@ -113,17 +114,18 @@ public function provideEnqueueConfigs()
113114 yield 'sqs_client ' => [[
114115 'transport ' => [
115116 'dsn ' => 'sqs: ' ,
116- 'client ' => 'test.sqs_client ' ,
117+ 'service ' => 'test.sqs_client ' ,
118+ 'factory_service ' => 'test.sqs_custom_connection_factory_factory ' ,
117119 ],
118120 ]];
119121
120122 yield 'mongodb_dsn ' => [[
121123 'transport ' => getenv ('MONGO_DSN ' ),
122124 ]];
123125
124- yield 'gps ' => [[
125- 'transport ' => ' gps: ' ,
126- ]];
126+ // yield 'gps' => [[
127+ // 'transport' => getenv('GPS_DSN') ,
128+ // ]];
127129 }
128130
129131 /**
@@ -139,117 +141,117 @@ public function testProducerSendsMessage(array $enqueueConfig)
139141
140142 $ consumer = $ this ->getPsrContext ()->createConsumer ($ this ->getTestQueue ());
141143
144+ $ message = $ consumer ->receive (1000 );
145+ $ this ->assertInstanceOf (PsrMessage::class, $ message );
146+ $ consumer ->acknowledge ($ message );
147+
148+ $ this ->assertSame ($ expectedBody , $ message ->getBody ());
149+ }
150+
151+ /**
152+ * @dataProvider provideEnqueueConfigs
153+ */
154+ public function testProducerSendsCommandMessage (array $ enqueueConfig )
155+ {
156+ $ this ->customSetUp ($ enqueueConfig );
157+
158+ $ expectedBody = __METHOD__ .time ();
159+
160+ $ this ->getMessageProducer ()->sendCommand (TestCommandProcessor::COMMAND , $ expectedBody );
161+
162+ $ consumer = $ this ->getPsrContext ()->createConsumer ($ this ->getTestQueue ());
163+
142164 $ message = $ consumer ->receive (100 );
143165 $ this ->assertInstanceOf (PsrMessage::class, $ message );
144166 $ consumer ->acknowledge ($ message );
145167
168+ $ this ->assertInstanceOf (PsrMessage::class, $ message );
146169 $ this ->assertSame ($ expectedBody , $ message ->getBody ());
147170 }
148171
149- // /**
150- // * @dataProvider provideEnqueueConfigs
151- // */
152- // public function testProducerSendsCommandMessage(array $enqueueConfig)
153- // {
154- // $this->customSetUp($enqueueConfig);
155- //
156- // $expectedBody = __METHOD__.time();
157- //
158- // $this->getMessageProducer()->sendCommand(TestCommandProcessor::COMMAND, $expectedBody);
159- //
160- // $consumer = $this->getPsrContext()->createConsumer($this->getTestQueue());
161- //
162- // $message = $consumer->receive(100);
163- // $this->assertInstanceOf(PsrMessage::class, $message);
164- // $consumer->acknowledge($message);
165- //
166- // $this->assertInstanceOf(PsrMessage::class, $message);
167- // $this->assertSame($expectedBody, $message->getBody());
168- // }
169- //
170- // /**
171- // * @dataProvider provideEnqueueConfigs
172- // */
173- // public function testClientConsumeCommandMessagesFromExplicitlySetQueue(array $enqueueConfig)
174- // {
175- // $this->customSetUp($enqueueConfig);
176- //
177- // $command = static::$container->get(ConsumeMessagesCommand::class);
178- // $processor = static::$container->get('test.message.command_processor');
179- //
180- // $expectedBody = __METHOD__.time();
181- //
182- // $this->getMessageProducer()->sendCommand(TestCommandProcessor::COMMAND, $expectedBody);
183- //
184- // $tester = new CommandTester($command);
185- // $tester->execute([
186- // '--message-limit' => 2,
187- // '--time-limit' => 'now +10 seconds',
188- // 'client-queue-names' => ['test'],
189- // ]);
190- //
191- // $this->assertInstanceOf(PsrMessage::class, $processor->message);
192- // $this->assertEquals($expectedBody, $processor->message->getBody());
193- // }
194- //
195- // /**
196- // * @dataProvider provideEnqueueConfigs
197- // */
198- // public function testClientConsumeMessagesFromExplicitlySetQueue(array $enqueueConfig)
199- // {
200- // $this->customSetUp($enqueueConfig);
201- //
202- // $expectedBody = __METHOD__.time();
203- //
204- // $command = static::$container->get(ConsumeMessagesCommand::class);
205- // $processor = static::$container->get('test.message.processor');
206- //
207- // $this->getMessageProducer()->sendEvent(TestProcessor::TOPIC, $expectedBody);
208- //
209- // $tester = new CommandTester($command);
210- // $tester->execute([
211- // '--message-limit' => 2,
212- // '--time-limit' => 'now +10 seconds',
213- // 'client-queue-names' => ['test'],
214- // ]);
215- //
216- // $this->assertInstanceOf(PsrMessage::class, $processor->message);
217- // $this->assertEquals($expectedBody, $processor->message->getBody());
218- // }
219- //
220- // /**
221- // * @dataProvider provideEnqueueConfigs
222- // */
223- // public function testTransportConsumeMessagesCommandShouldConsumeMessage(array $enqueueConfig)
224- // {
225- // $this->customSetUp($enqueueConfig);
226- //
227- // if ($this->getTestQueue() instanceof StompDestination) {
228- // $this->markTestSkipped('The test fails with the exception Stomp\Exception\ErrorFrameException: Error "precondition_failed". '.
229- // 'It happens because of the destination options are different from the one used while creating the dest. Nothing to do about it'
230- // );
231- // }
232- //
233- // $expectedBody = __METHOD__.time();
234- //
235- // $command = static::$container->get(ContainerAwareConsumeMessagesCommand::class);
236- // $command->setContainer(static::$container);
237- // $processor = static::$container->get('test.message.processor');
238- //
239- // $this->getMessageProducer()->sendEvent(TestProcessor::TOPIC, $expectedBody);
240- //
241- // $tester = new CommandTester($command);
242- // $tester->execute([
243- // '--message-limit' => 1,
244- // '--time-limit' => '+10sec',
245- // '--receive-timeout' => 1000,
246- // '--queue' => [$this->getTestQueue()->getQueueName()],
247- // 'processor-service' => 'test.message.processor',
248- // ]);
249- //
250- // $this->assertInstanceOf(PsrMessage::class, $processor->message);
251- // $this->assertEquals($expectedBody, $processor->message->getBody());
252- // }
172+ /**
173+ * @dataProvider provideEnqueueConfigs
174+ */
175+ public function testClientConsumeCommandMessagesFromExplicitlySetQueue (array $ enqueueConfig )
176+ {
177+ $ this ->customSetUp ($ enqueueConfig );
178+
179+ $ command = static ::$ container ->get (ConsumeMessagesCommand::class);
180+ $ processor = static ::$ container ->get ('test.message.command_processor ' );
181+
182+ $ expectedBody = __METHOD__ .time ();
183+
184+ $ this ->getMessageProducer ()->sendCommand (TestCommandProcessor::COMMAND , $ expectedBody );
185+
186+ $ tester = new CommandTester ($ command );
187+ $ tester ->execute ([
188+ '--message-limit ' => 2 ,
189+ '--time-limit ' => 'now +10 seconds ' ,
190+ 'client-queue-names ' => ['test ' ],
191+ ]);
192+
193+ $ this ->assertInstanceOf (PsrMessage::class, $ processor ->message );
194+ $ this ->assertEquals ($ expectedBody , $ processor ->message ->getBody ());
195+ }
196+
197+ /**
198+ * @dataProvider provideEnqueueConfigs
199+ */
200+ public function testClientConsumeMessagesFromExplicitlySetQueue (array $ enqueueConfig )
201+ {
202+ $ this ->customSetUp ($ enqueueConfig );
203+
204+ $ expectedBody = __METHOD__ .time ();
205+
206+ $ command = static ::$ container ->get (ConsumeMessagesCommand::class);
207+ $ processor = static ::$ container ->get ('test.message.processor ' );
208+
209+ $ this ->getMessageProducer ()->sendEvent (TestProcessor::TOPIC , $ expectedBody );
210+
211+ $ tester = new CommandTester ($ command );
212+ $ tester ->execute ([
213+ '--message-limit ' => 2 ,
214+ '--time-limit ' => 'now +10 seconds ' ,
215+ 'client-queue-names ' => ['test ' ],
216+ ]);
217+
218+ $ this ->assertInstanceOf (PsrMessage::class, $ processor ->message );
219+ $ this ->assertEquals ($ expectedBody , $ processor ->message ->getBody ());
220+ }
221+
222+ /**
223+ * @dataProvider provideEnqueueConfigs
224+ */
225+ public function testTransportConsumeMessagesCommandShouldConsumeMessage (array $ enqueueConfig )
226+ {
227+ $ this ->customSetUp ($ enqueueConfig );
228+
229+ if ($ this ->getTestQueue () instanceof StompDestination) {
230+ $ this ->markTestSkipped ('The test fails with the exception Stomp\Exception\ErrorFrameException: Error "precondition_failed". ' .
231+ 'It happens because of the destination options are different from the one used while creating the dest. Nothing to do about it '
232+ );
233+ }
234+
235+ $ expectedBody = __METHOD__ .time ();
236+
237+ $ command = static ::$ container ->get (ContainerAwareConsumeMessagesCommand::class);
238+ $ command ->setContainer (static ::$ container );
239+ $ processor = static ::$ container ->get ('test.message.processor ' );
240+
241+ $ this ->getMessageProducer ()->sendEvent (TestProcessor::TOPIC , $ expectedBody );
242+
243+ $ tester = new CommandTester ($ command );
244+ $ tester ->execute ([
245+ '--message-limit ' => 1 ,
246+ '--time-limit ' => '+10sec ' ,
247+ '--receive-timeout ' => 1000 ,
248+ '--queue ' => [$ this ->getTestQueue ()->getQueueName ()],
249+ 'processor-service ' => 'test.message.processor ' ,
250+ ]);
251+
252+ $ this ->assertInstanceOf (PsrMessage::class, $ processor ->message );
253+ $ this ->assertEquals ($ expectedBody , $ processor ->message ->getBody ());
254+ }
253255
254256 /**
255257 * @return string
@@ -278,7 +280,7 @@ protected function customSetUp(array $enqueueConfig)
278280
279281 try {
280282 $ context ->purgeQueue ($ this ->getTestQueue ());
281- } catch (\ Exception $ e ) {
283+ } catch (PurgeQueueNotSupportedException $ e ) {
282284 }
283285 }
284286
0 commit comments