function EntityResourceRestTestCoverageTest::setUp

Same name in other branches
  1. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/EntityResourceRestTestCoverageTest.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceRestTestCoverageTest::setUp()
  2. 10 core/modules/rest/tests/src/Kernel/EntityResource/EntityResourceRestTestCoverageTest.php \Drupal\Tests\rest\Kernel\EntityResource\EntityResourceRestTestCoverageTest::setUp()
  3. 11.x core/modules/rest/tests/src/Kernel/EntityResource/EntityResourceRestTestCoverageTest.php \Drupal\Tests\rest\Kernel\EntityResource\EntityResourceRestTestCoverageTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/rest/tests/src/Kernel/EntityResource/EntityResourceRestTestCoverageTest.php, line 39

Class

EntityResourceRestTestCoverageTest
Checks that all core content/config entity types have REST test coverage.

Namespace

Drupal\Tests\rest\Kernel\EntityResource

Code

protected function setUp() : void {
    parent::setUp();
    $all_modules = $this->container
        ->get('extension.list.module')
        ->getList();
    $stable_core_modules = array_filter($all_modules, function ($module) {
        // Filter out contrib, hidden, testing, deprecated and experimental
        // modules. We also don't need to enable modules that are already enabled.
        return $module->origin === 'core' && empty($module->info['hidden']) && $module->status == FALSE && $module->info['package'] !== 'Testing' && $module->info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER] !== ExtensionLifecycle::DEPRECATED && $module->info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER] !== ExtensionLifecycle::EXPERIMENTAL;
    });
    $this->container
        ->get('module_installer')
        ->install(array_keys($stable_core_modules));
    $this->definitions = $this->container
        ->get('entity_type.manager')
        ->getDefinitions();
    // Entity types marked as "internal" are not exposed by the entity REST
    // resource plugin and hence also don't need test coverage.
    $this->definitions = array_filter($this->definitions, function (EntityTypeInterface $entity_type) {
        return !$entity_type->isInternal();
    });
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.