function ShareEnvironment::isEnabledFor

Same name and namespace in other branches
  1. main core/tests/Drupal/TestTools/Attribute/ShareEnvironment.php \Drupal\TestTools\Attribute\ShareEnvironment::isEnabledFor()

Returns whether a class shares its environment between its test methods.

The attribute is deliberately not inherited: every test class declares for itself, as it already does for the PHPUnit attributes it has to repeat.

Parameters

string $class: The name of the class to check.

Return value

bool TRUE if the test methods of the class share one environment.

5 calls to ShareEnvironment::isEnabledFor()
KernelTestBase::sharesEnvironment in core/tests/Drupal/KernelTests/KernelTestBase.php
Returns whether this test class shares its environment between its methods.
ShareEnvironmentTest::testAttribute in core/tests/Drupal/Tests/TestTools/Attribute/ShareEnvironmentTest.php
Tests that the attribute makes a class share its environment.
ShareEnvironmentTest::testAttributeIsNotInherited in core/tests/Drupal/Tests/TestTools/Attribute/ShareEnvironmentTest.php
Tests that the attribute is not inherited.
ShareEnvironmentTest::testAttributeOptingOut in core/tests/Drupal/Tests/TestTools/Attribute/ShareEnvironmentTest.php
Tests that a class can state that it needs its own environment.
ShareEnvironmentTest::testNoAttribute in core/tests/Drupal/Tests/TestTools/Attribute/ShareEnvironmentTest.php
Tests that a class declaring nothing does not share its environment.

File

core/tests/Drupal/TestTools/Attribute/ShareEnvironment.php, line 74

Class

ShareEnvironment
Shares the environment of a test class between its test methods.

Namespace

Drupal\TestTools\Attribute

Code

public static function isEnabledFor(string $class) : bool {
  $attributes = (new \ReflectionClass($class))->getAttributes(self::class);
  // A class that declares nothing does not share its environment.
  return $attributes === [] ? FALSE : $attributes[0]->newInstance()->enabled;
}

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