You are here

class ExpectDeprecationTest in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/ExpectDeprecationTest.php \Drupal\Tests\ExpectDeprecationTest

@coversDefaultClass \Drupal\Tests\Traits\ExpectDeprecationTrait

@group Test @group legacy

Do not remove this test when \Drupal\Tests\Traits\ExpectDeprecationTrait is removed. Change it to use \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait instead to ensure Drupal has test coverage of Symfony's deprecation testing.

Hierarchy

Expanded class hierarchy of ExpectDeprecationTest

File

core/tests/Drupal/Tests/ExpectDeprecationTest.php, line 17

Namespace

Drupal\Tests
View source
class ExpectDeprecationTest extends UnitTestCase {
  use ExpectDeprecationTrait;

  /**
   * @covers ::addExpectedDeprecationMessage
   */
  public function testExpectDeprecation() {
    $this
      ->expectDeprecation('Drupal\\Tests\\Traits\\ExpectDeprecationTrait::addExpectedDeprecationMessage() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \\Symfony\\Bridge\\PhpUnit\\ExpectDeprecationTrait::expectDeprecation() instead. See https://www.drupal.org/node/3161901');
    $this
      ->addExpectedDeprecationMessage('Test deprecation');
    @trigger_error('Test deprecation', E_USER_DEPRECATED);
  }

  /**
   * @covers ::addExpectedDeprecationMessage
   * @runInSeparateProcess
   * @preserveGlobalState disabled
   */
  public function testExpectDeprecationInIsolation() {
    $this
      ->expectDeprecation('Drupal\\Tests\\Traits\\ExpectDeprecationTrait::addExpectedDeprecationMessage() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \\Symfony\\Bridge\\PhpUnit\\ExpectDeprecationTrait::expectDeprecation() instead. See https://www.drupal.org/node/3161901');
    $this
      ->expectDeprecation('Drupal\\Tests\\Traits\\ExpectDeprecationTrait::expectedDeprecations() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \\Symfony\\Bridge\\PhpUnit\\ExpectDeprecationTrait::expectDeprecation() instead. See https://www.drupal.org/node/3161901');
    $this
      ->addExpectedDeprecationMessage('Test isolated deprecation');
    $this
      ->expectedDeprecations([
      'Test isolated deprecation2',
    ]);
    @trigger_error('Test isolated deprecation', E_USER_DEPRECATED);
    @trigger_error('Test isolated deprecation2', E_USER_DEPRECATED);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExpectDeprecationTest::testExpectDeprecation public function @covers ::addExpectedDeprecationMessage
ExpectDeprecationTest::testExpectDeprecationInIsolation public function @covers ::addExpectedDeprecationMessage @runInSeparateProcess @preserveGlobalState disabled
ExpectDeprecationTrait::addExpectedDeprecationMessage protected function Sets an expected deprecation message.
ExpectDeprecationTrait::expectedDeprecations public function Sets expected deprecation messages.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 308
UnitTestCase::setUpBeforeClass public static function