Problem/Motivation
PHPUnit 9 deprecated ::expectError*() and ::expectWarning*()methods. They're removed from PHPUnit 10.
Proposed resolution
Issue fork drupal-3427171
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:
- 3427171-10.3
changes, plain diff MR !7005
- 3427171-11.x
changes, plain diff MR !7229
- 3427171-replace-calls-to
changes, plain diff MR !7002
Comments
Comment #3
samitk commentedComment #5
samitk commentedComment #6
mondrakeThanks @samit.310@gmail.com, the approach is interesting, but unfortunately not compatible with PHPUnit 10:
In this set of issues, we need to look at removing the calls to
trigger_error(..., E_USER_WARNING)from the runtime code, which is hard to figure out how - each case will have its own solution.Comment #7
mondrakePlease follow #3427173: Replace calls to :::expectWarning*() in Drupal\Tests\Component\PhpStorage\FileStorageTest for a reference how this could be fixed. I suggest to wait for that to be solved before continuing here.
Comment #9
mondrakeOpened a 10.3 MR to see if we can deprecate the trigger_error without too much hassle.
Comment #10
mondrakeI'm not sure we can throw an exception here in
calculateDependencies(), instead of triggering a warning. It would be an API change given it's not foreseen inDependentPluginInterface, the ramifications of the places where the exception should be caught is too broad.Any suggestions?
Comment #11
longwaveThe warning was first added in #2917006: Views referencing missing roles fail views_post_update_revision_metadata_fields() to solve some issues in the Drupal 8 upgrade path. Maybe we can just remove it again now? Or, we swap it to a watchdog error and/or the messenger service?
Comment #12
smustgrave commentedThanks for taking a look @longwave.
Comment #14
mondrakeIn MR!7229, trying the removal (for D11).
Comment #15
mondrakeJust removing may lead to WSOD, so we need to control if the role is missing and in that case log a warning, but still continue processing (as is right now).
Comment #16
mondrakeComment #19
smustgrave commentedLeft a comment on the MR.
Hid the other 2 for clarity.
Comment #20
longwaveI think this could be an
assert()? It would notify developers but skip at runtime as we can safely ignore it.Comment #21
longwaveHow do I even trigger this warning?
I created a role called "test".
I created a view called "test" and added the role filter to it, filtering for the "test" role.
I then tried to delete the "test" role and in the delete modal I see:
This implies that the view will be deleted if the role is deleted, and the warning won't be triggered.
This was originally added in #2917006: Views referencing missing roles fail views_post_update_revision_metadata_fields(), looks like it only happens in the upgrade path. Not sure what we should do - assert seems like a good option if this mostly useful during updates/development and shouldn't happen at runtime anyway?
Comment #22
longwaveDecided that log-and-continue is probably the best option here. We have some precedent in
EntityDisplayBase::onDependencyRemoval()which logs a warning when a component depends on a disabled dependency. This uses the default logger channel so I followed the same pattern here, and added test coverage.Comment #23
spokje- Approach makes sense, seeing there is precedence.
- Code changes make sense (Personally I find the new logged warning a lot more clear than before).
- Tests are green.
The only thing from RTBC-ing this is the CR link, which needs, at least for me, mentioning the new required
LoggerInterface $logger,inRoles::__contruct().Comment #24
quietone commentedI updated the CR.
Comment #25
spokjeThanks @quietone, good enough for me :)
Comment #26
catchThis looks like it could use a service closure - we'll only actually use the logger if there's a problem.
Comment #27
longwaveFWIW after doing some profiling last week I don't think it's worth the effort of using closures unless they are on the critical path, constructing a logger object is on the order of microseconds, and the dependent services will already exist. I believe closures are only worthwhile when the constructor has to do a large amount of work or requires a database or network call.
Comment #28
alexpottCommitted and pushed d708691285 to 11.x and f7ddabe7bb to 10.3.x. Thanks!
Comment #31
catchI think can be the case if the logger is the only/first thing that requires a database connection. This is possible when redis is installed and most caches are warm.
Comment #32
longwaveIf we are concerned about that I think we should push that decision into DbLog itself, inject the connection as a closure, and only initialise it when we have something to log? Then we don't have to concern ourselves with this every time we need a logger service somewhere.
Or an even bigger change: make connections themselves lazy, so they only try to connect when a query is performed.
Comment #33
catchI think #32 is a good idea, let's open an issue for both of those?
Comment #34
longwaveOpened:
#3441026: Lazily inject the database connection into DbLog
#3441027: Explore whether database connections can be lazily created