zenstruck / messenger-test

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

Ignore receiver when detached from transport #51

Closed alli83 closed 1 year ago

alli83 commented 1 year ago

Hello,

First of all, this library is super cool . Lately, I have encountered a small problem that prevented me from using it. In case there are transports (single or multiple) but also classes implementing ReceiverInterface without being attached to a transport, the registration of "the transport" is prevented because it implements receiverInterface but not transportInterface.

For example:

if I have in config:

    Zenstruck\Messenger\Test\Tests\Fixture\Messenger\Receiver\RandomReceiver:
        tags:
            - { name: messenger.receiver }

I tried with this test case and i received this type of error

self::bootKernel(['environment' => 'with_receiver']);
    $this->expectException(\TypeError::class);
    $this->expectExceptionMessage('Zenstruck\Messenger\Test\Transport\TestTransportRegistry::register(): Argument #2 ($transport) must be of type Symfony\Component\Messenger\Transport\TransportInterface');
$this->messenger();

In the compiler pass, the check is based on $container->findTaggedServiceIds('messenger.receiver') but it does not distinguish if it's a class that just implements ReceiverInterface or TransportInterface and then, the method call "register" of TestTransportRegistry expects a TransportInterface.

If it's possible, I would like to suggest a fix. #52

Thanks again for this library!