TestsAutoLoader.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /**
  3. * AutoLoader for the testing suite.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup Testing
  22. */
  23. global $wgAutoloadClasses;
  24. $testDir = __DIR__ . "/..";
  25. // phpcs:disable Generic.Files.LineLength
  26. $wgAutoloadClasses += [
  27. # tests/common
  28. 'TestSetup' => "$testDir/common/TestSetup.php",
  29. # tests/integration
  30. 'MWHttpRequestTestCase' => "$testDir/integration/includes/http/MWHttpRequestTestCase.php",
  31. # tests/parser
  32. 'DbTestPreviewer' => "$testDir/parser/DbTestPreviewer.php",
  33. 'DbTestRecorder' => "$testDir/parser/DbTestRecorder.php",
  34. 'DjVuSupport' => "$testDir/parser/DjVuSupport.php",
  35. 'MultiTestRecorder' => "$testDir/parser/MultiTestRecorder.php",
  36. 'ParserTestMockParser' => "$testDir/parser/ParserTestMockParser.php",
  37. 'ParserTestRunner' => "$testDir/parser/ParserTestRunner.php",
  38. 'ParserTestParserHook' => "$testDir/parser/ParserTestParserHook.php",
  39. 'ParserTestPrinter' => "$testDir/parser/ParserTestPrinter.php",
  40. 'ParserTestResult' => "$testDir/parser/ParserTestResult.php",
  41. 'ParserTestResultNormalizer' => "$testDir/parser/ParserTestResultNormalizer.php",
  42. 'PhpunitTestRecorder' => "$testDir/parser/PhpunitTestRecorder.php",
  43. 'TestFileEditor' => "$testDir/parser/TestFileEditor.php",
  44. 'TestFileReader' => "$testDir/parser/TestFileReader.php",
  45. 'TestRecorder' => "$testDir/parser/TestRecorder.php",
  46. 'TidySupport' => "$testDir/parser/TidySupport.php",
  47. # tests/phpunit
  48. 'EmptyResourceLoader' => "$testDir/phpunit/ResourceLoaderTestCase.php",
  49. 'HamcrestPHPUnitIntegration' => "$testDir/phpunit/HamcrestPHPUnitIntegration.php",
  50. 'LessFileCompilationTest' => "$testDir/phpunit/LessFileCompilationTest.php",
  51. 'MediaWikiCoversValidator' => "$testDir/phpunit/MediaWikiCoversValidator.php",
  52. 'MediaWikiLangTestCase' => "$testDir/phpunit/MediaWikiLangTestCase.php",
  53. 'MediaWikiPHPUnitCommand' => "$testDir/phpunit/MediaWikiPHPUnitCommand.php",
  54. 'MediaWikiPHPUnitTestListener' => "$testDir/phpunit/MediaWikiPHPUnitTestListener.php",
  55. 'MediaWikiTestCase' => "$testDir/phpunit/MediaWikiTestCase.php",
  56. 'MediaWikiTestResult' => "$testDir/phpunit/MediaWikiTestResult.php",
  57. 'MediaWikiTestRunner' => "$testDir/phpunit/MediaWikiTestRunner.php",
  58. 'PHPUnit4And6Compat' => "$testDir/phpunit/PHPUnit4And6Compat.php",
  59. 'ResourceLoaderFileModuleTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
  60. 'ResourceLoaderFileTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
  61. 'ResourceLoaderTestCase' => "$testDir/phpunit/ResourceLoaderTestCase.php",
  62. 'ResourceLoaderTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
  63. 'TestUser' => "$testDir/phpunit/includes/TestUser.php",
  64. 'TestUserRegistry' => "$testDir/phpunit/includes/TestUserRegistry.php",
  65. # tests/phpunit/includes
  66. 'PageArchiveTestBase' => "$testDir/phpunit/includes/page/PageArchiveTestBase.php",
  67. 'RevisionDbTestBase' => "$testDir/phpunit/includes/RevisionDbTestBase.php",
  68. 'RevisionTestModifyableContent' => "$testDir/phpunit/includes/RevisionTestModifyableContent.php",
  69. 'RevisionTestModifyableContentHandler' => "$testDir/phpunit/includes/RevisionTestModifyableContentHandler.php",
  70. 'TestLogger' => "$testDir/phpunit/includes/TestLogger.php",
  71. # tests/phpunit/includes/api
  72. 'ApiFormatTestBase' => "$testDir/phpunit/includes/api/format/ApiFormatTestBase.php",
  73. 'ApiQueryTestBase' => "$testDir/phpunit/includes/api/query/ApiQueryTestBase.php",
  74. 'ApiQueryContinueTestBase' => "$testDir/phpunit/includes/api/query/ApiQueryContinueTestBase.php",
  75. 'ApiTestCase' => "$testDir/phpunit/includes/api/ApiTestCase.php",
  76. 'ApiTestCaseUpload' => "$testDir/phpunit/includes/api/ApiTestCaseUpload.php",
  77. 'ApiTestContext' => "$testDir/phpunit/includes/api/ApiTestContext.php",
  78. 'ApiUploadTestCase' => "$testDir/phpunit/includes/api/ApiUploadTestCase.php",
  79. 'MockApi' => "$testDir/phpunit/includes/api/MockApi.php",
  80. 'MockApiQueryBase' => "$testDir/phpunit/includes/api/MockApiQueryBase.php",
  81. 'UserWrapper' => "$testDir/phpunit/includes/api/UserWrapper.php",
  82. 'RandomImageGenerator' => "$testDir/phpunit/includes/api/RandomImageGenerator.php",
  83. # tests/phpunit/includes/auth
  84. 'MediaWiki\\Auth\\AuthenticationRequestTestCase' =>
  85. "$testDir/phpunit/includes/auth/AuthenticationRequestTestCase.php",
  86. # tests/phpunit/includes/changes
  87. 'TestRecentChangesHelper' => "$testDir/phpunit/includes/changes/TestRecentChangesHelper.php",
  88. # tests/phpunit/includes/content
  89. 'DummyContentHandlerForTesting' =>
  90. "$testDir/phpunit/mocks/content/DummyContentHandlerForTesting.php",
  91. 'DummyContentForTesting' => "$testDir/phpunit/mocks/content/DummyContentForTesting.php",
  92. 'DummyNonTextContentHandler' => "$testDir/phpunit/mocks/content/DummyNonTextContentHandler.php",
  93. 'DummyNonTextContent' => "$testDir/phpunit/mocks/content/DummyNonTextContent.php",
  94. 'DummySerializeErrorContentHandler' =>
  95. "$testDir/phpunit/mocks/content/DummySerializeErrorContentHandler.php",
  96. 'ContentHandlerTest' => "$testDir/phpunit/includes/content/ContentHandlerTest.php",
  97. 'JavaScriptContentTest' => "$testDir/phpunit/includes/content/JavaScriptContentTest.php",
  98. 'TextContentTest' => "$testDir/phpunit/includes/content/TextContentTest.php",
  99. 'WikitextContentTest' => "$testDir/phpunit/includes/content/WikitextContentTest.php",
  100. # tests/phpunit/includes/db
  101. 'DatabaseTestHelper' => "$testDir/phpunit/includes/db/DatabaseTestHelper.php",
  102. # tests/phpunit/includes/debug
  103. 'TestDeprecatedClass' => "$testDir/phpunit/includes/debug/TestDeprecatedClass.php",
  104. 'TestDeprecatedSubclass' => "$testDir/phpunit/includes/debug/TestDeprecatedSubclass.php",
  105. # tests/phpunit/includes/diff
  106. 'CustomDifferenceEngine' => "$testDir/phpunit/includes/diff/CustomDifferenceEngine.php",
  107. 'FakeDiffOp' => "$testDir/phpunit/includes/diff/FakeDiffOp.php",
  108. # tests/phpunit/includes/externalstore
  109. 'ExternalStoreForTesting' => "$testDir/phpunit/includes/externalstore/ExternalStoreForTesting.php",
  110. # tests/phpunit/includes/logging
  111. 'LogFormatterTestCase' => "$testDir/phpunit/includes/logging/LogFormatterTestCase.php",
  112. # tests/phpunit/includes/page
  113. 'WikiPageDbTestBase' => "$testDir/phpunit/includes/page/WikiPageDbTestBase.php",
  114. # tests/phpunit/includes/parser
  115. 'ParserIntegrationTest' => "$testDir/phpunit/includes/parser/ParserIntegrationTest.php",
  116. # tests/phpunit/includes/password
  117. 'PasswordTestCase' => "$testDir/phpunit/includes/password/PasswordTestCase.php",
  118. # tests/phpunit/includes/resourceloader
  119. 'ResourceLoaderImageModuleTest' =>
  120. "$testDir/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php",
  121. 'ResourceLoaderImageModuleTestable' =>
  122. "$testDir/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php",
  123. # tests/phpunit/includes/session
  124. 'MediaWiki\\Session\\TestBagOStuff' => "$testDir/phpunit/includes/session/TestBagOStuff.php",
  125. 'MediaWiki\\Session\\TestUtils' => "$testDir/phpunit/includes/session/TestUtils.php",
  126. # tests/phpunit/includes/site
  127. 'SiteTest' => "$testDir/phpunit/includes/site/SiteTest.php",
  128. 'TestSites' => "$testDir/phpunit/includes/site/TestSites.php",
  129. # tests/phpunit/includes/specialpage
  130. 'SpecialPageTestHelper' => "$testDir/phpunit/includes/specialpage/SpecialPageTestHelper.php",
  131. 'AbstractChangesListSpecialPageTestCase' => "$testDir/phpunit/includes/specialpage/AbstractChangesListSpecialPageTestCase.php",
  132. # tests/phpunit/includes/specials
  133. 'SpecialPageTestBase' => "$testDir/phpunit/includes/specials/SpecialPageTestBase.php",
  134. 'SpecialPageExecutor' => "$testDir/phpunit/includes/specials/SpecialPageExecutor.php",
  135. # tests/phpunit/includes/Storage
  136. 'MediaWiki\Tests\Storage\McrSchemaDetection' => "$testDir/phpunit/includes/Storage/McrSchemaDetection.php",
  137. 'MediaWiki\Tests\Storage\McrSchemaOverride' => "$testDir/phpunit/includes/Storage/McrSchemaOverride.php",
  138. 'MediaWiki\Tests\Storage\McrWriteBothSchemaOverride' => "$testDir/phpunit/includes/Storage/McrWriteBothSchemaOverride.php",
  139. 'MediaWiki\Tests\Storage\McrReadNewSchemaOverride' => "$testDir/phpunit/includes/Storage/McrReadNewSchemaOverride.php",
  140. 'MediaWiki\Tests\Storage\RevisionSlotsTest' => "$testDir/phpunit/includes/Storage/RevisionSlotsTest.php",
  141. 'MediaWiki\Tests\Storage\RevisionRecordTests' => "$testDir/phpunit/includes/Storage/RevisionRecordTests.php",
  142. 'MediaWiki\Tests\Storage\RevisionStoreDbTestBase' => "$testDir/phpunit/includes/Storage/RevisionStoreDbTestBase.php",
  143. 'MediaWiki\Tests\Storage\PreMcrSchemaOverride' => "$testDir/phpunit/includes/Storage/PreMcrSchemaOverride.php",
  144. # tests/phpunit/languages
  145. 'LanguageClassesTestCase' => "$testDir/phpunit/languages/LanguageClassesTestCase.php",
  146. # tests/phpunit/includes/libs
  147. 'GenericArrayObjectTest' => "$testDir/phpunit/includes/libs/GenericArrayObjectTest.php",
  148. # tests/phpunit/maintenance
  149. 'MediaWiki\Tests\Maintenance\DumpTestCase' => "$testDir/phpunit/maintenance/DumpTestCase.php",
  150. 'MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase' => "$testDir/phpunit/maintenance/MaintenanceBaseTestCase.php",
  151. # tests/phpunit/media
  152. 'FakeDimensionFile' => "$testDir/phpunit/includes/media/FakeDimensionFile.php",
  153. 'MediaWikiMediaTestCase' => "$testDir/phpunit/includes/media/MediaWikiMediaTestCase.php",
  154. # tests/phpunit/mocks
  155. 'MockFSFile' => "$testDir/phpunit/mocks/filebackend/MockFSFile.php",
  156. 'MockFileBackend' => "$testDir/phpunit/mocks/filebackend/MockFileBackend.php",
  157. 'MockLocalRepo' => "$testDir/phpunit/mocks/filerepo/MockLocalRepo.php",
  158. 'MockBitmapHandler' => "$testDir/phpunit/mocks/media/MockBitmapHandler.php",
  159. 'MockImageHandler' => "$testDir/phpunit/mocks/media/MockImageHandler.php",
  160. 'MockSvgHandler' => "$testDir/phpunit/mocks/media/MockSvgHandler.php",
  161. 'MockDjVuHandler' => "$testDir/phpunit/mocks/media/MockDjVuHandler.php",
  162. 'MockChangesListFilter' => "$testDir/phpunit/mocks/MockChangesListFilter.php",
  163. 'MockChangesListFilterGroup' => "$testDir/phpunit/mocks/MockChangesListFilterGroup.php",
  164. 'MockWebRequest' => "$testDir/phpunit/mocks/MockWebRequest.php",
  165. 'MediaWiki\\Session\\DummySessionBackend'
  166. => "$testDir/phpunit/mocks/session/DummySessionBackend.php",
  167. 'DummySessionProvider' => "$testDir/phpunit/mocks/session/DummySessionProvider.php",
  168. 'MockMessageLocalizer' => "$testDir/phpunit/mocks/MockMessageLocalizer.php",
  169. 'MockCompletionSearchEngine' => "$testDir/phpunit/mocks/search/MockCompletionSearchEngine.php",
  170. 'MockSearchEngine' => "$testDir/phpunit/mocks/search/MockSearchEngine.php",
  171. 'MockSearchResultSet' => "$testDir/phpunit/mocks/search/MockSearchResultSet.php",
  172. 'MockSearchResult' => "$testDir/phpunit/mocks/search/MockSearchResult.php",
  173. # tests/suites
  174. 'ParserTestFileSuite' => "$testDir/phpunit/suites/ParserTestFileSuite.php",
  175. 'ParserTestTopLevelSuite' => "$testDir/phpunit/suites/ParserTestTopLevelSuite.php",
  176. ];
  177. // phpcs:enable
  178. /**
  179. * Alias any PHPUnit 4 era PHPUnit_... class
  180. * to it's PHPUnit 6 replacement. For most classes
  181. * this is a direct _ -> \ replacement, but for
  182. * some others we might need to maintain a manual
  183. * mapping. Once we drop support for PHPUnit 4 this
  184. * should be considered deprecated and eventually removed.
  185. */
  186. spl_autoload_register( function ( $class ) {
  187. if ( strpos( $class, 'PHPUnit_' ) !== 0 ) {
  188. // Skip if it doesn't start with the old prefix
  189. return;
  190. }
  191. // Classes that don't map 100%
  192. $map = [
  193. 'PHPUnit_Framework_TestSuite_DataProvider' => 'PHPUnit\Framework\DataProviderTestSuite',
  194. 'PHPUnit_Framework_Error' => 'PHPUnit\Framework\Error\Error',
  195. ];
  196. if ( isset( $map[$class] ) ) {
  197. $newForm = $map[$class];
  198. } else {
  199. $newForm = str_replace( '_', '\\', $class );
  200. }
  201. if ( class_exists( $newForm ) || interface_exists( $newForm ) ) {
  202. // If the new class name exists, alias
  203. // the old name to it.
  204. class_alias( $newForm, $class );
  205. }
  206. } );