annotate core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php @ 19:fa3358dc1485 tip

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