Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mailer] Ability to identify transport by name instead of transport as string #54394

Open
clement-michelet opened this issue Mar 25, 2024 · 0 comments

Comments

@clement-michelet
Copy link

clement-michelet commented Mar 25, 2024

Description

As a developer
I want to be able to identify the transport by the transport key/name used to send an email in my test
In order to ensure the mail was sent with the selected transport

Example

Given the following mailer configuration with multiple transports:

framework:
    mailer:
        transports:
            sendmail: '%env(MAILER_SENDMAIL_DSN)%'
            brevo: '%env(MAILER_BREVO_DSN)%'
            other_brevo: '%env(MAILER_OTHER_BREVO_DSN)%'

when@prod:
  parameters:
    env(MAILER_SENDMAIL_DSN): 'sendmail://default'
    env(MAILER_BREVO_DSN): 'brevo+api://KEY@default'
    env(MAILER_OTHER_BREVO_DSN): 'brevo+api://OTHER_KEY@default'

when@test:
  parameters:
    env(MAILER_SENDMAIL_DSN): 'null://null'
    env(MAILER_BREVO_DSN): 'null://null'
    env(MAILER_OTHER_BREVO_DSN): 'null://null'

I have some code that will set the header X-Transport with the target transport to use :

$email = new Email();
$email->getHeaders()
    ->addTextHeader('X-Transport', 'brevo')
;

// [...] Set from/to/subject/body/...

$mailer->send($email);

As of now, I cannot write a functional test to test that the expected transport is used. The transport is not identified by the declared transport key (i.e sendmail, brevo, other_brevo) but instead the transport in events is the transport casted as a string.

self::assertEmailCount(1, 'brevo'); // fails
self::assertEmailCount(1, 'null://'); // pass but is it brevo or sendmail  or other_brevo as both use null transport in test env ?
self::assertEmailCount(1, 'brevo+api://api.brevo.com'); // pass if I use brevo transport but it will call the API and I don't know if it's brevo or other_brevo

As X-Transport is removed from the message, I cannot assert on the header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants