You are here

class ClassFinderTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php \Drupal\Tests\Component\ClassFinder\ClassFinderTest
  2. 9 core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php \Drupal\Tests\Component\ClassFinder\ClassFinderTest

@coversDefaultClass \Drupal\Component\ClassFinder\ClassFinder @group ClassFinder

Hierarchy

  • class \Drupal\Tests\Component\ClassFinder\ClassFinderTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of ClassFinderTest

File

core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php, line 13

Namespace

Drupal\Tests\Component\ClassFinder
View source
class ClassFinderTest extends TestCase {

  /**
   * @covers ::findFile
   */
  public function testFindFile() {
    $finder = new ClassFinder();

    // The full path is returned therefore only tests with
    // assertStringEndsWith() so the test is portable.
    $this
      ->assertStringEndsWith('core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php', $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('core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php', $finder
      ->findFile(ClassFinderTest::class));

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

}

Members