comparison core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace Drupal\Tests\Component\ClassFinder;
4
5 use Composer\Autoload\ClassLoader;
6 use Drupal\Component\ClassFinder\ClassFinder;
7 use PHPUnit\Framework\TestCase;
8
9 /**
10 * @coversDefaultClass \Drupal\Component\ClassFinder\ClassFinder
11 * @group ClassFinder
12 */
13 class ClassFinderTest extends TestCase {
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/Component/ClassFinder/ClassFinderTest.php', $finder->findFile(ClassFinderTest::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/Component/ClassFinder/ClassFinderTest.php', $finder->findFile(ClassFinderTest::class));
34
35 // Clean up the additional autoloader after the test.
36 $loader->unregister();
37 }
38
39 }