From 94c7904d86536ddcb598f966bbbbeb87b654e0b4 Mon Sep 17 00:00:00 2001
From: IMMACULATE X <58532-immaculate.x@users.noreply.drupalcode.org>
Date: Fri, 21 Oct 2022 12:01:50 +0300
Subject: [PATCH] Issue #3297522 by Project Update Bot, immaculatexavier:
 Automated Drupal 10 compatibility fixes

---
 libraries.api.php                             |   2 +-
 libraries.info.yml                            |   2 +-
 libraries.module                              |   6 +-
 src/Plugin/libraries/Locator/UriLocator.php   |   3 +-
 .../libraries/Type/AssetLibraryType.php       |   3 +-
 .../Type/MultipleAssetLibraryType.php         |   2 +-
 .../VersionDetector/LinePatternDetector.php   |   2 +-
 .../libraries_test/libraries_test.info.yml    |   2 +-
 .../libraries_test/libraries_test.module      |  36 ++--
 .../DefinitionDiscoveryFactoryTest.php        |   8 +-
 tests/src/Functional/LibrariesWebTest.php     | 164 +++++++++---------
 .../Asset/AssetLibraryTestBase.php            |   4 +-
 .../ExternalLibrary/GlobalLocatorTest.php     |   2 +-
 .../PhpFile/PhpFileLibraryTest.php            |   2 +-
 .../Kernel/LibrariesApi/LibrariesUnitTest.php |   2 +-
 .../src/Kernel/LibraryTypeKernelTestBase.php  |   6 +-
 .../LinePatternDetectorTest.php               |   2 +
 17 files changed, 127 insertions(+), 121 deletions(-)

diff --git a/libraries.api.php b/libraries.api.php
index 7e127ae..ec4a3e8 100644
--- a/libraries.api.php
+++ b/libraries.api.php
@@ -605,5 +605,5 @@ function hook_libraries_info_alter(&$libraries) {
 function hook_libraries_info_file_paths() {
   // Taken from the Libraries test module, which needs to specify the path to
   // the test library.
-  return [drupal_get_path('module', 'libraries_test') . '/example'];
+  return [\Drupal::service('extension.list.module')->getPath('libraries_test') . '/example'];
 }
diff --git a/libraries.info.yml b/libraries.info.yml
index 59e3b4e..9b11f7d 100644
--- a/libraries.info.yml
+++ b/libraries.info.yml
@@ -1,4 +1,4 @@
 name: Libraries
 type: module
 description: Allows version-dependent and shared usage of external libraries.
-core_version_requirement: ^8.8 || ^9
+core_version_requirement: ^8.8 || ^9 || ^10
diff --git a/libraries.module b/libraries.module
index a4b0d89..647a1ee 100644
--- a/libraries.module
+++ b/libraries.module
@@ -117,7 +117,7 @@ function libraries_get_libraries() {
   // profile, installation profiles may want to place libraries into a
   // 'libraries' directory.
   if ($profile = \Drupal::installProfile()) {
-    $profile_path = drupal_get_path('profile', $profile);
+    $profile_path = \Drupal::service('extension.list.profile')->getPath($profile);
     $searchdir[] = "$profile_path/libraries";
   };
 
@@ -168,7 +168,7 @@ function libraries_get_libraries() {
  * https://www.drupal.org/node/2170763
  */
 function libraries_scan_info_files() {
-  $profile = drupal_get_path('profile', \Drupal::installProfile());
+  $profile = \Drupal::service('extension.list.profile')->getPath(\Drupal::installProfile());
   $config = DrupalKernel::findSitePath(\Drupal::request());
 
   // Build a list of directories.
@@ -808,7 +808,7 @@ function libraries_load_files($library) {
       libraries_load_files([
         'files' => $files,
         'path' => '',
-        'library path' => drupal_get_path('module', $module),
+        'library path' => \Drupal::service('extension.list.module')->getPath($module),
       ]);
     }
   }
diff --git a/src/Plugin/libraries/Locator/UriLocator.php b/src/Plugin/libraries/Locator/UriLocator.php
index 2732505..aa53183 100644
--- a/src/Plugin/libraries/Locator/UriLocator.php
+++ b/src/Plugin/libraries/Locator/UriLocator.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\libraries\Plugin\libraries\Locator;
 
+use Drupal\Core\StreamWrapper\LocalStream;
 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
 use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
 use Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface;
@@ -73,7 +74,7 @@ class UriLocator implements LocatorInterface, ContainerFactoryPluginInterface {
   public function locate(LocalLibraryInterface $library) {
     /** @var \Drupal\Core\StreamWrapper\LocalStream $stream_wrapper */
     $stream_wrapper = $this->streamWrapperManager->getViaUri($this->uri);
-    assert($stream_wrapper instanceof \Drupal\Core\StreamWrapper\LocalStream);
+    assert($stream_wrapper instanceof LocalStream);
     // Calling LocalStream::getDirectoryPath() explicitly avoids the realpath()
     // usage in LocalStream::getLocalPath(), which breaks if Libraries API is
     // symbolically linked into the Drupal installation.
diff --git a/src/Plugin/libraries/Type/AssetLibraryType.php b/src/Plugin/libraries/Type/AssetLibraryType.php
index a92f27d..9cd5b52 100644
--- a/src/Plugin/libraries/Type/AssetLibraryType.php
+++ b/src/Plugin/libraries/Type/AssetLibraryType.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\libraries\Plugin\libraries\Type;
 
+use Drupal\libraries\ExternalLibrary\Asset\AssetLibraryInterface;
 use Drupal\libraries\ExternalLibrary\Asset\AssetLibrary;
 use Drupal\libraries\ExternalLibrary\Asset\AttachableAssetLibraryRegistrationInterface;
 use Drupal\libraries\ExternalLibrary\LibraryInterface;
@@ -24,7 +25,7 @@ class AssetLibraryType extends LibraryTypeBase implements AttachableAssetLibrary
    * {@inheritdoc}
    */
   public function getAttachableAssetLibraries(LibraryInterface $library, LibraryManagerInterface $library_manager) {
-    assert($library instanceof \Drupal\libraries\ExternalLibrary\Asset\AssetLibraryInterface);
+    assert($library instanceof AssetLibraryInterface);
     /** @var \Drupal\libraries\ExternalLibrary\Asset\AssetLibraryInterface $library */
     return [$library->getId() => $library->getAttachableAssetLibrary($library_manager)];
   }
diff --git a/src/Plugin/libraries/Type/MultipleAssetLibraryType.php b/src/Plugin/libraries/Type/MultipleAssetLibraryType.php
index f73887e..b1b8984 100644
--- a/src/Plugin/libraries/Type/MultipleAssetLibraryType.php
+++ b/src/Plugin/libraries/Type/MultipleAssetLibraryType.php
@@ -25,7 +25,7 @@ class MultipleAssetLibraryType extends LibraryTypeBase implements AttachableAsse
    * {@inheritdoc}
    */
   public function getAttachableAssetLibraries(LibraryInterface $external_library, LibraryManagerInterface $library_manager) {
-    assert($external_library instanceof \Drupal\libraries\ExternalLibrary\Asset\MultipleAssetLibraryInterface);
+    assert($external_library instanceof MultipleAssetLibraryInterface);
     /** @var \Drupal\libraries\ExternalLibrary\Asset\MultipleAssetLibraryInterface $external_library */
     $attachable_libraries = [];
     foreach ($external_library->getAttachableAssetLibraries($library_manager) as $component_name => $attachable_library) {
diff --git a/src/Plugin/libraries/VersionDetector/LinePatternDetector.php b/src/Plugin/libraries/VersionDetector/LinePatternDetector.php
index 25a799c..3d187a5 100644
--- a/src/Plugin/libraries/VersionDetector/LinePatternDetector.php
+++ b/src/Plugin/libraries/VersionDetector/LinePatternDetector.php
@@ -56,7 +56,7 @@ class LinePatternDetector extends PluginBase implements VersionDetectorInterface
       $configuration,
       $plugin_id,
       $plugin_definition,
-      $container->get('app.root')
+      $container->getParameter('app.root')
     );
   }
 
diff --git a/tests/modules/libraries_test/libraries_test.info.yml b/tests/modules/libraries_test/libraries_test.info.yml
index 2e75715..e2e8e05 100644
--- a/tests/modules/libraries_test/libraries_test.info.yml
+++ b/tests/modules/libraries_test/libraries_test.info.yml
@@ -1,7 +1,7 @@
 name: Libraries test module
 type: module
 description: Tests library detection and loading.
-core_version_requirement: ^8 || ^9
+core_version_requirement: ^8 || ^9 || ^10
 dependencies:
   - libraries:libraries
 hidden: TRUE
diff --git a/tests/modules/libraries_test/libraries_test.module b/tests/modules/libraries_test/libraries_test.module
index 2f6ee0e..89b0eca 100644
--- a/tests/modules/libraries_test/libraries_test.module
+++ b/tests/modules/libraries_test/libraries_test.module
@@ -15,17 +15,17 @@ function libraries_test_libraries_info() {
   // Test library detection.
   $libraries['example_missing'] = [
     'name' => 'Example missing',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/missing',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/missing',
   ];
   $libraries['example_undetected_version'] = [
     'name' => 'Example undetected version',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests',
     'version callback' => '_libraries_test_return_version',
     'version arguments' => [FALSE],
   ];
   $libraries['example_unsupported_version'] = [
     'name' => 'Example unsupported version',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests',
     'version callback' => '_libraries_test_return_version',
     'version arguments' => ['1'],
     'versions' => [
@@ -35,7 +35,7 @@ function libraries_test_libraries_info() {
 
   $libraries['example_supported_version'] = [
     'name' => 'Example supported version',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests',
     'version callback' => '_libraries_test_return_version',
     'version arguments' => ['1'],
     'versions' => [
@@ -46,7 +46,7 @@ function libraries_test_libraries_info() {
   // Test the default version callback.
   $libraries['example_default_version_callback'] = [
     'name' => 'Example default version callback',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     'version arguments' => [
       'file' => 'README.txt',
       // Version 1
@@ -58,7 +58,7 @@ function libraries_test_libraries_info() {
   // Test a multiple-parameter version callback.
   $libraries['example_multiple_parameter_version_callback'] = [
     'name' => 'Example multiple parameter version callback',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     // Version 1
     'version callback' => '_libraries_test_get_version',
     'version arguments' => ['README.txt', '/Version (\d+)/', 5],
@@ -67,7 +67,7 @@ function libraries_test_libraries_info() {
   // Test a top-level files property.
   $libraries['example_files'] = [
     'name' => 'Example files',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     'version' => '1',
     'files' => [
       'js' => ['example_1.js'],
@@ -81,7 +81,7 @@ function libraries_test_libraries_info() {
   // these files should be automatically loaded when the library is loaded.
   $libraries['example_integration_files'] = [
     'name' => 'Example integration files',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     'version' => '1',
     'integration files' => [
       'libraries_test' => [
@@ -95,7 +95,7 @@ function libraries_test_libraries_info() {
   // Test version overloading.
   $libraries['example_versions'] = [
     'name' => 'Example versions',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     'version' => '2',
     'versions' => [
       '1' => [
@@ -118,7 +118,7 @@ function libraries_test_libraries_info() {
   // Test variant detection.
   $libraries['example_variant_missing'] = [
     'name' => 'Example variant missing',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     'version' => '1',
     'variants' => [
       'example_variant' => [
@@ -135,7 +135,7 @@ function libraries_test_libraries_info() {
 
   $libraries['example_variant'] = [
     'name' => 'Example variant',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     'version' => '1',
     'variants' => [
       'example_variant' => [
@@ -153,7 +153,7 @@ function libraries_test_libraries_info() {
   // Test correct behaviour with multiple versions and multiple variants.
   $libraries['example_versions_and_variants'] = [
     'name' => 'Example versions and variants',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     'version' => '2',
     'versions' => [
       '1' => [
@@ -209,27 +209,27 @@ function libraries_test_libraries_info() {
   // This library acts as a dependency for the libraries below.
   $libraries['example_dependency'] = [
     'name' => 'Example dependency',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     'version' => '1.1',
     'files' => ['js' => ['example_1.js']],
   ];
   $libraries['example_dependency_missing'] = [
     'name' => 'Example dependency missing',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     'version' => '1',
     'dependencies' => ['example_missing'],
     'files' => ['js' => ['example_1.js']],
   ];
   $libraries['example_dependency_incompatible'] = [
     'name' => 'Example dependency incompatible',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     'version' => '1',
     'dependencies' => ['example_dependency (>1.1)'],
     'files' => ['js' => ['example_1.js']],
   ];
   $libraries['example_dependency_compatible'] = [
     'name' => 'Example dependency compatible',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     'version' => '1',
     'dependencies' => ['example_dependency (>=1.1)'],
     'files' => ['js' => ['example_1.js']],
@@ -238,7 +238,7 @@ function libraries_test_libraries_info() {
   // Test the applying of callbacks.
   $libraries['example_callback'] = [
     'name' => 'Example callback',
-    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
     'version' => '1',
     'versions' => [
       '1' => [
@@ -292,7 +292,7 @@ function libraries_test_libraries_info() {
  * Implements hook_libraries_info_file_paths()
  */
 function libraries_test_libraries_info_file_paths() {
-  return [drupal_get_path('module', 'libraries') . '/tests/example'];
+  return [\Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example'];
 }
 
 /**
diff --git a/tests/src/Functional/ExternalLibrary/Definition/DefinitionDiscoveryFactoryTest.php b/tests/src/Functional/ExternalLibrary/Definition/DefinitionDiscoveryFactoryTest.php
index 0fee23e..b212bac 100644
--- a/tests/src/Functional/ExternalLibrary/Definition/DefinitionDiscoveryFactoryTest.php
+++ b/tests/src/Functional/ExternalLibrary/Definition/DefinitionDiscoveryFactoryTest.php
@@ -39,12 +39,12 @@ class DefinitionDiscoveryFactoryTest extends BrowserTestBase {
   /**
    * {@inheritdoc}
    */
-  public static $modules = ['libraries'];
+  protected static $modules = ['libraries'];
 
   /**
    * {@inheritdoc}
    */
-  protected function setUp() {
+  protected function setUp(): void {
     parent::setUp();
 
     /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
@@ -115,9 +115,9 @@ class DefinitionDiscoveryFactoryTest extends BrowserTestBase {
     /** @var \Drupal\libraries\ExternalLibrary\Definition\DefinitionDiscoveryInterface $discovery */
     $discovery = $this->container->get($discovery_service_id);
     $definition_file = "$definitions_directory/$library_id.json";
-    $this->assertFileNotExists($definition_file);
+    $this->assertFileDoesNotExist($definition_file);
     $this->assertTrue($discovery->hasDefinition($library_id));
-    $this->assertFileNotExists($definition_file);
+    $this->assertFileDoesNotExist($definition_file);
     $this->assertEquals($discovery->getDefinition($library_id), $expected_definition);
     $this->assertFileExists($definition_file);
   }
diff --git a/tests/src/Functional/LibrariesWebTest.php b/tests/src/Functional/LibrariesWebTest.php
index c109094..d1c964a 100644
--- a/tests/src/Functional/LibrariesWebTest.php
+++ b/tests/src/Functional/LibrariesWebTest.php
@@ -29,7 +29,7 @@ class LibrariesWebTest extends BrowserTestBase {
    *
    * @var array
    */
-  public static $modules = ['libraries', 'libraries_test'];
+  protected static $modules = ['libraries', 'libraries_test'];
 
   /**
    * The URL generator used in this test.
@@ -48,7 +48,7 @@ class LibrariesWebTest extends BrowserTestBase {
   /**
    * {@inheritdoc}
    */
-  protected function setUp() {
+  protected function setUp(): void {
     parent::setUp();
 
     $this->urlAssembler = $this->container->get('unrouted_url_assembler');
@@ -63,14 +63,14 @@ class LibrariesWebTest extends BrowserTestBase {
       'name' => 'Example',
       'dependencies' => ['Example missing'],
     ];
-    libraries_detect_dependencies($library);
+    \Drupal::service('libraries.manager')->getLibrary($library);
     $this->assertEquals($library['error'], 'missing dependency', 'libraries_detect_dependencies() detects missing dependency');
     $error_message = t('The %dependency library, which the %library library depends on, is not installed.', [
       '%dependency' => 'Example missing',
       '%library' => $library['name'],
     ]);
-    $this->verbose("Expected:<br>$error_message");
-    $this->verbose('Actual:<br>' . $library['error message']);
+    dump("Expected:<br>$error_message");
+    dump('Actual:<br>' . $library['error message']);
     $this->assertEquals($library['error message'], $error_message, 'Correct error message for a missing dependency');
     // Test versioned dependencies.
     $version = '1.1';
@@ -110,14 +110,14 @@ class LibrariesWebTest extends BrowserTestBase {
       // 'installed' is already set, when it is called. It sets the value to
       // FALSE for missing or incompatible dependencies.
       $library['installed'] = TRUE;
-      libraries_detect_dependencies($library);
+      \Drupal::service('libraries.manager')->getLibrary($library);
       $this->assertTrue($library['installed'], "libraries_detect_dependencies() detects compatible version string: '$version_string' is compatible with '$version'");
     }
     foreach ($incompatible as $version_string) {
       $library['dependencies'][0] = "example_dependency ($version_string)";
       $library['installed'] = TRUE;
       unset($library['error'], $library['error message']);
-      libraries_detect_dependencies($library);
+      \Drupal::service('libraries.manager')->getLibrary($library);
       $this->assertEquals($library['error'], 'incompatible dependency', "libraries_detect_dependencies() detects incompatible version strings: '$version_string' is incompatible with '$version'");
     }
     // Instead of repeating this assertion for each version string, we just
@@ -127,8 +127,8 @@ class LibrariesWebTest extends BrowserTestBase {
       '%dependency' => 'Example dependency',
       '%library' => $library['name'],
     ]);
-    $this->verbose("Expected:<br>$error_message");
-    $this->verbose('Actual:<br>' . $library['error message']);
+    dump("Expected:<br>$error_message");
+    dump('Actual:<br>' . $library['error message']);
     $this->assertEquals($library['error message'], $error_message, 'Correct error message for an incompatible dependency');
   }
 
@@ -138,16 +138,16 @@ class LibrariesWebTest extends BrowserTestBase {
   public function testLibrariesScanInfoFiles() {
     $expected = [
       'example_info_file' => (object) [
-        'uri' => drupal_get_path('module', 'libraries') . '/tests/example/example_info_file.libraries.info.yml',
+        'uri' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example/example_info_file.libraries.info.yml',
         'filename' => 'example_info_file.libraries.info.yml',
         'name' => 'example_info_file.libraries.info',
       ],
     ];
-    $actual = libraries_scan_info_files();
-    $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
-    $this->verbose('Actual:<pre>' . var_export($actual, TRUE) . '</pre>');
+    $actual = \Drupal::service('libraries.manager')->scan_info_files();
+    dump('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
+    dump('Actual:<pre>' . var_export($actual, TRUE) . '</pre>');
     $this->assertEquals($actual, $expected, 'libraries_scan_info_files() correctly finds the example info file.');
-    $this->verbose('<pre>' . var_export(libraries_scan_info_files(), TRUE) . '</pre>');
+    dump('<pre>' . var_export($actual, TRUE) . '</pre>');
   }
 
   /**
@@ -157,7 +157,7 @@ class LibrariesWebTest extends BrowserTestBase {
     // Test that library information is found correctly.
     $expected = [
       'name' => 'Example files',
-      'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+      'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
       'version' => '1',
       'files' => [
         'js' => ['example_1.js' => []],
@@ -166,25 +166,25 @@ class LibrariesWebTest extends BrowserTestBase {
       ],
       'module' => 'libraries_test',
     ];
-    libraries_info_defaults($expected, 'example_files');
-    $library = libraries_info('example_files');
-    $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
-    $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
+    \Drupal::service('libraries.manager')->info_defaults($expected, 'example_files');
+    $library = \Drupal::service('libraries.manager')->info('example_files');
+    dump('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
+    dump('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library, $expected, 'Library information is correctly gathered.');
 
     // Test a library specified with an .info file gets detected.
     $expected = [
       'name' => 'Example info file',
-      'info file' => drupal_get_path('module', 'libraries') . '/tests/example/example_info_file.libraries.info.yml',
+      'info file' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example/example_info_file.libraries.info.yml',
     ];
-    libraries_info_defaults($expected, 'example_info_file');
-    $library = libraries_info('example_info_file');
+    \Drupal::service('libraries.manager')->info_defaults($expected, 'example_info_file');
+    $library = \Drupal::service('libraries.manager')->info('example_info_file');
     // If this module was downloaded from Drupal.org, the Drupal.org packaging
     // system has corrupted the test info file.
     // @see http://drupal.org/node/1606606
     unset($library['core'], $library['datestamp'], $library['project'], $library['version']);
-    $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
-    $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
+    dump('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
+    dump('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library, $expected, 'Library specified with an .info file found');
   }
 
@@ -193,8 +193,8 @@ class LibrariesWebTest extends BrowserTestBase {
    */
   public function testLibrariesDetect() {
     // Test missing library.
-    $library = libraries_detect('example_missing');
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->getLibrary('example_missing');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library['error'], 'not found', 'Missing library not found.');
     $error_message = t('The %library library could not be found.', [
       '%library' => $library['name'],
@@ -202,8 +202,8 @@ class LibrariesWebTest extends BrowserTestBase {
     $this->assertEquals($library['error message'], $error_message, 'Correct error message for a missing library.');
 
     // Test unknown library version.
-    $library = libraries_detect('example_undetected_version');
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->getLibrary('example_undetected_version');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library['error'], 'not detected', 'Undetected version detected as such.');
     $error_message = t('The version of the %library library could not be detected.', [
       '%library' => $library['name'],
@@ -211,8 +211,8 @@ class LibrariesWebTest extends BrowserTestBase {
     $this->assertEquals($library['error message'], $error_message, 'Correct error message for a library with an undetected version.');
 
     // Test unsupported library version.
-    $library = libraries_detect('example_unsupported_version');
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->getLibrary('example_unsupported_version');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library['error'], 'not supported', 'Unsupported version detected as such.');
     $error_message = t('The installed version %version of the %library library is not supported.', [
       '%version' => $library['version'],
@@ -221,43 +221,43 @@ class LibrariesWebTest extends BrowserTestBase {
     $this->assertEquals($library['error message'], $error_message, 'Correct error message for a library with an unsupported version.');
 
     // Test supported library version.
-    $library = libraries_detect('example_supported_version');
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->getLibrary('example_supported_version');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library['installed'], TRUE, 'Supported library version found.');
 
     // Test libraries_get_version().
-    $library = libraries_detect('example_default_version_callback');
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->getLibrary('example_default_version_callback');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library['version'], '1', 'Expected version returned by default version callback.');
 
     // Test a multiple-parameter version callback.
-    $library = libraries_detect('example_multiple_parameter_version_callback');
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->getLibrary('example_multiple_parameter_version_callback');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library['version'], '1', 'Expected version returned by multiple parameter version callback.');
 
     // Test a top-level files property.
-    $library = libraries_detect('example_files');
+    $library = \Drupal::service('libraries.manager')->getLibrary('example_files');
     $files = [
       'js' => ['example_1.js' => []],
       'css' => ['example_1.css' => []],
       'php' => ['example_1.php' => []],
     ];
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library['files'], $files, 'Top-level files property works.');
 
     // Test version-specific library files.
-    $library = libraries_detect('example_versions');
+    $library = \Drupal::service('libraries.manager')->getLibrary('example_versions');
     $files = [
       'js' => ['example_2.js' => []],
       'css' => ['example_2.css' => []],
       'php' => ['example_2.php' => []],
     ];
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library['files'], $files, 'Version-specific library files found.');
 
     // Test missing variant.
-    $library = libraries_detect('example_variant_missing');
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->getLibrary('example_variant_missing');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library['variants']['example_variant']['error'], 'not found', 'Missing variant not found');
     $error_message = t('The %variant variant of the %library library could not be found.', [
       '%variant' => 'example_variant',
@@ -266,8 +266,8 @@ class LibrariesWebTest extends BrowserTestBase {
     $this->assertEquals($library['variants']['example_variant']['error message'], $error_message, 'Correct error message for a missing variant.');
 
     // Test existing variant.
-    $library = libraries_detect('example_variant');
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->getLibrary('example_variant');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library['variants']['example_variant']['installed'], TRUE, 'Existing variant found.');
   }
 
@@ -278,17 +278,17 @@ class LibrariesWebTest extends BrowserTestBase {
    */
   public function _testLibrariesLoad() {
     // Test dependencies.
-    $library = libraries_load('example_dependency_missing');
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->load('example_dependency_missing');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertFalse($library['loaded'], 'Library with missing dependency cannot be loaded');
-    $library = libraries_load('example_dependency_incompatible');
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->load('example_dependency_incompatible');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertFalse($library['loaded'], 'Library with incompatible dependency cannot be loaded');
-    $library = libraries_load('example_dependency_compatible');
-    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->load('example_dependency_compatible');
+    dump('<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library['loaded'], 1, 'Library with compatible dependency is loaded');
     $loaded = &drupal_static('libraries_load');
-    $this->verbose('<pre>' . var_export($loaded, TRUE) . '</pre>');
+    dump('<pre>' . var_export($loaded, TRUE) . '</pre>');
     $this->assertEquals($loaded['example_dependency']['loaded'], 1, 'Dependency library is also loaded');
   }
 
@@ -298,7 +298,7 @@ class LibrariesWebTest extends BrowserTestBase {
   public function testCallbacks() {
     $expected = [
       'name' => 'Example callback',
-      'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+      'library path' => \Drupal::service('extension.list.module')->getPath('libraries') . '/tests/example',
       'version' => '1',
       'versions' => [
         '1' => [
@@ -341,16 +341,16 @@ class LibrariesWebTest extends BrowserTestBase {
       'post-load callback' => 'not applied',
       'module' => 'libraries_test',
     ];
-    libraries_info_defaults($expected, 'example_callback');
+    \Drupal::service('libraries.manager')->info_defaults($expected, 'example_callback');
 
     // Test a callback in the 'info' group.
     $expected['info callback'] = 'applied (top-level)';
     $expected['versions']['1']['info callback'] = 'applied (version 1)';
     $expected['versions']['1']['variants']['example_variant']['info callback'] = 'applied (version 1, variant example_variant)';
     $expected['variants']['example_variant']['info callback'] = 'applied (variant example_variant)';
-    $library = libraries_info('example_callback');
-    $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
-    $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->info('example_callback');
+    dump('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
+    dump('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library, $expected, 'Prepare callback was applied correctly.');
 
     // Test a callback in the 'pre-detect' and 'post-detect' phases.
@@ -369,9 +369,9 @@ class LibrariesWebTest extends BrowserTestBase {
     $expected['post-detect callback'] = 'applied (top-level)';
     $expected['variants']['example_variant']['pre-detect callback'] = 'applied (version 1, variant example_variant)';
     $expected['variants']['example_variant']['post-detect callback'] = 'applied (variant example_variant)';
-    $library = libraries_detect('example_callback');
-    $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
-    $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->getLibrary('example_callback');
+    dump('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
+    dump('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library, $expected, 'Detect callback was applied correctly.');
 
     // Test a callback in the 'pre-load' and 'post-load' phases.
@@ -381,9 +381,9 @@ class LibrariesWebTest extends BrowserTestBase {
     $expected['loaded'] = 0;
     $expected['pre-load callback'] = 'applied (top-level)';
     $expected['post-load callback'] = 'applied (top-level)';
-    $library = libraries_load('example_callback');
-    $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
-    $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->load('example_callback');
+    dump('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
+    dump('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library, $expected, 'Pre-load and post-load callbacks were applied correctly.');
     // This is not recommended usually and is only used for testing purposes.
     drupal_static_reset('libraries_load');
@@ -392,9 +392,9 @@ class LibrariesWebTest extends BrowserTestBase {
     $expected['info callback'] = 'applied (version 1, variant example_variant)';
     $expected['pre-detect callback'] = 'applied (version 1, variant example_variant)';
     $expected['post-detect callback'] = 'applied (variant example_variant)';
-    $library = libraries_load('example_callback', 'example_variant');
-    $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
-    $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
+    $library = \Drupal::service('libraries.manager')->load('example_callback', 'example_variant');
+    dump('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
+    dump('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
     $this->assertEquals($library, $expected, 'Pre-detect and post-detect callbacks were applied correctly to a variant.');
   }
 
@@ -414,9 +414,9 @@ class LibrariesWebTest extends BrowserTestBase {
 
     // Test loading of integration files.
     $this->drupalGet('libraries_test/integration_files');
-    $this->assertRaw('libraries_test.js', 'Integration file loading: libraries_test.js found');
-    $this->assertRaw('libraries_test.css', 'Integration file loading: libraries_test.css found');
-    $this->assertRaw('libraries_test.inc', 'Integration file loading: libraries_test.inc found');
+    $this->assertSession()->responseContains('libraries_test.js');
+    $this->assertSession()->responseContains('libraries_test.css');
+    $this->assertSession()->responseContains('libraries_test.inc');
 
     // Test version overloading.
     $this->drupalGet('libraries_test/versions');
@@ -436,19 +436,19 @@ class LibrariesWebTest extends BrowserTestBase {
     // When the library information is not cached, all callback groups should be
     // invoked.
     $this->drupalGet('libraries_test/cache');
-    $this->assertRaw('The <em>info</em> callback group was invoked.', 'Info callback invoked for uncached libraries.');
-    $this->assertRaw('The <em>pre-detect</em> callback group was invoked.', 'Pre-detect callback invoked for uncached libraries.');
-    $this->assertRaw('The <em>post-detect</em> callback group was invoked.', 'Post-detect callback invoked for uncached libraries.');
-    $this->assertRaw('The <em>pre-load</em> callback group was invoked.', 'Pre-load callback invoked for uncached libraries.');
-    $this->assertRaw('The <em>post-load</em> callback group was invoked.', 'Post-load callback invoked for uncached libraries.');
+    $this->assertSession()->responseContains('The <em>info</em> callback group was invoked.');
+    $this->assertSession()->responseContains('The <em>pre-detect</em> callback group was invoked.');
+    $this->assertSession()->responseContains('The <em>post-detect</em> callback group was invoked.');
+    $this->assertSession()->responseContains('The <em>pre-load</em> callback group was invoked.');
+    $this->assertSession()->responseContains('The <em>post-load</em> callback group was invoked.');
     // When the library information is cached only the 'pre-load' and
     // 'post-load' callback groups should be invoked.
     $this->drupalGet('libraries_test/cache');
-    $this->assertNoRaw('The <em>info</em> callback group was not invoked.', 'Info callback not invoked for cached libraries.');
-    $this->assertNoRaw('The <em>pre-detect</em> callback group was not invoked.', 'Pre-detect callback not invoked for cached libraries.');
-    $this->assertNoRaw('The <em>post-detect</em> callback group was not invoked.', 'Post-detect callback not invoked for cached libraries.');
-    $this->assertRaw('The <em>pre-load</em> callback group was invoked.', 'Pre-load callback invoked for cached libraries.');
-    $this->assertRaw('The <em>post-load</em> callback group was invoked.', 'Post-load callback invoked for cached libraries.');
+    $this->assertSession()->responseNotContains('The <em>info</em> callback group was not invoked.');
+    $this->assertSession()->responseNotContains('The <em>pre-detect</em> callback group was not invoked.');
+    $this->assertSession()->responseNotContains('The <em>post-detect</em> callback group was not invoked.');
+    $this->assertSession()->responseContains('The <em>pre-load</em> callback group was invoked.');
+    $this->assertSession()->responseContains('The <em>post-load</em> callback group was invoked.');
     \Drupal::state()->set('libraries_test.cache', FALSE);
   }
 
@@ -500,7 +500,7 @@ class LibrariesWebTest extends BrowserTestBase {
 
     foreach ($names as $name => $expected) {
       foreach ($extensions as $extension) {
-        $filepath = drupal_get_path('module', 'libraries') . "/tests/example/$name.$extension";
+        $filepath = \Drupal::service('extension.list.module')->getPath('libraries') . "/tests/example/$name.$extension";
         // JavaScript and CSS files appear as full URLs and with an appended
         // query string.
         if (in_array($extension, ['js', 'css'])) {
@@ -517,18 +517,18 @@ class LibrariesWebTest extends BrowserTestBase {
         $raw = $prefix . $filepath . $suffix;
         if ($expected) {
           $html_expected[] = Html::escape($raw);
-          $this->assertRaw($raw, "$label$name.$extension found.");
+          $this->assertSession()->responseContains($raw);
         }
         else {
           $html_not_expected[] = Html::escape($raw);
-          $this->assertNoRaw($raw, "$label$name.$extension not found.");
+          $this->assertSession()->responseNotContains($raw);
         }
       }
     }
 
     $html_expected = '<ul><li><pre>' . implode('</pre></li><li><pre>', $html_expected) . '</pre></li></ul>';
     $html_not_expected = '<ul><li><pre>' . implode('</pre></li><li><pre>', $html_not_expected) . '</pre></li></ul>';
-    $this->verbose("Strings of HTML that are expected to be present:{$html_expected}Strings of HTML that are expected to not be present:{$html_not_expected}");
+    dump("Strings of HTML that are expected to be present:{$html_expected}Strings of HTML that are expected to not be present:{$html_not_expected}");
   }
 
 }
diff --git a/tests/src/Kernel/ExternalLibrary/Asset/AssetLibraryTestBase.php b/tests/src/Kernel/ExternalLibrary/Asset/AssetLibraryTestBase.php
index 4f835b7..1056098 100644
--- a/tests/src/Kernel/ExternalLibrary/Asset/AssetLibraryTestBase.php
+++ b/tests/src/Kernel/ExternalLibrary/Asset/AssetLibraryTestBase.php
@@ -16,7 +16,7 @@ abstract class AssetLibraryTestBase extends LibraryTypeKernelTestBase {
    *
    * @see \Drupal\libraries\ExternalLibrary\LibraryManager::getRequiredLibraryIds()
    */
-  public static $modules = ['system'];
+  protected static $modules = ['system'];
 
   /**
    * The Drupal core library discovery.
@@ -28,7 +28,7 @@ abstract class AssetLibraryTestBase extends LibraryTypeKernelTestBase {
   /**
    * {@inheritdoc}
    */
-  protected function setUp() {
+  protected function setUp(): void {
     parent::setUp();
     $this->coreLibraryDiscovery = $this->container->get('library.discovery');
   }
diff --git a/tests/src/Kernel/ExternalLibrary/GlobalLocatorTest.php b/tests/src/Kernel/ExternalLibrary/GlobalLocatorTest.php
index 84eb86e..39a361d 100644
--- a/tests/src/Kernel/ExternalLibrary/GlobalLocatorTest.php
+++ b/tests/src/Kernel/ExternalLibrary/GlobalLocatorTest.php
@@ -15,7 +15,7 @@ class GlobalLocatorTest extends LibraryTypeKernelTestBase {
   /**
    * {@inheritdoc}
    */
-  protected function setUp() {
+  protected function setUp(): void {
     parent::setUp();
     // Assign our test stream (which points to the test php lib) to the asset
     // scheme. This gives us a scheme to work with in the test that is not
diff --git a/tests/src/Kernel/ExternalLibrary/PhpFile/PhpFileLibraryTest.php b/tests/src/Kernel/ExternalLibrary/PhpFile/PhpFileLibraryTest.php
index 10c1d2c..75098e7 100644
--- a/tests/src/Kernel/ExternalLibrary/PhpFile/PhpFileLibraryTest.php
+++ b/tests/src/Kernel/ExternalLibrary/PhpFile/PhpFileLibraryTest.php
@@ -15,7 +15,7 @@ class PhpFileLibraryTest extends LibraryTypeKernelTestBase {
   /**
    * {@inheritdoc}
    */
-  protected function setUp() {
+  protected function setUp(): void {
     parent::setUp();
 
     $this->container->set('stream_wrapper.php_file_libraries', new TestLibraryFilesStream(
diff --git a/tests/src/Kernel/LibrariesApi/LibrariesUnitTest.php b/tests/src/Kernel/LibrariesApi/LibrariesUnitTest.php
index ffcfa27..247c116 100644
--- a/tests/src/Kernel/LibrariesApi/LibrariesUnitTest.php
+++ b/tests/src/Kernel/LibrariesApi/LibrariesUnitTest.php
@@ -14,7 +14,7 @@ class LibrariesUnitTest extends KernelTestBase {
   /**
    * {@inheritdoc}
    */
-  public static $modules = ['libraries'];
+  protected static $modules = ['libraries'];
 
   /**
    * Tests libraries_get_path().
diff --git a/tests/src/Kernel/LibraryTypeKernelTestBase.php b/tests/src/Kernel/LibraryTypeKernelTestBase.php
index 8185794..b2bdf70 100644
--- a/tests/src/Kernel/LibraryTypeKernelTestBase.php
+++ b/tests/src/Kernel/LibraryTypeKernelTestBase.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\libraries\Kernel;
 
+use Prophecy\PhpUnit\ProphecyTrait;
 use Drupal\Component\Plugin\Exception\PluginException;
 use Drupal\KernelTests\KernelTestBase;
 use Drupal\libraries\ExternalLibrary\Exception\LibraryDefinitionNotFoundException;
@@ -14,6 +15,7 @@ use Drupal\libraries\ExternalLibrary\Type\LibraryTypeInterface;
  */
 abstract class LibraryTypeKernelTestBase extends KernelTestBase {
 
+  use ProphecyTrait;
   /**
    * The external library manager.
    *
@@ -38,7 +40,7 @@ abstract class LibraryTypeKernelTestBase extends KernelTestBase {
   /**
    * {@inheritdoc}
    */
-  public static $modules = ['libraries', 'libraries_test'];
+  protected static $modules = ['libraries', 'libraries_test'];
 
   /**
    * Gets the ID of the library type that is being tested.
@@ -50,7 +52,7 @@ abstract class LibraryTypeKernelTestBase extends KernelTestBase {
   /**
    * {@inheritdoc}
    */
-  protected function setUp() {
+  protected function setUp(): void {
     parent::setUp();
 
     /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
diff --git a/tests/src/Unit/Plugin/libraries/VersionDetector/LinePatternDetectorTest.php b/tests/src/Unit/Plugin/libraries/VersionDetector/LinePatternDetectorTest.php
index 9f60071..ab9ed61 100644
--- a/tests/src/Unit/Plugin/libraries/VersionDetector/LinePatternDetectorTest.php
+++ b/tests/src/Unit/Plugin/libraries/VersionDetector/LinePatternDetectorTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\libraries\Unit\Plugin\libraries\VersionDetector;
 
+use Prophecy\PhpUnit\ProphecyTrait;
 use Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface;
 use Drupal\libraries\ExternalLibrary\Version\VersionedLibraryInterface;
 use Drupal\libraries\Plugin\libraries\VersionDetector\LinePatternDetector;
@@ -18,6 +19,7 @@ use org\bovigo\vfs\vfsStream;
  */
 class LinePatternDetectorTest extends UnitTestCase {
 
+  use ProphecyTrait;
   protected $libraryId = 'test_library';
 
   /**
-- 
GitLab