1657e8185234afc56d36e7c3fc6bab9bc4482387
[lhc/web/wiklou.git] / tests / common / TestsAutoLoader.php
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
24 global $wgAutoloadClasses;
25 $testDir = __DIR__ . "/..";
26
27 // phpcs:disable Generic.Files.LineLength
28 $wgAutoloadClasses += [
29
30 # tests/common
31 'TestSetup' => "$testDir/common/TestSetup.php",
32
33 # tests/integration
34 'MWHttpRequestTestCase' => "$testDir/integration/includes/http/MWHttpRequestTestCase.php",
35
36 # tests/parser
37 'DbTestPreviewer' => "$testDir/parser/DbTestPreviewer.php",
38 'DbTestRecorder' => "$testDir/parser/DbTestRecorder.php",
39 'DjVuSupport' => "$testDir/parser/DjVuSupport.php",
40 'MultiTestRecorder' => "$testDir/parser/MultiTestRecorder.php",
41 'ParserTestMockParser' => "$testDir/parser/ParserTestMockParser.php",
42 'ParserTestRunner' => "$testDir/parser/ParserTestRunner.php",
43 'ParserTestParserHook' => "$testDir/parser/ParserTestParserHook.php",
44 'ParserTestPrinter' => "$testDir/parser/ParserTestPrinter.php",
45 'ParserTestResult' => "$testDir/parser/ParserTestResult.php",
46 'ParserTestResultNormalizer' => "$testDir/parser/ParserTestResultNormalizer.php",
47 'PhpunitTestRecorder' => "$testDir/parser/PhpunitTestRecorder.php",
48 'TestFileEditor' => "$testDir/parser/TestFileEditor.php",
49 'TestFileReader' => "$testDir/parser/TestFileReader.php",
50 'TestRecorder' => "$testDir/parser/TestRecorder.php",
51
52 # tests/phpunit
53 'EmptyResourceLoader' => "$testDir/phpunit/ResourceLoaderTestCase.php",
54 'HamcrestPHPUnitIntegration' => "$testDir/phpunit/HamcrestPHPUnitIntegration.php",
55 'LessFileCompilationTest' => "$testDir/phpunit/LessFileCompilationTest.php",
56 'MediaWikiCoversValidator' => "$testDir/phpunit/MediaWikiCoversValidator.php",
57 'MediaWikiGroupValidator' => "$testDir/phpunit/MediaWikiGroupValidator.php",
58 'MediaWikiLangTestCase' => "$testDir/phpunit/MediaWikiLangTestCase.php",
59 'MediaWikiLoggerPHPUnitTestListener' => "$testDir/phpunit/MediaWikiLoggerPHPUnitTestListener.php",
60 'MediaWikiPHPUnitCommand' => "$testDir/phpunit/MediaWikiPHPUnitCommand.php",
61 'MediaWikiPHPUnitResultPrinter' => "$testDir/phpunit/MediaWikiPHPUnitResultPrinter.php",
62 'MediaWikiPHPUnitTestListener' => "$testDir/phpunit/MediaWikiPHPUnitTestListener.php",
63 'MediaWikiTestCase' => "$testDir/phpunit/MediaWikiIntegrationTestCase.php",
64 'MediaWikiTestCaseTrait' => "$testDir/phpunit/MediaWikiTestCaseTrait.php",
65 'MediaWikiUnitTestCase' => "$testDir/phpunit/MediaWikiUnitTestCase.php",
66 'MediaWikiIntegrationTestCase' => "$testDir/phpunit/MediaWikiIntegrationTestCase.php",
67 'MediaWikiTestResult' => "$testDir/phpunit/MediaWikiTestResult.php",
68 'MediaWikiTestRunner' => "$testDir/phpunit/MediaWikiTestRunner.php",
69 'PHPUnit4And6Compat' => "$testDir/phpunit/PHPUnit4And6Compat.php",
70 'ResourceLoaderFileModuleTestingSubclass' => "$testDir/phpunit/ResourceLoaderTestCase.php",
71 'ResourceLoaderFileTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
72 'ResourceLoaderTestCase' => "$testDir/phpunit/ResourceLoaderTestCase.php",
73 'ResourceLoaderTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
74 'TestLocalisationCache' => "$testDir/phpunit/includes/TestLocalisationCache.php",
75 'TestUser' => "$testDir/phpunit/includes/TestUser.php",
76 'TestUserRegistry' => "$testDir/phpunit/includes/TestUserRegistry.php",
77
78 # tests/phpunit/includes
79 'FactoryArgTestTrait' => "$testDir/phpunit/unit/includes/FactoryArgTestTrait.php",
80 'PageArchiveTestBase' => "$testDir/phpunit/includes/page/PageArchiveTestBase.php",
81 'RevisionDbTestBase' => "$testDir/phpunit/includes/RevisionDbTestBase.php",
82 'RevisionTestModifyableContent' => "$testDir/phpunit/includes/RevisionTestModifyableContent.php",
83 'RevisionTestModifyableContentHandler' => "$testDir/phpunit/includes/RevisionTestModifyableContentHandler.php",
84 'TestLogger' => "$testDir/phpunit/includes/TestLogger.php",
85
86 # tests/phpunit/includes/api
87 'ApiFormatTestBase' => "$testDir/phpunit/includes/api/format/ApiFormatTestBase.php",
88 'ApiQueryTestBase' => "$testDir/phpunit/includes/api/query/ApiQueryTestBase.php",
89 'ApiQueryContinueTestBase' => "$testDir/phpunit/includes/api/query/ApiQueryContinueTestBase.php",
90 'ApiTestCase' => "$testDir/phpunit/includes/api/ApiTestCase.php",
91 'ApiTestContext' => "$testDir/phpunit/includes/api/ApiTestContext.php",
92 'ApiUploadTestCase' => "$testDir/phpunit/includes/api/ApiUploadTestCase.php",
93 'MockApi' => "$testDir/phpunit/includes/api/MockApi.php",
94 'MockApiQueryBase' => "$testDir/phpunit/includes/api/MockApiQueryBase.php",
95 'UserWrapper' => "$testDir/phpunit/includes/api/UserWrapper.php",
96 'RandomImageGenerator' => "$testDir/phpunit/includes/api/RandomImageGenerator.php",
97
98 # tests/phpunit/includes/auth
99 'MediaWiki\\Auth\\AuthenticationRequestTestCase' =>
100 "$testDir/phpunit/includes/auth/AuthenticationRequestTestCase.php",
101
102 # tests/phpunit/includes/block
103 'MediaWiki\\Tests\\Block\\Restriction\\RestrictionTestCase' => "$testDir/phpunit/includes/block/Restriction/RestrictionTestCase.php",
104
105 # tests/phpunit/includes/changes
106 'TestRecentChangesHelper' => "$testDir/phpunit/includes/changes/TestRecentChangesHelper.php",
107
108 # tests/phpunit/includes/config
109 'TestAllServiceOptionsUsed' => "$testDir/phpunit/includes/config/TestAllServiceOptionsUsed.php",
110 'LoggedServiceOptions' => "$testDir/phpunit/includes/config/LoggedServiceOptions.php",
111
112 # tests/phpunit/includes/content
113 'DummyContentHandlerForTesting' =>
114 "$testDir/phpunit/mocks/content/DummyContentHandlerForTesting.php",
115 'DummyContentForTesting' => "$testDir/phpunit/mocks/content/DummyContentForTesting.php",
116 'DummyNonTextContentHandler' => "$testDir/phpunit/mocks/content/DummyNonTextContentHandler.php",
117 'DummyNonTextContent' => "$testDir/phpunit/mocks/content/DummyNonTextContent.php",
118 'DummySerializeErrorContentHandler' =>
119 "$testDir/phpunit/mocks/content/DummySerializeErrorContentHandler.php",
120 'ContentHandlerTest' => "$testDir/phpunit/includes/content/ContentHandlerTest.php",
121 'JavaScriptContentTest' => "$testDir/phpunit/includes/content/JavaScriptContentTest.php",
122 'TextContentTest' => "$testDir/phpunit/includes/content/TextContentTest.php",
123 'WikitextContentTest' => "$testDir/phpunit/includes/content/WikitextContentTest.php",
124
125 # tests/phpunit/includes/db
126 'DatabaseTestHelper' => "$testDir/phpunit/includes/db/DatabaseTestHelper.php",
127
128 # tests/phpunit/includes/debug
129 'TestDeprecatedClass' => "$testDir/phpunit/includes/debug/TestDeprecatedClass.php",
130 'TestDeprecatedSubclass' => "$testDir/phpunit/includes/debug/TestDeprecatedSubclass.php",
131
132 # tests/phpunit/includes/diff
133 'CustomDifferenceEngine' => "$testDir/phpunit/includes/diff/CustomDifferenceEngine.php",
134 'FakeDiffOp' => "$testDir/phpunit/includes/diff/FakeDiffOp.php",
135
136 # tests/phpunit/includes/externalstore
137 'ExternalStoreForTesting' => "$testDir/phpunit/includes/externalstore/ExternalStoreForTesting.php",
138
139 # tests/phpunit/includes/logging
140 'LogFormatterTestCase' => "$testDir/phpunit/includes/logging/LogFormatterTestCase.php",
141
142 # tests/phpunit/includes/page
143 'WikiPageDbTestBase' => "$testDir/phpunit/includes/page/WikiPageDbTestBase.php",
144
145 # tests/phpunit/includes/parser
146 'ParserIntegrationTest' => "$testDir/phpunit/suites/ParserIntegrationTest.php",
147
148 # tests/phpunit/includes/password
149 'PasswordTestCase' => "$testDir/phpunit/includes/password/PasswordTestCase.php",
150
151 # tests/phpunit/includes/resourceloader
152 'ResourceLoaderImageModuleTest' =>
153 "$testDir/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php",
154 'ResourceLoaderImageModuleTestable' =>
155 "$testDir/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php",
156
157 # tests/phpunit/includes/session
158 'MediaWiki\\Session\\TestBagOStuff' => "$testDir/phpunit/includes/session/TestBagOStuff.php",
159 'MediaWiki\\Session\\TestUtils' => "$testDir/phpunit/includes/session/TestUtils.php",
160
161 # tests/phpunit/includes/site
162 'SiteTest' => "$testDir/phpunit/includes/site/SiteTest.php",
163 'TestSites' => "$testDir/phpunit/includes/site/TestSites.php",
164
165 # tests/phpunit/includes/specialpage
166 'SpecialPageTestHelper' => "$testDir/phpunit/includes/specialpage/SpecialPageTestHelper.php",
167 'AbstractChangesListSpecialPageTestCase' => "$testDir/phpunit/includes/specialpage/AbstractChangesListSpecialPageTestCase.php",
168 'FormSpecialPageTestCase' => "$testDir/phpunit/includes/specialpage/FormSpecialPageTestCase.php",
169
170 # tests/phpunit/includes/specials
171 'SpecialPageTestBase' => "$testDir/phpunit/includes/specials/SpecialPageTestBase.php",
172 'SpecialPageExecutor' => "$testDir/phpunit/includes/specials/SpecialPageExecutor.php",
173
174 # tests/phpunit/includes/Revision
175 'MediaWiki\Tests\Revision\McrSchemaDetection' => "$testDir/phpunit/includes/Revision/McrSchemaDetection.php",
176 'MediaWiki\Tests\Revision\McrSchemaOverride' => "$testDir/phpunit/includes/Revision/McrSchemaOverride.php",
177 'MediaWiki\Tests\Revision\McrWriteBothSchemaOverride' => "$testDir/phpunit/includes/Revision/McrWriteBothSchemaOverride.php",
178 'MediaWiki\Tests\Revision\McrReadNewSchemaOverride' => "$testDir/phpunit/includes/Revision/McrReadNewSchemaOverride.php",
179 'MediaWiki\Tests\Revision\RevisionSlotsTest' => "$testDir/phpunit/includes/Revision/RevisionSlotsTest.php",
180 'MediaWiki\Tests\Revision\RevisionRecordTests' => "$testDir/phpunit/includes/Revision/RevisionRecordTests.php",
181 'MediaWiki\Tests\Revision\RevisionStoreDbTestBase' => "$testDir/phpunit/includes/Revision/RevisionStoreDbTestBase.php",
182 'MediaWiki\Tests\Revision\RevisionStoreRecordTest' => "$testDir/phpunit/includes/Revision/RevisionStoreRecordTest.php",
183
184 # tests/phpunit/languages
185 'LanguageClassesTestCase' => "$testDir/phpunit/languages/LanguageClassesTestCase.php",
186
187 # tests/phpunit/includes/libs
188 'GenericArrayObjectTest' => "$testDir/phpunit/includes/libs/GenericArrayObjectTest.php",
189 'Wikimedia\ParamValidator\TypeDef\TypeDefTestCase' => "$testDir/phpunit/includes/libs/ParamValidator/TypeDef/TypeDefTestCase.php",
190
191 # tests/phpunit/maintenance
192 'MediaWiki\Tests\Maintenance\DumpAsserter' => "$testDir/phpunit/maintenance/DumpAsserter.php",
193 'MediaWiki\Tests\Maintenance\DumpTestCase' => "$testDir/phpunit/maintenance/DumpTestCase.php",
194 'MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase' => "$testDir/phpunit/maintenance/MaintenanceBaseTestCase.php",
195
196 # tests/phpunit/media
197 'FakeDimensionFile' => "$testDir/phpunit/includes/media/FakeDimensionFile.php",
198 'MediaWikiMediaTestCase' => "$testDir/phpunit/includes/media/MediaWikiMediaTestCase.php",
199
200 # tests/phpunit/mocks
201 'MockFSFile' => "$testDir/phpunit/mocks/filebackend/MockFSFile.php",
202 'MockFileBackend' => "$testDir/phpunit/mocks/filebackend/MockFileBackend.php",
203 'MockLocalRepo' => "$testDir/phpunit/mocks/filerepo/MockLocalRepo.php",
204 'MockBitmapHandler' => "$testDir/phpunit/mocks/media/MockBitmapHandler.php",
205 'MockImageHandler' => "$testDir/phpunit/mocks/media/MockImageHandler.php",
206 'MockSvgHandler' => "$testDir/phpunit/mocks/media/MockSvgHandler.php",
207 'MockDjVuHandler' => "$testDir/phpunit/mocks/media/MockDjVuHandler.php",
208 'MockChangesListFilter' => "$testDir/phpunit/mocks/MockChangesListFilter.php",
209 'MockChangesListFilterGroup' => "$testDir/phpunit/mocks/MockChangesListFilterGroup.php",
210 'MockWebRequest' => "$testDir/phpunit/mocks/MockWebRequest.php",
211 'MediaWiki\\Session\\DummySessionBackend'
212 => "$testDir/phpunit/mocks/session/DummySessionBackend.php",
213 'DummySessionProvider' => "$testDir/phpunit/mocks/session/DummySessionProvider.php",
214 'MockMessageLocalizer' => "$testDir/phpunit/mocks/MockMessageLocalizer.php",
215 'MockCompletionSearchEngine' => "$testDir/phpunit/mocks/search/MockCompletionSearchEngine.php",
216 'MockSearchEngine' => "$testDir/phpunit/mocks/search/MockSearchEngine.php",
217 'MockSearchResultSet' => "$testDir/phpunit/mocks/search/MockSearchResultSet.php",
218 'MockSearchResult' => "$testDir/phpunit/mocks/search/MockSearchResult.php",
219
220 # tests/phpunit/unit/includes
221 'BadFileLookupTest' => "$testDir/phpunit/unit/includes/BadFileLookupTest.php",
222
223 # tests/phpunit/unit/includes/filebackend
224 'FileBackendGroupTestTrait' => "$testDir/phpunit/unit/includes/filebackend/FileBackendGroupTestTrait.php",
225
226 # tests/phpunit/unit/includes/language
227 'LanguageFallbackTestTrait' => "$testDir/phpunit/unit/includes/language/LanguageFallbackTestTrait.php",
228
229 # tests/phpunit/unit/includes/libs/filebackend/fsfile
230 'TempFSFileTestTrait' => "$testDir/phpunit/unit/includes/libs/filebackend/fsfile/TempFSFileTestTrait.php",
231
232 # tests/suites
233 'ParserTestFileSuite' => "$testDir/phpunit/suites/ParserTestFileSuite.php",
234 'ParserTestTopLevelSuite' => "$testDir/phpunit/suites/ParserTestTopLevelSuite.php",
235 ];
236 // phpcs:enable
237
238 /**
239 * Alias any PHPUnit 4 era PHPUnit_... class
240 * to it's PHPUnit 6 replacement. For most classes
241 * this is a direct _ -> \ replacement, but for
242 * some others we might need to maintain a manual
243 * mapping. Once we drop support for PHPUnit 4 this
244 * should be considered deprecated and eventually removed.
245 */
246 spl_autoload_register( function ( $class ) {
247 if ( strpos( $class, 'PHPUnit_' ) !== 0 ) {
248 // Skip if it doesn't start with the old prefix
249 return;
250 }
251
252 // Classes that don't map 100%
253 $map = [
254 'PHPUnit_Framework_TestSuite_DataProvider' => 'PHPUnit\Framework\DataProviderTestSuite',
255 'PHPUnit_Framework_Error' => 'PHPUnit\Framework\Error\Error',
256 ];
257
258 $newForm = $map[$class] ?? str_replace( '_', '\\', $class );
259
260 if ( class_exists( $newForm ) || interface_exists( $newForm ) ) {
261 // If the new class name exists, alias
262 // the old name to it.
263 class_alias( $newForm, $class );
264 }
265 } );