You are here

public function LibraryDiscoveryTest::testAssetLibraryDeprecation in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryTest::testAssetLibraryDeprecation()
  2. 10 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryTest::testAssetLibraryDeprecation()

Tests getting a deprecated library.

File

core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryTest.php, line 105

Class

LibraryDiscoveryTest
@coversDefaultClass \Drupal\Core\Asset\LibraryDiscovery @group Asset

Namespace

Drupal\Tests\Core\Asset

Code

public function testAssetLibraryDeprecation() {
  $previous_error_handler = set_error_handler(function ($severity, $message, $file, $line, $context) use (&$previous_error_handler) {

    // Convert deprecation error into a catchable exception.
    if ($severity === E_USER_DEPRECATED) {
      throw new \ErrorException($message, 0, $severity, $file, $line);
    }
    if ($previous_error_handler) {
      return $previous_error_handler($severity, $message, $file, $line, $context);
    }
  });
  try {
    $this->libraryDiscovery
      ->getLibraryByName('test', 'test_3');
    $this
      ->fail('No deprecation error triggered.');
  } catch (\ErrorException $e) {
    $this
      ->assertSame('The "test/test_3" asset library is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use the test_2 library instead. See https://www.example.com', $e
      ->getMessage());
  }
  restore_error_handler();
}