ClassFinderTest.php in Drupal 9
File
core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php
View source
<?php
namespace Drupal\Tests\Component\ClassFinder;
use Composer\Autoload\ClassLoader;
use Drupal\Component\ClassFinder\ClassFinder;
use PHPUnit\Framework\TestCase;
class ClassFinderTest extends TestCase {
public function testFindFile() {
$finder = new ClassFinder();
$this
->assertStringEndsWith('core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php', $finder
->findFile(ClassFinderTest::class));
$class = 'Not\\A\\Class';
$this
->assertNull($finder
->findFile($class));
$loader = new ClassLoader();
$loader
->addClassMap([
$class => __FILE__,
]);
$loader
->register();
$this
->assertEquals(__FILE__, $finder
->findFile($class));
$this
->assertStringEndsWith('core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php', $finder
->findFile(ClassFinderTest::class));
$loader
->unregister();
}
}