class ShareEnvironmentTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/TestTools/Attribute/ShareEnvironmentTest.php \Drupal\Tests\TestTools\Attribute\ShareEnvironmentTest

Tests how the ShareEnvironment attribute is resolved.

The fixtures below are plain classes. A test class cannot be used, because every concrete test class must repeat the PHPUnit attributes that these fixtures have no use for.

Attributes

#[CoversClass(ShareEnvironment::class)] #[Group('TestTools')]

Hierarchy

Expanded class hierarchy of ShareEnvironmentTest

See also

\Drupal\PHPStan\Rules\TestClassClassMetadata

File

core/tests/Drupal/Tests/TestTools/Attribute/ShareEnvironmentTest.php, line 21

Namespace

Drupal\Tests\TestTools\Attribute
View source
class ShareEnvironmentTest extends TestCase {
  
  /**
   * Tests that a class declaring nothing does not share its environment.
   */
  public function testNoAttribute() : void {
    $this->assertFalse(ShareEnvironment::isEnabledFor(PlainEnvironmentFixture::class));
  }
  
  /**
   * Tests that the attribute makes a class share its environment.
   */
  public function testAttribute() : void {
    $this->assertTrue(ShareEnvironment::isEnabledFor(SharedEnvironmentFixture::class));
  }
  
  /**
   * Tests that a class can state that it needs its own environment.
   *
   * The declaration does nothing while sharing is opt-in, and everything once
   * sharing becomes the default.
   */
  public function testAttributeOptingOut() : void {
    $this->assertFalse(ShareEnvironment::isEnabledFor(DedicatedEnvironmentFixture::class));
  }
  
  /**
   * Tests that the attribute is not inherited.
   *
   * Every test class declares for itself. A class that inherited the attribute
   * would start sharing an environment nobody audited it for.
   */
  public function testAttributeIsNotInherited() : void {
    $this->assertFalse(ShareEnvironment::isEnabledFor(UndeclaredEnvironmentFixture::class));
  }

}

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