API page: https://api.drupal.org/api/drupal/core%21tests%21Drupal%21KernelTests%21...

The docs here leave much unanswered:

> The module/hook system is functional and operates on a fixed module list. Additional modules needed in a test may be loaded and added to the fixed module list.

What defines the fixed module list?

> the modules are only loaded, but not installed

What does that actually mean? Outside of testing, there is no concept of a module being loaded but not installed, so this needs to be clearly defined.

> Modules have to be installed manually, if needed.

How do you do that?

Also, the @see links are broken.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim created an issue. See original summary.

dawehner’s picture

Issue tags: +phpunit initiative
Mile23’s picture

Status: Active » Needs review
FileSize
4.58 KB

Here's the docblock I came up with:

/**
 * Base class for functional integration tests.
 *
 * This base class partially boots Drupal. The state of the fixture Drupal is
 * comparable to the state of a system during the early part of the installation
 * process.
 *
 * Tests extending this base class can access services and the database, but the
 * system is initially empty. This Drupal runs in a minimal mocked filesystem
 * which operates within vfsStream.
 *
 * Modules specified in the $modules property are added to the service container
 * for each test. The module/hook system is functional. Additional modules
 * needed in a test should override $modules. Modules specified in this way will
 * be added to those specified in superclasses.
 *
 * Unlike \Drupal\Tests\BrowserTestBase, the modules are not installed. They are
 * loaded such that their services and hooks are available, but the install
 * process has not been performed.
 *
 * Other modules can be made available in this way using enableModules().
 *
 * No modules can be fully installed.
 *
 * @see \Drupal\Tests\KernelTestBase::$modules
 * @see \Drupal\Tests\KernelTestBase::enableModules()
 *
 * @todo Extend ::checkRequirements() to account for '@requires module'.
 *   https://www.drupal.org/node/2728579
 */
joachim’s picture

Status: Needs review » Needs work

> No modules can be fully installed.

Is it not the case that if you do installConfig() and installEntitySchema() you get the equivalent of the module being installed?

Lendude’s picture

@Mile23 that looks much better!

Some additional thoughts I had:
I would definitely mention installConfig() and installEntitySchema(), even if it's just a @see.

And I agree that 'No modules can be fully installed.' might cause a little confusion. I would just leave that out. The previous two paragraph make it pretty clear what you get, whether or not that, combined with installConfig() and installEntitySchema(), is equivalent to a full install probably depends on the module.

joachim’s picture

> combined with installConfig() and installEntitySchema(), is equivalent to a full install probably depends on the module.

It would be good to say that for most modules, those together are sufficient (if that is actually the case!)

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Version: 8.5.x-dev » 8.4.x-dev
Status: Needs work » Needs review
FileSize
5.34 KB
2.55 KB

This is a documentation-only change and also a testing improvement, so it scores the 8.4.x-alpha double bonus.

Added info about installConfig() and installEntitySchema(), with a suggestion that you might try BrowserTestBase, too.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

  1. +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
    @@ -31,24 +31,39 @@
     /**
      * Base class for functional integration tests.
      *
    - * Tests extending this base class can access files and the database, but the
    

    Should we also have some sentence mentioning when this class should actually be used? "The KernelTestBase should be extended when you want to test integrations between components in a module, or anything related with storing/loading data." Better suggestions are welcomed.

  2. +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
    @@ -31,24 +31,39 @@
      *
      * @see \Drupal\Tests\KernelTestBase::$modules
      * @see \Drupal\Tests\KernelTestBase::enableModules()
    + * @see \Drupal\Tests\KernelTestBase::installConfig()
    + * @see \Drupal\Tests\KernelTestBase::installEntitySchema()
    + * @see \Drupal\Tests\BrowserTestBase
    

    At least a @see ::installSchema would be helpful, I think

Mile23’s picture

Version: 8.5.x-dev » 8.4.x-dev
FileSize
6.43 KB
4.66 KB

#10.1:

Okay.... But if we go too much further down this path we get into an argument about whether we should use KTB as a replacement for everything this says: https://www.drupal.org/docs/8/phpunit/unit-testing-more-complicated-drup... :-)

#10.2:

Done.

Setting back to 8.4.x because: docs-only and testing.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @Mile23
I think we can iterate on this issue forever ...

joachim’s picture

Agreed -- this patch is a huge improvement! Let's get this in and we can think about adding more detail in the future.

Gábor Hojtsy’s picture

Version: 8.4.x-dev » 8.5.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Looks like a great improvement! Thanks!

As per our backport policy this would need to be committed to 8.5.x first and then backported/cherry-picked. Unfortunately this patch does not apply to 8.5.x.

$ git apply --index 2898373_11.patch 
error: patch failed: core/tests/Drupal/KernelTests/KernelTestBase.php:31
error: core/tests/Drupal/KernelTests/KernelTestBase.php: patch does not apply
Gábor Hojtsy’s picture

Adjusted credits.

Gábor Hojtsy’s picture

Title: gaps in docs for KernelTestBase » Gaps in docs for KernelTestBase
jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
6.19 KB

Re-rolled.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @Jo Fitzgerald!

  • larowlan committed d034b44 on 8.5.x
    Issue #2898373 by Mile23, Jo Fitzgerald, joachim, dawehner, Gábor Hojtsy...

  • larowlan committed 14aec6b on 8.4.x
    Issue #2898373 by Mile23, Jo Fitzgerald, joachim, dawehner, Gábor Hojtsy...
larowlan’s picture

Version: 8.5.x-dev » 8.4.x-dev
Status: Reviewed & tested by the community » Fixed

Committed as d034b44 and pushed to 8.5.x.
Cherry-picked as 14aec6b and pushed to 8.4.x.

Status: Fixed » Closed (fixed)

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