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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

undertext created an issue. See original summary.

undertext’s picture

undertext’s picture

Status: Active » Needs review
Mile23’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Updated 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.

alexpott’s picture

Version: 8.6.x-dev » 8.7.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 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.

  • alexpott committed 2c1c25a on 8.8.x
    Issue #3038825 by undertext, Mile23: Remove unused code from...

  • alexpott committed 673f5a4 on 8.7.x
    Issue #3038825 by undertext, Mile23: Remove unused code from...

Status: Fixed » Closed (fixed)

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