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