trait ExpectDeprecationTrait

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Traits/ExpectDeprecationTrait.php \Drupal\Tests\Traits\ExpectDeprecationTrait
  2. 11.x core/tests/Drupal/TestTools/Extension/DeprecationBridge/ExpectDeprecationTrait.php \Drupal\TestTools\Extension\DeprecationBridge\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

Title Sort descending Modifiers Object type Summary
ExpectDeprecationTrait::addExpectedDeprecationMessage protected function Sets an expected deprecation message.
ExpectDeprecationTrait::expectedDeprecations public function Sets expected deprecation messages.

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