You are here

public function PhpUnitWarnings::addWarning in Drupal 10

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Traits/PhpUnitWarnings.php \Drupal\Tests\Traits\PhpUnitWarnings::addWarning()

Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.

@internal

Parameters

string $warning: The warning message raised in tests.

See also

\PHPUnit\Framework\TestCase::addWarning()

1 call to PhpUnitWarnings::addWarning()
PhpUnitWarningsTest::testAddWarning in core/tests/Drupal/Tests/PhpUnitWarningsTest.php
Tests that selected PHPUnit warning is converted to deprecation.

File

core/tests/Drupal/Tests/Traits/PhpUnitWarnings.php, line 48

Class

PhpUnitWarnings
Converts deprecation warnings added by PHPUnit to silenced deprecations.

Namespace

Drupal\Tests\Traits

Code

public function addWarning(string $warning) : void {
  if (in_array($warning, self::$deprecationWarnings, TRUE)) {

    // Convert listed PHPUnit deprecations into E_USER_DEPRECATED and prevent
    // each from being raised as a test warning.
    @trigger_error($warning, E_USER_DEPRECATED);
    return;
  }

  // Otherwise, let the parent raise any warning not specifically listed.
  parent::addWarning($warning);
}