| 1 |
<?php |
| 2 |
|
| 3 |
use Wikimedia\TestingAccessWrapper; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
class AutoLoaderTest extends MediaWikiIntegrationTestCase { |
| 9 |
|
| 10 |
|
| 11 |
private $oldPsr4; |
| 12 |
|
| 13 |
private $oldClassFiles; |
| 14 |
|
| 15 |
protected function setUp(): void { |
| 16 |
parent::setUp(); |
| 17 |
|
| 18 |
$this->mergeMwGlobalArrayValue( 'wgAutoloadLocalClasses', [ |
| 19 |
'TestAutoloadedLocalClass' => |
| 20 |
__DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php', |
| 21 |
] ); |
| 22 |
$this->mergeMwGlobalArrayValue( 'wgAutoloadClasses', [ |
| 23 |
'TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php', |
| 24 |
] ); |
| 25 |
|
| 26 |
$access = TestingAccessWrapper::newFromClass( AutoLoader::class ); |
| 27 |
$this->oldPsr4 = $access->psr4Namespaces; |
| 28 |
$this->oldClassFiles = $access->classFiles; |
| 29 |
AutoLoader::registerNamespaces( [ |
| 30 |
'Test\\MediaWiki\\AutoLoader\\' => __DIR__ . '/../data/autoloader/psr4' |
| 31 |
] ); |
| 32 |
AutoLoader::registerClasses( [ |
| 33 |
'TestAnotherAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAnotherAutoloadedClass.php', |
| 34 |
] ); |
| 35 |
} |
| 36 |
|
| 37 |
protected function tearDown(): void { |
| 38 |
$access = TestingAccessWrapper::newFromClass( AutoLoader::class ); |
| 39 |
$access->psr4Namespaces = $this->oldPsr4; |
| 40 |
$access->classFiles = $this->oldClassFiles; |
| 41 |
parent::tearDown(); |
| 42 |
} |
| 43 |
|
| 44 |
public function testFind() { |
| 45 |
$path = __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php'; |
| 46 |
$this->assertSame( $path, AutoLoader::find( TestAutoloadedLocalClass::class ) ); |
| 47 |
} |
| 48 |
|
| 49 |
public function testCoreClass() { |
| 50 |
$this->assertTrue( class_exists( 'TestAutoloadedLocalClass' ) ); |
| 51 |
} |
| 52 |
|
| 53 |
public function testExtensionClass() { |
| 54 |
$this->assertTrue( class_exists( 'TestAnotherAutoloadedClass' ) ); |
| 55 |
} |
| 56 |
|
| 57 |
public function testLegacyExtensionClass() { |
| 58 |
$this->assertTrue( class_exists( 'TestAutoloadedClass' ) ); |
| 59 |
} |
| 60 |
|
| 61 |
public function testPsr4() { |
| 62 |
$this->assertTrue( class_exists( 'Test\\MediaWiki\\AutoLoader\\TestFooBar' ) ); |
| 63 |
} |
| 64 |
} |