Passed
Branch master (631cc3)
by Stephan
33:03
created

getDirectory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 9.4285
1
<?php
2
/**
3
 * This file is part of the MediaWiki extension Lingo.
4
 *
5
 * @copyright 2011 - 2016, Stephan Gambke, mwjames
6
 * @license   GNU General Public License, version 2 (or any later version)
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" );
38
	return require $path;
39
}
40
41
/**
42
 * @return string
43
 */
44
function getDirectory() {
45
46
	$directory = $GLOBALS[ 'argv' ][ 0 ];
47
48
	if ( $directory[ 0 ] !== DIRECTORY_SEPARATOR ) {
49
		$directory = $_SERVER[ 'PWD' ] . DIRECTORY_SEPARATOR . $directory;
50
	}
51
52
	$directory = dirname( $directory );
53
54
	return $directory;
55
}
56
57
function runTestAutoLoader( $autoLoader = null ) {
58
59
	$directory = getDirectory();
60
61
	$mwVendorPath = $directory . '/../../vendor/autoload.php';
62
	$localVendorPath = $directory . '/../vendor/autoload.php';
63
64
	if ( is_readable( $localVendorPath ) ) {
65
		$autoLoader = registerAutoloaderPath( 'local', $localVendorPath );
66
	} elseif ( is_readable( $mwVendorPath ) ) {
67
		$autoLoader = registerAutoloaderPath( 'MediaWiki', $mwVendorPath  );
68
	}
69
70
	if ( !$autoLoader instanceof \Composer\Autoload\ClassLoader ) {
71
		return false;
72
	}
73
74
	return true;
75
}
76
77
if ( !runTestAutoLoader() ) {
78
	die( 'Required test class loader was not accessible' );
79
}
80