zenstruck / messenger-test

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

Send with json data type #49

Closed amanformuli closed 1 year ago

amanformuli commented 1 year ago

Hi All,

First of all I appreciate your work. Secondly, is it possible to add a separate public method(in Zenstruck\Messenger\Test\Transport\TestTransport) to send with deserialized data so that a JSON data type is passed as parameter? { 'headers' => [ 'type' => 'Class' ], 'body' => '{"serialized":"data}' }

Thanks

kbond commented 1 year ago

Hey @amanformuli!

First of all I appreciate your work.

Thank you :)

Secondly, is it possible to add a separate public method...

I guess you mean something like ->sendSerialized(string $data) and the transport decodes this $data before actually calling ->send()?

amanformuli commented 1 year ago

Hi Kevin,

Indeed I asked for such method with only one thing: is it possible to keep the $data type as an array so that both the headers and body of the message is passed. If the send method does not do anything with the headers, then string $data would be fine.

Thanks

kbond commented 1 year ago

is it possible to keep the $data type as an array

I will need to use the transport's configured serializer to decode the message - this does indeed require an array (I thought it was a string) so yes, sendSerialized() should be able to take an array.

kbond commented 1 year ago

BTW, can you describe your use case for this? I don't think it's invalid, I'd like to describe why you'd do this in the docs for this feature.

amanformuli commented 1 year ago

Actually I am using symfony serializer(configured to my symfony messenger) and wanted to test the message with json format instead of Object class.

kbond commented 1 year ago

Got it, would it be valuable to for TestTransport::send() to accept a json string in addition to a decoded json array?

amanformuli commented 1 year ago

Yeah that is also fine to accept a json string.