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.
https://www.drupal.org/node/2880911 was fixed a long time ago but the codebase still has a code related to that issue (but not used anymore)
As that code is not used anywhere (lines 344-353 of KernelTestBase) it can be safely removed.
KernelTestBase used to say this;
+ // Prepare a precompiled container for all tests of this class.
+ // Substantially improves performance, since ContainerBuilder::compile()
+ // is very expensive. Encourages testing best practices (small tests).
+ // Normally a setUpBeforeClass() operation, but object scope is required to
+ // inject $this test class instance as a service provider (see above).
+ $rc = new \ReflectionClass(get_class($this));
+ $test_method_count = count(array_filter($rc->getMethods(), function ($method) {
+ // PHPUnit's @test annotations are intentionally ignored/not supported.
+ return strpos($method->getName(), 'test') === 0;
+ }));
+ if ($test_method_count > 1 && !$this->isTestInIsolation()) {
+ // Clone a precompiled, empty ContainerBuilder instance for each test.
+ $container = $this->getCompiledContainerBuilder($modules);
+ }
But that last if statement is now gone, leaving only the declarations of $rc
and $test_method_count
.
Comment | File | Size | Author |
---|---|---|---|
#2 | kerneltestbase-unused-code-3038825-1.patch | 1.21 KB | undertext |
Comments
Comment #2
undertext CreditAttribution: undertext as a volunteer commentedComment #3
undertext CreditAttribution: undertext as a volunteer commentedComment #4
Mile23Updated IS.
This is clearly unneeded code. My IDE says
$test_method_count
is unused, and I agree.This is a bug because it's wasting resources, and it's a testing bug so it's applicable to be in the 8.6.x queue.
Comment #5
alexpottCommitted and pushed 2c1c25a40d to 8.8.x and 673f5a4496 to 8.7.x. Thanks!
As a test only change backported to 8.7.x - I discussed backporting test-only changes with @catch (as a release manager).
Credited @Mile23 for review and issue management.