addClassMap example

return $this->testClasses;
      }
    }
    $list = [];

    $classmap = $this->findAllClassFiles($extension);

    // Prevent expensive class loader lookups for each reflected test class by     // registering the complete classmap of test classes to the class loader.     // This also ensures that test classes are loaded from the discovered     // pathnames; a namespace/classname mismatch will throw an exception.     $this->classLoader->addClassMap($classmap);

    foreach ($classmap as $classname => $pathname) {
      $finder = MockFileFinder::create($pathname);
      $parser = new StaticReflectionParser($classname$finder, TRUE);
      try {
        $info = static::getTestInfo($classname$parser->getDocComment());
      }
      catch (MissingGroupException $e) {
        // If the class name ends in Test and is not a migrate table dump.         if (preg_match('/Test$/', $classname) && !str_contains($classname, 'migrate_drupal\Tests\Table')) {
          throw $e;
        }
$finder = new ClassFinder();

    // The full path is returned therefore only tests with     // assertStringEndsWith() so the test is portable.     $expected_path = str_replace('/', DIRECTORY_SEPARATOR, 'core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php');
    $this->assertStringEndsWith($expected_path$finder->findFile(ClassFinderTest::class));
    $class = 'Not\\A\\Class';
    $this->assertNull($finder->findFile($class));

    // Register an autoloader that can find this class.     $loader = new ClassLoader();
    $loader->addClassMap([$class => __FILE__]);
    $loader->register();
    $this->assertEquals(__FILE__, $finder->findFile($class));
    // This shouldn't prevent us from finding the original file.     $this->assertStringEndsWith($expected_path$finder->findFile(ClassFinderTest::class));

    // Clean up the additional autoloader after the test.     $loader->unregister();
  }

}
Home | Imprint | This part of the site doesn't use cookies.