zenstruck / messenger-test

Assertions and helpers for testing your symfony/messenger queues.
MIT License
223 stars 15 forks source link

Add explicitly a message in order to process for fonctional test #13

Closed fpondepeyre closed 3 years ago

fpondepeyre commented 3 years ago

Hello, thank you for your amazing lib. Is there a way to explicitly add a message in a queue in order to process this message ? In my case, an other service push a message in messenger. My main app receive and process the message. I would like to realize a functional test (no access to the first app, no shared rabbitmq in ci). I am no way to populate the queue without special hack for test.

for exemple, i would like to do this with phpunit:

$this->messenger()->queue()->addMessage(new MyMessage('42')); 
$this->messenger()->process();
//check in db|file|other the process was successfully executed

Do you think it's the right way or completely dumby ?

Thank you for your help !

[EDIT]

It's work with

$transport = self::$container->get('messenger.transport.my_message');
$transport->send(new Envelope($new MyMessage(42), [new AmqpStamp("my_message")]));
$this->messenger('my_message')->queue()->assertContains(MyMessage::class, 1);
$this->messenger('my_message')->process();
kbond commented 3 years ago

I was going to suggest what you did in your edit. TestTransport::send() is marked as internal - maybe I should remove that?

fpondepeyre commented 3 years ago

Thank you, but i don't know all about the impact of this change... you are the expert !

kbond commented 3 years ago

No impact really, I just marked everything that I didn't expect to be used by end-users as @internal.

kbond commented 3 years ago

@fpondepeyre, what do you think of #14?