Exceptions ignored in errorHandler for DrupalTestCase

Created on 11 October 2023, about 1 year ago
Updated 5 December 2023, about 1 year ago

Problem/Motivation

If the test suite is run in versions of PHP 7 or above, there are some situations where exceptions happen, but they are not caught by the custom error handler set in DrupalTestCase and the exit code is 0 (success), even with clear errors.

This leads to false positives in tests.

Steps to reproduce

See successful run with clear errors: https://git.drupalcode.org/issue/scheduler-3387331/-/jobs/159694
- See the "*** Status: 0" which is debug added to the script.
- We can also see HTML thrown into the error output and the test summary full of fails and exceptions, yet the status code is still 0

To force this error, you just need to call $this->drupalLogin(FALSE);

Proposed resolution

Newer versions of PHP throw other type of errors, not just "Exception", but they are all "Throwable", so try to catch that and then default into "Exception".

          try {
            $this->$method();
            // Finish up.
          }
          catch (Throwable $e) {
            // PHP7+ versions
            $this->exceptionHandler($e);
          }
          catch (Exception $e) {
            // PHP5.6 version
            $this->exceptionHandler($e);
          }

Suggested here: https://www.php.net/manual/en/class.throwable.php#124604

We can see that if the suggestion above is put in place, the exception is now caught and the exit code and results are as excepted. See here: https://git.drupalcode.org/issue/scheduler-3387331/-/jobs/159786

Remaining tasks

MR

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

7.0 ⚰️

Component
PHPUnit 

Last updated about 6 hours ago

Created by

🇪🇸Spain fjgarlin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024