Problem/Motivation

PHPUnit 9 deprecated ::expectError*() and ::expectWarning*()methods. They're removed from PHPUnit 10.

Proposed resolution

Replace them as appropriate; requires refactoring of runtime code to remove trigger_error() calls.

Individual issue per instance is required.

CommentFileSizeAuthor
#7 3417650-nr-bot.txt90 bytesneeds-review-queue-bot

Issue fork drupal-3417650

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Issue summary: View changes
mondrake’s picture

Status: Active » Needs review
mondrake’s picture

Issue summary: View changes
andypost’s picture

Looks nice, moreover in context of PHP 8.3 and assert requirements in php.ini

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mondrake’s picture

Status: Needs work » Needs review

Dizzy bot? The MR is mergeable.

spokje’s picture

Issue tags: +no-needs-review-bot

Tagged with no-needs-review-bot to tell bot to f.....ind something else to do.

EDIT: I think the bot is a bit less clever in merging the baseline file than GitLab is.

gábor hojtsy’s picture

Issue tags: -PHPUnit 11
smustgrave’s picture

Change looks fine, clearly didn't break anything. But not sure a good way to search for others. Any suggestions?

mondrake’s picture

#11 what we need here is to stop using TestCase::expectError*() methods. If you don’t find others, it should be ok.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Searching for expectError and all instances are replaced.

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Added some review questions. These are all kind of awkward places where we don't have a logger available and can't necessarily throw an exception, but something bad has happened and we should be able to inform the site owner.

mondrake’s picture

Status: Needs work » Needs review

Yeah the problem in some of the cases here is notifying ‘somehow’ that an error occurred. So I think we have the following options:

1. We keep throwing user errors, and we abide to PHPUnit 10 vision that is no longer going to test on such errors by expecting them. We do not implement a gap fill to expect errors. Therefore we drop any test that expects an error.
2. We keep throwing user errors, and we fill the gap vs PHPUnit 10 using our own error handler to test error expectations. We keep the tests as they are now. This is currently done in #3417066: Upgrade PHPUnit to 10, drop Symfony PHPUnit-bridge dependency.
3. We stop throwing user errors, and again abide to PHPUnit 10. We replace the user error, where we expect the user to be informed, with a log call like \Drupal::service(‘logger something’)->error(‘whatever’). Assuming the container is available.
4. ?

Each of the cases here will probably need to have its own solution.

Thoughts?

smustgrave’s picture

Status: Needs review » Needs work

Appears to have a unit test failure.

Also needs a rebase.

mondrake’s picture

Status: Needs work » Needs review

#16 yes, but I’d be more interested on reviews and input on #15 ATM.

mondrake’s picture

IMHO, I would prefer NOT to reimplement expectError*() methods.

Between the lines, I read PHPUnit 10 approach as one where using trigger_error in SUT code is no longer seen as a good practice. We might debate whether this is right or not, but that’s OOS here.

So what is the practical effect of the PHPUnit 10 change is that triggering E_USER_ERROR in SUT is not expectable in test and therefore FAILS the test itself. In other words, triggering an error should not be in any covered code path. That’s a bold assumption, with its own meaning i.e. that you should develop code where triggering errors is really exceptional. If we backfill the expectation we’re swallowing the assumption.

Possibly we could take a different stance for expectWarning* but that’s for another issue.

longwave’s picture

I guess we have to ask who is the error intended for, and how should we be notifying these users.

We already have multiple ways of notifying different types of users: the messenger service (if the error is intended for UI), the logger services (if the error is intended for a site administrator), and exceptions (if the error is intended for a developer or another piece of code).

We also have assertions which are usually used when we would have an exception for a developer but at runtime we should carry on.

But what is the intended audience for trigger_error errors and warnings? Are these really yet another category on top of the ones listed above, or should we migrate these to one of those types?

I think PHPUnit's stance is that exceptions are catchable and therefore testable; errors are more low level than that and therefore out of scope.

longwave’s picture

Maybe we need another meta like the withConsecutive one to take each case and decide how to refactor it?

mondrake’s picture

#20 fine, but IMHO we need first to establish whether we will have expectError*() methods as our own stuff, or not. I am for NO.

spokje’s picture

#20 fine, but IMHO we need first to establish whether we will have expectError*() methods as our own stuff, or not. I am for NO.

Isn't @longwave in #19 with

But what is the intended audience for trigger_error errors and warnings? Are these really yet another category on top of the ones listed above, or should we migrate these to one of those types?

kinda implying the same?

At least that's the way I read it.

FWIW: I'm on #TeamNo on shimming expectError*().

mondrake’s picture

Title: Replace calls to ::expectError*(), if possible » [PP-2] Replace calls to ::expectError*(), if possible
Status: Needs review » Postponed

OK, not sure about a meta, for the moment I created two spin-offs, #3419690: Find an alternative to trigger_error in Drupal\Core\Database\Query\Condition::compile and #3419693: Log error instead of trigger_error in Drupal\Core\EventSubscriber\RedirectResponseSubscriber::checkRedirectUrl, that are tackling a couple of cases that were reverted from the MR here.

I think we still need this MR to fix the clear bugs (for example, Statement objects trigger E_USER_WARNING but the test expects errors), and to cleanup the deprecation and warning ignores.

longwave’s picture

Similar to the conclusion of withConsecutive() I also lean towards "no", but let's also summon the framework managers to see if they have opinions on the use of trigger_error().

mondrake’s picture

#24 thanks. For completeness: let's differentiate between triggering E_USER_ERROR and triggering E_USER_WARNING, though. PHPUnit 10 drops expect* methods for both. I'm on a NO to reintroduce expectError*() methods as our own implementation; more open to keep expectWarning*()methods.

See #3417066: Upgrade PHPUnit to 10, drop Symfony PHPUnit-bridge dependency for the current status of reimplementing deprecation, warning and error expectations, that were dropped in PHPUnit 10 or for which Symfony's PHPUnit-bridge has not come up with a solution yet. Decisions here will impact how much fill-gap code we will have to write and maintain.

mondrake’s picture

Title: [PP-2] Replace calls to ::expectError*(), if possible » [meta] Replace calls to ::expectError*() and ::expectWarning*()
Issue summary: View changes

Adjusted IS with latest direction discussed in Slack.

mondrake changed the visibility of the branch 3417650-replace-calls-to to hidden.

mondrake’s picture

mondrake’s picture

Status: Postponed » Active
catch’s picture

Status: Active » Fixed

All of the sub-issues are done here, and it's noted in the change record. Unfortunately not one way to fix this since it has mostly meant refactoring code.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.