Do not insert page titles into querycache.qc_value
[lhc/web/wiklou.git] / tests / phpunit / bootstrap.php
1 <?php
2
3 /**
4 * PHPUnit bootstrap file.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @file
22 * @ingroup Testing
23 */
24
25 if ( PHP_SAPI !== 'cli' ) {
26 die( 'This file is only meant to be executed indirectly by PHPUnit\'s bootstrap process!' );
27 }
28
29 /**
30 * PHPUnit includes the bootstrap file inside a method body, while most MediaWiki startup files
31 * assume to be included in the global scope.
32 * This utility provides a way to include these files: it makes all globals available in the
33 * inclusion scope before including the file, then exports all new or changed globals.
34 *
35 * @param string $fileName the file to include
36 */
37 function wfRequireOnceInGlobalScope( $fileName ) {
38 // phpcs:disable MediaWiki.Usage.ForbiddenFunctions.extract
39 extract( $GLOBALS, EXTR_REFS | EXTR_SKIP );
40 // phpcs:enable
41
42 require_once $fileName;
43
44 foreach ( get_defined_vars() as $varName => $value ) {
45 $GLOBALS[$varName] = $value;
46 }
47 }
48
49 define( 'MEDIAWIKI', true );
50 define( 'MW_PHPUNIT_TEST', true );
51
52 $IP = realpath( __DIR__ . '/../../' );
53 // We don't use a settings file here but some code still assumes that one exists
54 define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" );
55
56 // these variables must be defined before setup runs
57 $GLOBALS['IP'] = $IP;
58
59 require_once "$IP/tests/common/TestSetup.php";
60 TestSetup::snapshotGlobals();
61
62 // Faking in lieu of Setup.php
63 $GLOBALS['wgScopeTest'] = 'MediaWiki Setup.php scope test';
64 $GLOBALS['wgCommandLineMode'] = true;
65 $GLOBALS['wgAutoloadClasses'] = [];
66
67 wfRequireOnceInGlobalScope( "$IP/includes/AutoLoader.php" );
68 wfRequireOnceInGlobalScope( "$IP/tests/common/TestsAutoLoader.php" );
69 wfRequireOnceInGlobalScope( "$IP/includes/Defines.php" );
70 wfRequireOnceInGlobalScope( "$IP/includes/DefaultSettings.php" );
71 wfRequireOnceInGlobalScope( "$IP/includes/GlobalFunctions.php" );
72
73 // Populate classes and namespaces from extensions and skins present in filesystem.
74 $directoryToJsonMap = [
75 $GLOBALS['wgExtensionDirectory'] => [ 'extension.json', 'extension-wip.json' ],
76 $GLOBALS['wgStyleDirectory'] => [ 'skin.json', 'skin-wip.json' ]
77 ];
78 foreach ( $directoryToJsonMap as $directory => $jsonFile ) {
79 foreach ( new DirectoryIterator( $directory ) as $iterator ) {
80 foreach ( $jsonFile as $file ) {
81
82 $jsonPath = $iterator->getPathname() . '/' . $file;
83 if ( file_exists( $jsonPath ) ) {
84 // ExtensionRegistry->readFromQueue is not used as it checks extension/skin
85 // dependencies, which we don't need or want for unit tests.
86 $json = file_get_contents( $jsonPath );
87 $info = json_decode( $json, true );
88 $dir = dirname( $jsonPath );
89 ExtensionRegistry::exportAutoloadClassesAndNamespaces( $dir, $info );
90 }
91 }
92 }
93 }