Skip to content

Allow to control Kernel building or control its cacheability

Is your feature request related to a problem? Please describe.

I have a test with ~700 test cases. It's simple, it submits the form and checks what email was sent. Tests cases provided via @dataProvider notation. The problem is, that the process itself takes ~200ms, but another ~1000ms took by Drupal container build. This means, I have additional 700 seconds for building exactly the same container on each case, this is insane.

I dig and found this (https://gitlab.com/weitzman/drupal-test-traits/-/blob/e40ee4e8e41f229d297c5e714fd63c4a00c633a2/src/DrupalTrait.php#L87-93):

        $this->kernel = DrupalKernel::createFromRequest(
            $request,
            $classLoader,
            'existing-site-testcase',
            false,
            $finder->getDrupalRoot()
        );

The fourth parameter is $allow_dumping. If it set to FALSE, then built container will not be cached.

Describe the solution you'd like

  1. Provide a method to control cacheability of container, something like ::shouldContainerRebuild() or a switch ::useCachedContainer().
  2. Provide a parameter to ::setUp() to control this value (I don't like that).
  3. Provide a dedicated method for building Drupal Kernel ::buildDrupalKernelFromRequest() and let a developer decide how to override this part.

Additional context

I don't know why exactly it is done in DTT, because I run other tests with TRUE and they all pass under 3 mins, before it took 30 minutes. I don't see, for now, why it should be disabled by default. Its cacheability can also be disabled via $settings['cache']['bins']['container'] = 'cache.backend.null';, but I can't enable it if I need it.

I would like to have control over that part. Because in cases like I described, I know that the container is static for all cases, I don't see any reason to build it from scratch every time. It simply slows down the whole testing process.

Edited by Nikita Malyshev (Niklan)
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information