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

Sent emails should be persisted between kernel reboots #5

Closed
kbond opened this issue Aug 11, 2021 · 1 comment · Fixed by #9
Closed

Sent emails should be persisted between kernel reboots #5

kbond opened this issue Aug 11, 2021 · 1 comment · Fixed by #9
Labels
bug Something isn't working enhancement New feature or request

Comments

@kbond
Copy link
Member

kbond commented Aug 11, 2021

The following doesn't currently work:

// ...some code that sends 2 emails...
// reboot kernel
$this->mailer()->assertSentEmailCount(2);

It needs to be modified to the following to work:

// ...some code that sends 2 emails...
$this->mailer()->assertSentEmailCount(2);
// reboot kernel

I believe the only way to achieve this is to add a lightweight bundle that registers a listener for MessageEvent and stores them statically (and resets them after the test). This would be similar to how zenstruck/messenger-test works.

This will also remove the requirement for the profiler to be enabled on some versions of Symfony:

/**
* @test
*/
public function profiler_must_be_enabled_after_5_2(): void
{
if (Kernel::VERSION_ID < 50200) {
// profile needs to be enabled in 5.2+
$this->markTestSkipped();
}
self::bootKernel(['environment' => 'no_profiler']);
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Mailer and/or profiling not enabled');
$this->mailer();
}
/**
* @test
*/
public function profiler_does_not_need_to_enabled_prior_to_5_2(): void
{
if (Kernel::VERSION_ID >= 50200) {
// profile does not need to be enabled in <5.2
$this->markTestSkipped();
}
self::bootKernel(['environment' => 'no_profiler']);
self::$container->get('mailer')->send(new Email1());
$this->mailer()->assertSentEmailCount(1);
}

@kbond kbond added bug Something isn't working enhancement New feature or request labels Aug 11, 2021
@OskarStark
Copy link
Contributor

cc @silasjoisten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

2 participants