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

addArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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
/**
29
 * Lazy script to invoke the MediaWiki phpunit runner
30
 *
31
 *   php mw-phpunit-runner.php [options]
32
 */
33
34
if ( php_sapi_name() !== 'cli' ) {
35
	die( 'Not an entry point' );
36
}
37
38
print( "\nMediaWiki phpunit runnner ... \n" );
39
40
function isReadablePath( $path ) {
41
42
	if ( is_readable( $path ) ) {
43
		return $path;
44
	}
45
46
	throw new RuntimeException( "Expected an accessible {$path} path" );
47
}
48
49
function addArguments( $args ) {
50
51
	array_shift( $args );
52
	return $args;
53
}
54
55
/**
56
 * @return string
57
 */
58
function getDirectory() {
59
60
	$directory = $GLOBALS[ 'argv' ][ 0 ];
61
62
	if ( $directory[ 0 ] !== DIRECTORY_SEPARATOR ) {
63
		$directory = $_SERVER[ 'PWD' ] . DIRECTORY_SEPARATOR . $directory;
64
	}
65
66
	$directory = dirname( $directory );
67
68
	return $directory;
69
}
70
71
$extDirectory = dirname ( getDirectory() );
72
73
$config = isReadablePath( "$extDirectory/phpunit.xml.dist" );
74
$mw = isReadablePath( dirname( dirname( $extDirectory ) ) . "/tests/phpunit/phpunit.php" );
75
76
echo "php {$mw} -c {$config} " . implode( ' ', addArguments( $GLOBALS['argv'] ) ) . "\n\n";
77
78
passthru( "php {$mw} -c {$config} " . implode( ' ', addArguments( $GLOBALS['argv'] ) ) );
79