You are here

trait ExpectDeprecationTrait in Drupal 9

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

Adds the ability to dynamically set expected deprecation messages in tests.

@internal

Hierarchy

Deprecated

in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait instead.

See also

https://www.drupal.org/node/3161901

2 files declare their use of ExpectDeprecationTrait
ContextAwarePluginTraitTest.php in core/tests/Drupal/KernelTests/Core/Plugin/Context/ContextAwarePluginTraitTest.php
ExpectDeprecationTest.php in core/tests/Drupal/Tests/ExpectDeprecationTest.php

File

core/tests/Drupal/Tests/Traits/ExpectDeprecationTrait.php, line 15

Namespace

Drupal\Tests\Traits
View source
trait ExpectDeprecationTrait {

  /**
   * Sets an expected deprecation message.
   *
   * @param string $message
   *   The expected deprecation message.
   */
  protected function addExpectedDeprecationMessage($message) {
    @trigger_error(__METHOD__ . '() 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', E_USER_DEPRECATED);
    $this
      ->expectDeprecation($message);
  }

  /**
   * Sets expected deprecation messages.
   *
   * @param string[] $messages
   *   The expected deprecation messages.
   *
   * @see \Symfony\Bridge\PhpUnit\Legacy\ExpectDeprecationTraitForV8_4::expectDeprecation()
   */
  public function expectedDeprecations(array $messages) {
    @trigger_error(__METHOD__ . '() 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', E_USER_DEPRECATED);
    foreach ($messages as $message) {
      $this
        ->expectDeprecation($message);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExpectDeprecationTrait::addExpectedDeprecationMessage protected function Sets an expected deprecation message.
ExpectDeprecationTrait::expectedDeprecations public function Sets expected deprecation messages.