Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Follow up for #2848914: Move DbLogTest::generateLogEntries() into a Trait
From #9.2
+++ b/core/modules/dblog/tests/src/Functional/FakeLogEntries.php
@@ -0,0 +1,57 @@
+ $logger = $this->container->get('logger.dblog');
This assumes the ->container object will be present. This can make harder to re-use the trait. I think would be better to use Drupal::service instead.
From #19.4
+++ b/core/modules/dblog/tests/src/Functional/FakeLogEntries.php
@@ -0,0 +1,63 @@
+ 'user' => $this->adminUser,
+ 'uid' => $this->adminUser->id(),
I think could be safe to check if $this->adminUser
is defined before try to use is. Maybe using a ternary operator and fallback to an anonymous user if empty.
Comment | File | Size | Author |
---|---|---|---|
#9 | 2985701-9.patch | 1.27 KB | longwave |
Comments
Comment #2
dagmarComment #3
dagmarComment #5
dagmar#2848914: Move DbLogTest::generateLogEntries() into a Trait was committed. This issue is unblocked now.
Comment #6
longwave#2848529: Move DbLogTest::verifyCron to a kernel test will suffer from the missing adminUser issue.
This patch makes both the requested changes.
Comment #7
dagmarThanks @longwave. Patch looks good.
Comment #8
catchUnder what circumstances would $this->container not be present in a test class using this trait?
The admin user change looks fine though.
Comment #9
longwaveGood point, I don't see when it wouldn't be available, and we can always revisit if it turns out to be a problem. Attached patch removes this change and also fixes a whitespace issue in the original patch.
Incidentally, do we have or need any way of documenting trait dependencies like this? I guess it should be obvious in most cases when you try to use them?
Comment #10
dagmarThanks again @longwave
Yes. Sorry, I checked the KernelTestBase class and the
container
is defined there. I didn't realized this when I created the issue.Comment #12
catchCommitted/pushed to 8.7.x and cherry-picked to 8.6.x. Thanks!