Files
pest/bin/pest
2021-08-05 15:31:09 +01:00

70 lines
2.3 KiB
PHP
Executable File

#!/usr/bin/env php
<?php declare(strict_types=1);
use NunoMaduro\Collision\Provider;
use ParaTest\Console\Commands\ParaTestCommand;
use Pest\Actions\ValidatesEnvironment;
use Pest\Console\Command;
use Pest\Console\Paratest\Runner;
use Pest\Support\Container;
use Pest\TestSuite;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
(static function () {
// Used when Pest is required using composer.
$vendorPath = dirname(__DIR__, 4) . '/vendor/autoload.php';
// Used when Pest maintainers are running Pest tests.
$localPath = dirname(__DIR__) . '/vendor/autoload.php';
if (file_exists($vendorPath)) {
include_once $vendorPath;
$autoloadPath = $vendorPath;
} else {
include_once $localPath;
$autoloadPath = $localPath;
}
(new Provider())->register();
// Get $rootPath based on $autoloadPath
$rootPath = dirname($autoloadPath, 2);
$argv = new ArgvInput();
$testSuite = TestSuite::getInstance($rootPath, $argv->getParameterOption('--test-directory', 'tests'));
$shouldExecuteInParallel = $argv->hasParameterOption('--parallel');
// Let's remove the parallel option now we've retrieved its value
if (($parallelKey = array_search('--parallel', $_SERVER['argv'])) !== false) {
unset($_SERVER['argv'][$parallelKey]);
}
$isDecorated = $argv->getParameterOption('--colors', 'always') !== 'never';
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, $isDecorated);
$container = Container::getInstance();
$container->add(TestSuite::class, $testSuite);
$container->add(OutputInterface::class, $output);
ValidatesEnvironment::in($testSuite);
// Let's remove any arguments that PHPUnit does not understand
if ($argv->hasParameterOption('--test-directory')) {
foreach ($_SERVER['argv'] as $key => $value) {
if (strpos($value, '--test-directory') !== false) {
unset($_SERVER['argv'][$key]);
}
}
}
if ($shouldExecuteInParallel) {
$_SERVER['argv'][] = '--runner';
$_SERVER['argv'][] = Runner::class;
exit(ParaTestCommand::applicationFactory($testSuite->rootPath)->run(new ArgvInput()));
}
exit($container->get(Command::class)->run($_SERVER['argv']));
})();