3 use Wikimedia\TestingAccessWrapper
;
8 class AutoLoaderTest
extends MediaWikiIntegrationTestCase
{
13 private $oldClassFiles;
15 protected function setUp(): void
{
18 $this->mergeMwGlobalArrayValue( 'wgAutoloadLocalClasses', [
19 'TestAutoloadedLocalClass' =>
20 __DIR__
. '/../data/autoloader/TestAutoloadedLocalClass.php',
22 $this->mergeMwGlobalArrayValue( 'wgAutoloadClasses', [
23 'TestAutoloadedClass' => __DIR__
. '/../data/autoloader/TestAutoloadedClass.php',
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'
32 AutoLoader
::registerClasses( [
33 'TestAnotherAutoloadedClass' => __DIR__
. '/../data/autoloader/TestAnotherAutoloadedClass.php',
37 protected function tearDown(): void
{
38 $access = TestingAccessWrapper
::newFromClass( AutoLoader
::class );
39 $access->psr4Namespaces
= $this->oldPsr4
;
40 $access->classFiles
= $this->oldClassFiles
;
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' ) );