Provide PHPUnit 4 and 6 compatibility layer
[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 'TidySupport' => "$testDir/parser/TidySupport.php",
52
53 # tests/phpunit
54 'MediaWikiTestCase' => "$testDir/phpunit/MediaWikiTestCase.php",
55 'MediaWikiPHPUnitTestListener' => "$testDir/phpunit/MediaWikiPHPUnitTestListener.php",
56 'MediaWikiLangTestCase' => "$testDir/phpunit/MediaWikiLangTestCase.php",
57 'ResourceLoaderTestCase' => "$testDir/phpunit/ResourceLoaderTestCase.php",
58 'ResourceLoaderTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
59 'ResourceLoaderFileTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
60 'ResourceLoaderFileModuleTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
61 'EmptyResourceLoader' => "$testDir/phpunit/ResourceLoaderTestCase.php",
62 'TestUser' => "$testDir/phpunit/includes/TestUser.php",
63 'TestUserRegistry' => "$testDir/phpunit/includes/TestUserRegistry.php",
64 'LessFileCompilationTest' => "$testDir/phpunit/LessFileCompilationTest.php",
65 'MediaWikiCoversValidator' => "$testDir/phpunit/MediaWikiCoversValidator.php",
66 'PHPUnit4And6Compat' => "$testDir/phpunit/PHPUnit4And6Compat.php",
67
68 # tests/phpunit/includes
69 'RevisionDbTestBase' => "$testDir/phpunit/includes/RevisionDbTestBase.php",
70 'RevisionTestModifyableContent' => "$testDir/phpunit/includes/RevisionTestModifyableContent.php",
71 'RevisionTestModifyableContentHandler' => "$testDir/phpunit/includes/RevisionTestModifyableContentHandler.php",
72 'TestLogger' => "$testDir/phpunit/includes/TestLogger.php",
73
74 # tests/phpunit/includes/api
75 'ApiFormatTestBase' => "$testDir/phpunit/includes/api/format/ApiFormatTestBase.php",
76 'ApiQueryTestBase' => "$testDir/phpunit/includes/api/query/ApiQueryTestBase.php",
77 'ApiQueryContinueTestBase' => "$testDir/phpunit/includes/api/query/ApiQueryContinueTestBase.php",
78 'ApiTestCase' => "$testDir/phpunit/includes/api/ApiTestCase.php",
79 'ApiTestCaseUpload' => "$testDir/phpunit/includes/api/ApiTestCaseUpload.php",
80 'ApiTestContext' => "$testDir/phpunit/includes/api/ApiTestContext.php",
81 'MockApi' => "$testDir/phpunit/includes/api/MockApi.php",
82 'MockApiQueryBase' => "$testDir/phpunit/includes/api/MockApiQueryBase.php",
83 'UserWrapper' => "$testDir/phpunit/includes/api/UserWrapper.php",
84 'RandomImageGenerator' => "$testDir/phpunit/includes/api/RandomImageGenerator.php",
85
86 # tests/phpunit/includes/auth
87 'MediaWiki\\Auth\\AuthenticationRequestTestCase' =>
88 "$testDir/phpunit/includes/auth/AuthenticationRequestTestCase.php",
89
90 # tests/phpunit/includes/changes
91 'TestRecentChangesHelper' => "$testDir/phpunit/includes/changes/TestRecentChangesHelper.php",
92
93 # tests/phpunit/includes/content
94 'DummyContentHandlerForTesting' =>
95 "$testDir/phpunit/mocks/content/DummyContentHandlerForTesting.php",
96 'DummyContentForTesting' => "$testDir/phpunit/mocks/content/DummyContentForTesting.php",
97 'DummyNonTextContentHandler' => "$testDir/phpunit/mocks/content/DummyNonTextContentHandler.php",
98 'DummyNonTextContent' => "$testDir/phpunit/mocks/content/DummyNonTextContent.php",
99 'ContentHandlerTest' => "$testDir/phpunit/includes/content/ContentHandlerTest.php",
100 'JavaScriptContentTest' => "$testDir/phpunit/includes/content/JavaScriptContentTest.php",
101 'TextContentTest' => "$testDir/phpunit/includes/content/TextContentTest.php",
102 'WikitextContentTest' => "$testDir/phpunit/includes/content/WikitextContentTest.php",
103
104 # tests/phpunit/includes/db
105 'DatabaseTestHelper' => "$testDir/phpunit/includes/db/DatabaseTestHelper.php",
106
107 # tests/phpunit/includes/diff
108 'FakeDiffOp' => "$testDir/phpunit/includes/diff/FakeDiffOp.php",
109
110 # tests/phpunit/includes/externalstore
111 'ExternalStoreForTesting' => "$testDir/phpunit/includes/externalstore/ExternalStoreForTesting.php",
112
113 # tests/phpunit/includes/logging
114 'LogFormatterTestCase' => "$testDir/phpunit/includes/logging/LogFormatterTestCase.php",
115
116 # tests/phpunit/includes/page
117 'WikiPageDbTestBase' => "$testDir/phpunit/includes/page/WikiPageDbTestBase.php",
118
119 # tests/phpunit/includes/parser
120 'ParserIntegrationTest' => "$testDir/phpunit/includes/parser/ParserIntegrationTest.php",
121
122 # tests/phpunit/includes/password
123 'PasswordTestCase' => "$testDir/phpunit/includes/password/PasswordTestCase.php",
124
125 # tests/phpunit/includes/resourceloader
126 'ResourceLoaderImageModuleTest' =>
127 "$testDir/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php",
128 'ResourceLoaderImageModuleTestable' =>
129 "$testDir/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php",
130
131 # tests/phpunit/includes/session
132 'MediaWiki\\Session\\TestBagOStuff' => "$testDir/phpunit/includes/session/TestBagOStuff.php",
133 'MediaWiki\\Session\\TestUtils' => "$testDir/phpunit/includes/session/TestUtils.php",
134
135 # tests/phpunit/includes/site
136 'SiteTest' => "$testDir/phpunit/includes/site/SiteTest.php",
137 'TestSites' => "$testDir/phpunit/includes/site/TestSites.php",
138
139 # tests/phpunit/includes/specialpage
140 'SpecialPageTestHelper' => "$testDir/phpunit/includes/specialpage/SpecialPageTestHelper.php",
141 'AbstractChangesListSpecialPageTestCase' => "$testDir/phpunit/includes/specialpage/AbstractChangesListSpecialPageTestCase.php",
142
143 # tests/phpunit/includes/specials
144 'SpecialPageTestBase' => "$testDir/phpunit/includes/specials/SpecialPageTestBase.php",
145 'SpecialPageExecutor' => "$testDir/phpunit/includes/specials/SpecialPageExecutor.php",
146
147 # tests/phpunit/languages
148 'LanguageClassesTestCase' => "$testDir/phpunit/languages/LanguageClassesTestCase.php",
149
150 # tests/phpunit/includes/libs
151 'GenericArrayObjectTest' => "$testDir/phpunit/includes/libs/GenericArrayObjectTest.php",
152
153 # tests/phpunit/maintenance
154 'MediaWiki\Tests\Maintenance\DumpTestCase' => "$testDir/phpunit/maintenance/DumpTestCase.php",
155 'MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase' => "$testDir/phpunit/maintenance/MaintenanceBaseTestCase.php",
156
157 # tests/phpunit/media
158 'FakeDimensionFile' => "$testDir/phpunit/includes/media/FakeDimensionFile.php",
159 'MediaWikiMediaTestCase' => "$testDir/phpunit/includes/media/MediaWikiMediaTestCase.php",
160
161 # tests/phpunit/mocks
162 'MockFSFile' => "$testDir/phpunit/mocks/filebackend/MockFSFile.php",
163 'MockFileBackend' => "$testDir/phpunit/mocks/filebackend/MockFileBackend.php",
164 'MockLocalRepo' => "$testDir/phpunit/mocks/filerepo/MockLocalRepo.php",
165 'MockBitmapHandler' => "$testDir/phpunit/mocks/media/MockBitmapHandler.php",
166 'MockImageHandler' => "$testDir/phpunit/mocks/media/MockImageHandler.php",
167 'MockSvgHandler' => "$testDir/phpunit/mocks/media/MockSvgHandler.php",
168 'MockDjVuHandler' => "$testDir/phpunit/mocks/media/MockDjVuHandler.php",
169 'MockChangesListFilter' => "$testDir/phpunit/mocks/MockChangesListFilter.php",
170 'MockChangesListFilterGroup' => "$testDir/phpunit/mocks/MockChangesListFilterGroup.php",
171 'MockWebRequest' => "$testDir/phpunit/mocks/MockWebRequest.php",
172 'MediaWiki\\Session\\DummySessionBackend'
173 => "$testDir/phpunit/mocks/session/DummySessionBackend.php",
174 'DummySessionProvider' => "$testDir/phpunit/mocks/session/DummySessionProvider.php",
175
176 # tests/suites
177 'ParserTestFileSuite' => "$testDir/phpunit/suites/ParserTestFileSuite.php",
178 'ParserTestTopLevelSuite' => "$testDir/phpunit/suites/ParserTestTopLevelSuite.php",
179 ];
180 // phpcs:enable
181
182 /**
183 * Alias any PHPUnit 4 era PHPUnit_... class
184 * to it's PHPUnit 6 replacement. For most classes
185 * this is a direct _ -> \ replacement, but for
186 * some others we might need to maintain a manual
187 * mapping. Once we drop support for PHPUnit 4 this
188 * should be considered deprecated and eventually removed.
189 */
190 spl_autoload_register( function ( $class ) {
191 if ( strpos( $class, 'PHPUnit_' ) !== 0 ) {
192 // Skip if it doesn't start with the old prefix
193 return;
194 }
195
196 // Classes that don't map 100%
197 $map = [
198 'PHPUnit_Framework_TestSuite_DataProvider' => 'PHPUnit\Framework\DataProviderTestSuite'
199 ];
200
201 if ( isset( $map[$class] ) ) {
202 $newForm = $map[$class];
203 } else {
204 $newForm = str_replace( '_', '\\', $class );
205 }
206
207 if ( class_exists( $newForm ) ) {
208 // If the new class name exists, alias
209 // the old name to it.
210 class_alias( $newForm, $class );
211 }
212 } );