AutoLoaderTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @covers AutoLoader
  4. */
  5. class AutoLoaderTest extends MediaWikiTestCase {
  6. private $oldPsr4;
  7. protected function setUp() {
  8. parent::setUp();
  9. // Fancy dance to trigger a rebuild of AutoLoader::$autoloadLocalClassesLower
  10. $this->mergeMwGlobalArrayValue( 'wgAutoloadLocalClasses', [
  11. 'TestAutoloadedLocalClass' =>
  12. __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php',
  13. 'TestAutoloadedCamlClass' =>
  14. __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php',
  15. 'TestAutoloadedSerializedClass' =>
  16. __DIR__ . '/../data/autoloader/TestAutoloadedSerializedClass.php',
  17. ] );
  18. AutoLoader::resetAutoloadLocalClassesLower();
  19. $this->mergeMwGlobalArrayValue( 'wgAutoloadClasses', [
  20. 'TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php',
  21. ] );
  22. $this->oldPsr4 = AutoLoader::$psr4Namespaces;
  23. AutoLoader::$psr4Namespaces['Test\\MediaWiki\\AutoLoader\\'] =
  24. __DIR__ . '/../data/autoloader/psr4';
  25. }
  26. protected function tearDown() {
  27. AutoLoader::$psr4Namespaces = $this->oldPsr4;
  28. parent::tearDown();
  29. }
  30. public function testCoreClass() {
  31. $this->assertTrue( class_exists( 'TestAutoloadedLocalClass' ) );
  32. }
  33. public function testExtensionClass() {
  34. $this->assertTrue( class_exists( 'TestAutoloadedClass' ) );
  35. }
  36. public function testWrongCaseClass() {
  37. $this->setMwGlobals( 'wgAutoloadAttemptLowercase', true );
  38. $this->assertTrue( class_exists( 'testautoLoadedcamlCLASS' ) );
  39. }
  40. public function testWrongCaseSerializedClass() {
  41. $this->setMwGlobals( 'wgAutoloadAttemptLowercase', true );
  42. $dummyCereal = 'O:29:"testautoloadedserializedclass":0:{}';
  43. $uncerealized = unserialize( $dummyCereal );
  44. $this->assertFalse( $uncerealized instanceof __PHP_Incomplete_Class,
  45. "unserialize() can load classes case-insensitively." );
  46. }
  47. public function testPsr4() {
  48. $this->assertTrue( class_exists( 'Test\\MediaWiki\\AutoLoader\\TestFooBar' ) );
  49. }
  50. }