-
Notifications
You must be signed in to change notification settings - Fork 34
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
Symfony upgrade 5.4 -> 6.4 brokes my tests #152
Comments
Howdy @badmansan! sorry for the late reply to this. I'm working on the ability to generate tests over in maker-bundle for class RegistrationFormTest extends WebTestCase
{
public function testRegister(): void
{
$client = static::createClient();
$container = static::getContainer();
$em = $container->get('doctrine.orm.entity_manager');
$userRepository = $container->get(UserRepository::class);
foreach ($userRepository->findAll() as $user) {
$em->remove($user);
}
$em->flush();
self::assertCount(0, $userRepository->findAll());
$client->request('GET', '/register');
self::assertResponseIsSuccessful();
$client->submitForm('Register', [
'registration_form[email]' => '[email protected]',
'registration_form[plainPassword]' => 'password',
'registration_form[agreeTerms]' => true,
]);
self::assertResponseRedirects('/');
self::assertCount(1, $userRepository->findAll());
self::assertFalse(($user = $userRepository->findAll()[0])->isVerified());
// Use either assertQueuedEmailCount() || assertEmailCount() depending on your mailer setup
self::assertQueuedEmailCount(1);
// self::assertEmailCount(1);
self::assertCount(1, $messages = $this->getMailerMessages());
self::assertEmailTextBodyContains($messages[0], 'This link will expire in 1 hour.');
$client->followRedirect();
$client->loginUser($user);
/** @var TemplatedEmail $templatedEmail */
$templatedEmail = $messages[0];
$messageBody = $templatedEmail->getHtmlBody();
preg_match('#(http://localhost/verify/email.+)">#', $messageBody, $resetLink);
$client->request('GET', $resetLink[1]);
$client->followRedirect();
self::assertTrue(static::getContainer()->get(UserRepository::class)->findAll()[0]->isVerified());
}
} Let me know if you this helps! |
Closing as no further feedback from the author. If you still have this issue - please, feel free to reopen it again with more details |
I have some functional tests that check the registration process with email confirmation. It looks like this:
In test
signedUrl
is confirmation link that I generate from service during registration process:In symfony 5.4 this test works fine. But at 6.4 it brakes because of empty
$email->getContext()
. In the same time the body of email is ok, with correct link and all things works actually.The problem is how email is rendered in later symfony. In 6.4 context erases after render. Here is BodyRenderer.php (6.4) and here BodyRenderer.php from 5.4. As you can see in 6.4
$message->markAsRendered()
calls wherecontext
erases:Now I'm confused. What test should be written for such a check? Ok, I can parse raw html email body with regex. But how can I check that this link is the same I generated before in service?
The text was updated successfully, but these errors were encountered: