Merge ".mailmap: Correct two contributor names"
[mediawiki.git] / tests / phpunit / includes / AutoLoaderTest.php
blob565980ff0bf78570f1851f3b3e49e34705fbc49b
1 <?php
3 use Wikimedia\TestingAccessWrapper;
5 /**
6 * @covers \AutoLoader
7 */
8 class AutoLoaderTest extends MediaWikiIntegrationTestCase {
10 /** @var string[] */
11 private $oldPsr4;
12 /** @var string[] */
13 private $oldClassFiles;
15 protected function setUp(): void {
16 parent::setUp();
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 ] );
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 ] );
37 protected function tearDown(): void {
38 $access = TestingAccessWrapper::newFromClass( AutoLoader::class );
39 $access->psr4Namespaces = $this->oldPsr4;
40 $access->classFiles = $this->oldClassFiles;
41 parent::tearDown();
44 public function testFind() {
45 $path = __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php';
46 $this->assertSame( $path, AutoLoader::find( TestAutoloadedLocalClass::class ) );
49 public function testCoreClass() {
50 $this->assertTrue( class_exists( 'TestAutoloadedLocalClass' ) );
53 public function testExtensionClass() {
54 $this->assertTrue( class_exists( 'TestAnotherAutoloadedClass' ) );
57 public function testLegacyExtensionClass() {
58 $this->assertTrue( class_exists( 'TestAutoloadedClass' ) );
61 public function testPsr4() {
62 $this->assertTrue( class_exists( 'Test\\MediaWiki\\AutoLoader\\TestFooBar' ) );