cf1a84b112e34413b0394e8d53c7597f8c54ea78
[yaffs-website] / web / core / tests / Drupal / Tests / Component / ClassFinder / ClassFinderTest.php
1 <?php
2
3 namespace Drupal\Tests\Component\ClassFinder;
4
5 use Composer\Autoload\ClassLoader;
6 use Drupal\Component\ClassFinder\ClassFinder;
7 use Drupal\Tests\UnitTestCase;
8
9 /**
10  * @coversDefaultClass \Drupal\Component\ClassFinder\ClassFinder
11  * @group ClassFinder
12  */
13 class ClassFinderTest extends UnitTestCase {
14
15   /**
16    * @covers ::findFile
17    */
18   public function testFindFile() {
19     $finder = new ClassFinder();
20
21     // The full path is returned therefore only tests with
22     // assertStringEndsWith() so the test is portable.
23     $this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
24     $class = 'Not\\A\\Class';
25     $this->assertNull($finder->findFile($class));
26
27     // Register an autoloader that can find this class.
28     $loader = new ClassLoader();
29     $loader->addClassMap([$class => __FILE__]);
30     $loader->register();
31     $this->assertEquals(__FILE__, $finder->findFile($class));
32     // This shouldn't prevent us from finding the original file.
33     $this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
34
35     // Clean up the additional autoloader after the test.
36     $loader->unregister();
37   }
38
39 }