wikimedia /
mediawiki-extensions-Lingo
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the MediaWiki extension Lingo. |
||
| 4 | * |
||
| 5 | * @copyright 2011 - 2016, Stephan Gambke, mwjames |
||
| 6 | * @license GPL-2.0-or-later |
||
| 7 | * |
||
| 8 | * The Lingo extension is free software: you can redistribute it and/or modify |
||
| 9 | * it under the terms of the GNU General Public License as published by the Free |
||
| 10 | * Software Foundation; either version 2 of the License, or (at your option) any |
||
| 11 | * later version. |
||
| 12 | * |
||
| 13 | * The Lingo extension is distributed in the hope that it will be useful, but |
||
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
||
| 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
||
| 16 | * details. |
||
| 17 | * |
||
| 18 | * You should have received a copy of the GNU General Public License along |
||
| 19 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
||
| 20 | * |
||
| 21 | * @author Stephan Gambke |
||
| 22 | * @author mwjames |
||
| 23 | * @since 2.0 |
||
| 24 | * @file |
||
| 25 | * @ingroup Lingo |
||
| 26 | */ |
||
| 27 | |||
| 28 | if ( php_sapi_name() !== 'cli' ) { |
||
| 29 | die( 'Not an entry point' ); |
||
| 30 | } |
||
| 31 | |||
| 32 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
| 33 | die( 'MediaWiki is not available for the test environment' ); |
||
| 34 | } |
||
| 35 | |||
| 36 | function registerAutoloaderPath( $identifier, $path ) { |
||
| 37 | print( "\nUsing the {$identifier} vendor autoloader ...\n\n" ); |
||
|
0 ignored issues
–
show
|
|||
| 38 | return require $path; |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @return string |
||
| 43 | */ |
||
| 44 | function getDirectory() { |
||
| 45 | $directory = $GLOBALS[ 'argv' ][ 0 ]; |
||
| 46 | |||
| 47 | if ( $directory[ 0 ] !== DIRECTORY_SEPARATOR ) { |
||
| 48 | $directory = $_SERVER[ 'PWD' ] . DIRECTORY_SEPARATOR . $directory; |
||
| 49 | } |
||
| 50 | |||
| 51 | $directory = dirname( $directory ); |
||
| 52 | |||
| 53 | return $directory; |
||
| 54 | } |
||
| 55 | |||
| 56 | function runTestAutoLoader( $autoLoader = null ) { |
||
| 57 | $directory = getDirectory(); |
||
| 58 | |||
| 59 | $mwVendorPath = $directory . '/../../vendor/autoload.php'; |
||
| 60 | $localVendorPath = $directory . '/../vendor/autoload.php'; |
||
| 61 | |||
| 62 | if ( is_readable( $localVendorPath ) ) { |
||
| 63 | $autoLoader = registerAutoloaderPath( 'local', $localVendorPath ); |
||
| 64 | } elseif ( is_readable( $mwVendorPath ) ) { |
||
| 65 | $autoLoader = registerAutoloaderPath( 'MediaWiki', $mwVendorPath ); |
||
| 66 | } |
||
| 67 | |||
| 68 | if ( !$autoLoader instanceof \Composer\Autoload\ClassLoader ) { |
||
| 69 | return false; |
||
| 70 | } |
||
| 71 | |||
| 72 | return true; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ( !runTestAutoLoader() ) { |
||
| 76 | die( 'Required test class loader was not accessible' ); |
||
| 77 | } |
||
| 78 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.