class ConfigEntityValidationTestBaseUnsharedTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBaseUnsharedTest.php \Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBaseUnsharedTest

Tests a subclass that does not share its environment.

This class carries no ShareEnvironment attribute on purpose, and it assigns ::$entity from ::setUp() after the parent method ran. Subclasses wrote their fixture that way before the shared environment existed, and contrib subclasses still do. Every test method of the base class runs here, against a fixture built once per test method.

Attributes

#[Group('config')] #[Group('Validation')] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of ConfigEntityValidationTestBaseUnsharedTest

See also

\Drupal\TestTools\Attribute\ShareEnvironment

File

core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBaseUnsharedTest.php, line 22

Namespace

Drupal\KernelTests\Core\Config
View source
class ConfigEntityValidationTestBaseUnsharedTest extends ConfigEntityValidationTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->entity = DateFormat::create([
      'id' => 'test',
      'label' => 'Test',
      'pattern' => 'Y-m-d',
    ]);
    $this->entity
      ->save();
  }
  
  /**
   * Tests that the entity assigned after ::setUp() is the one under test.
   *
   * The base class reloads ::$entity only for a shared environment. Reloading
   * it here would throw, because nothing recorded which entity to load.
   */
  public function testEntityComesFromSetUp() : void {
    $this->assertFalse(static::sharesEnvironment());
    $this->assertSame('test', $this->entity
      ->id());
    $this->assertFalse($this->entity
      ->isNew());
  }

}

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