- Issue created by @donquixote
- 🇩🇪Germany donquixote
Actually...
this is not a ::__destruct() method, but a ::destruct(), which is called from $kernel->terminate().We see this in index.php:
$response->send(); $kernel->terminate($request, $response);
So this explains the order :)
- 🇩🇪Germany donquixote
Also, the current solution with using state assumes that all emails are sent during a single request.
If there are multiple requests that happen before the test can collect the emails, e.g. as a batch process, and each of them is sending emails, then there will be a problem in the __construct() which expects the state collected mails to be empty.A database table with one row per mail and auto increment would solve this.
There can be a counter in the test trait that contains the last read auto increment id.
In the ::setUp() method the table can be truncated, and the auto increment reset, OR the internal counter variable/property can be set to the current auto increment counter from the db.We also want this to work with ExistingSite tests, where we cannot rely on the module being freshly installed each time.
- Merge request !95Issue #3463648: Save emails to state immediately, instead of on destruct(). → (Merged) created by donquixote
- Merge request !96Draft: DO NOT MERGE: Resolve #463648 "Fail mailertestservice destruct too late" → (Open) created by donquixote
- 🇩🇪Germany donquixote
This is interesting.
The "FAIL" merge request does not actually fail the phpunit test.
But in my local env (with ddev) I do get test failures, even without the usleep().One thing I suspect is that usleep()/sleep() does not really work in the pipeline.
- 🇩🇪Germany donquixote
In my local I get these failures with the FAIL branch:
Time: 00:37.938, Memory: 4.00 MB There were 4 failures: 1) Drupal\Tests\symfony_mailer\Functional\LegacyEmailTest::testSendLegacyEmail Failed asserting that null is not null. /var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122 /var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:56 /var/www/html/tests/modules/symfony_mailer_test/src/MailerTestTrait.php:46 /var/www/html/tests/src/Functional/LegacyEmailTest.php:43 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:729 2) Drupal\Tests\symfony_mailer\Functional\LegacyEmailTest::testSendLegacyEmailWithTheme Failed asserting that null is not null. /var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122 /var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:56 /var/www/html/tests/modules/symfony_mailer_test/src/MailerTestTrait.php:46 /var/www/html/tests/src/Functional/LegacyEmailTest.php:81 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:729 3) Drupal\Tests\symfony_mailer\Functional\OverrideTest::testUpdate Failed asserting that null is not null. /var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122 /var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:56 /var/www/html/tests/modules/symfony_mailer_test/src/MailerTestTrait.php:46 /var/www/html/tests/src/Functional/OverrideTest.php:127 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:729 4) Drupal\Tests\symfony_mailer\Functional\TestEmailTest::testTest Failed asserting that null is not null. /var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122 /var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:56 /var/www/html/tests/modules/symfony_mailer_test/src/MailerTestTrait.php:46 /var/www/html/tests/src/Functional/TestEmailTest.php:27 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:729 FAILURES! Tests: 26, Assertions: 274, Failures: 4.
With the 1.x branch I get 1 failure:
Time: 00:47.724, Memory: 4.00 MB There was 1 failure: 1) Drupal\Tests\symfony_mailer\Functional\OverrideTest::testUpdate Failed asserting that null is not null. /var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122 /var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:56 /var/www/html/tests/modules/symfony_mailer_test/src/MailerTestTrait.php:46 /var/www/html/tests/src/Functional/OverrideTest.php:127 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:729 FAILURES! Tests: 26, Assertions: 312, Failures: 1.
With the fix branch, all tests pass.
- First commit to issue fork.
-
AdamPS →
committed babf7894 on 1.x authored by
donquixote →
Issue #3463648 by donquixote: Handling emails in MailerTestService::...
-
AdamPS →
committed babf7894 on 1.x authored by
donquixote →
- Status changed to Fixed
23 days ago 4:00pm 15 August 2024 - 🇬🇧United Kingdom AdamPS
Thanks.
I believe the current code was written for efficiency with a test that sent 1000s of emails. I guess the new code would be slower in that case?? But core TestMailCollector also rewrites the state for every mail, so it probably doesn't matter much.
Please can you raise a follow on issue for the other problems you spotted?
Automatically closed - issue fixed for 2 weeks with no activity.