/** * Lazy script to invoke the MediaWiki phpunit runner * * php mw-phpunit-runner.php [options] */ if (php_sapi_name() !== 'cli') { die('Not an entry point'); } print "\nMediaWiki phpunit runnner ... \n"; function isReadablePath($path) { if (is_readable($path)) { return $path; } throw new RuntimeException("Expected an accessible {$path} path"); } function addArguments($args) { $arguments = array(); for ($arg = reset($args); $arg !== false; $arg = next($args)) { if ($arg === basename(__FILE__)) { continue; } $arguments[] = $arg; } return $arguments; } $mw = isReadablePath(__DIR__ . "/../../../tests/phpunit/phpunit.php"); $config = isReadablePath(__DIR__ . "/../phpunit.xml.dist"); passthru("php {$mw} -c {$config} " . implode(' ', addArguments($GLOBALS['argv'])));
/** * Executes the command just like \Hiatus\exec(), but if the exit code is not 0 then an exception is raised. * * @param string $command The shell command to execute. This can contain arguments, but make sure to use PHP's escapeshellarg for any arguments * supplied by the user. * @param array $arguments The arguments to pass to the command. These will be passed through PHP's escapeshellarg function so pass the * arguments unescaped. If a key in the array is not numeric, then it will be included as well in a KEY=VALUE format. * @param float $timeout If given, this will terminate the command if it does not finish before the timeout expires. * @param string $stdin A string to pass to the command on stdin. * @return array A 2-member array is returned. * * string The output of the command. * * string The stderr output of the command. */ function execX($command, array $arguments = [], $timeout = null, $stdin = null) { list($exitCode, $stdout, $stderr) = exec($command, $arguments, $timeout, $stdin); if ($exitCode !== 0) { throw new \Exception("Failed to execute command '" . addArguments($command, $arguments) . "'. Exited with code {$exitCode}."); } return [$stdout, $stderr]; }