Change BrowserTestBase to flag PHPUnit failures instead of throwing Mink exceptions

Created on 23 March 2022, about 2 years ago
Updated 5 March 2024, 3 months ago

Problem/Motivation

Spin off from #3268932-49: Add methods to assert status messages to WebAssert

From https://phpunit.readthedocs.io/en/9.5/textui.html:

For each test run, the PHPUnit command-line tool prints one character to indicate progress:

. Printed when the test succeeds.

F Printed when an assertion fails while running the test method.

E Printed when an error occurs while running the test method.

and

PHPUnit distinguishes between failures and errors. A failure is a violated PHPUnit assertion such as a failing assertSame() call. An error is an unexpected exception or a PHP error. Sometimes this distinction proves useful since errors tend to be easier to fix than failures. If you have a big list of problems, it is best to tackle the errors first and see if you have any failures left when they are all fixed.

In current Drupal, WebAssert methods, in case of failure, throw a Mink exception which in PHPUnit are reported as errors and not failures. This is a bit confusing when looking at test run reports because the assertion in these cases are actually checking a condition.

Proposed resolution

Catch Mink's ExpectationException in BrowserTestBase and re-throw a PHPUnit AssertionFailedError instead, ensuring the stack trace remains intact as this is critical to debugging test failures.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Closed: duplicate

Version

11.0 🔥

Component
PHPUnit 

Last updated 6 minutes ago

Created by

🇮🇹Italy mondrake 🇮🇹

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024