Skip to content

Draft: Copy errors from the SUT to the phpunit runner process

Moshe Weitzman requested to merge logger-drupal-to-headers into master

Adds an error handler which is conditionally set in the Drupal Site Under Test (SUT). This error handler works just like Drupal's _drupal_error_handler_real() but it unconditionally copies errors into http headers so that phpunit may learn about them.

The phpunit process reads the http errors and creates Exceptions out of them, just like https://github.com/drupal/drupal/blob/9.0.x/core/lib/Drupal/Core/Test/HttpClientMiddleware/TestHttpClientMiddleware.php. IMO it would make more sense to trigger local errors (Notices, Warnings, etc.) and then phpunit's configuration (convertNoticesToExceptions, convertWarningsToExceptions), determines if they merit a failure. But for now they are Exceptions, just like Drupal.

This PR copies Drupal code. It would be more DRY to reuse core code but DrupalKernel's setting of the DRUPAL_TEST_IN_CHILD_SITE=FALSE constant and checks for drupal_valid_test_ua() make that impossible. A core patch could help the situation, but I'm not able to push that through.

Edited by Moshe Weitzman

Merge request reports