Skip to content

Error sending message to new transport from an EntityListener #81

@mbopp

Description

@mbopp

I'm using API Platform. I have many transports and many tests that work great. But after adding a new transport and implementing a test I am getting an error:

 TypeError: Zenstruck\Messenger\Test\Transport\TestTransport::isIntercepting(): Return value must be of type bool, null returned

Which seems to indicate that the new transport isn't found. Here are some of the details that cause this error ('hubspot_transport' is the name of the one that fails)

messenger.yaml

framework:
    messenger:
        reset_on_message: true
        default_bus: event.bus
        buses:
            event.bus:
                default_middleware: allow_no_handlers
                middleware:
                    - App\Messenger\AuditMiddleware

        failure_transport: failed

        transports:
            async_transport:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
            hubspot_transport:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                retry_strategy:
                    max_retries: 1
            failed: 'doctrine://default?queue_name=failed'

        routing:
            'App\Message\ActivityMessage': async_transport
            'App\Message\HubspotUpdateMessage': hubspot_transport

when@test:
    framework:
        messenger:
            transports:
              async_transport: 'test://'
              hubspot_transport: 'test://'


when@dev:
    framework:
        messenger:
            transports:
              async_transport: '%env(MESSENGER_TRANSPORT_DSN)%'
              hubspot_transport: '%env(MESSENGER_TRANSPORT_DSN)%'

relevant test code:

    $client = self::createClient();

    $messenger = $this->transport('hubspot_transport');

    // Error ONLY occurs when this statement exists.
    $messenger->resetAll(); 

    // This request produces error 
    $client->request('POST', '/api/authentication/token', [
      'headers' => ['Content-Type' => 'application/json'],
      'json' => [
        'username' => $username,
        'password' => $password,
      ],
    ]);

The login request alters a field on the user entity...

In my entity listener:

#[AsEntityListener(event: Events::preUpdate, method: 'preUpdate', entity: User::class)]
class UserListener
{
  public function __construct(
    private readonly MessageBusInterface $messageBus,
  ) {
  }

  public function preUpdate(User $user, PreUpdateEventArgs $event): void
  {
    $hubspotMessage = new HubspotUpdateMessage(HubspotUpdateType::CONTACT, $user->getId(), ['updating user']);
    $this->messageBus->dispatch($hubspotMessage); // <<< Error
  }
...
}

Please let me know if there is more info I can provide to help put a finger on what is happening here. Thank you so much for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions