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