mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
87 lines
2.4 KiB
PHP
Executable File
87 lines
2.4 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php declare(strict_types=1);
|
|
|
|
use Pest\Actions\ValidatesEnvironment;
|
|
use Pest\ConfigLoader;
|
|
use Pest\Repositories\TestRepository;
|
|
use Pest\Support\Container;
|
|
use Pest\Kernel;
|
|
use Pest\Support\DirtyTestCaseFilter;
|
|
use Pest\TestSuite;
|
|
use Symfony\Component\Console\Input\ArgvInput;
|
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
(static function () {
|
|
// Ensures Collision's Printer is registered.
|
|
$_SERVER['COLLISION_PRINTER'] = 'DefaultPrinter';
|
|
|
|
$args = $_SERVER['argv'];
|
|
|
|
foreach ($args as $key => $value) {
|
|
if (str_contains($value, '--compact')) {
|
|
$_SERVER['COLLISION_PRINTER_COMPACT'] = 'true';
|
|
}
|
|
|
|
if (str_contains($value, '--profile')) {
|
|
$_SERVER['COLLISION_PRINTER_PROFILE'] = 'true';
|
|
}
|
|
}
|
|
|
|
// 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;
|
|
}
|
|
|
|
// Get $rootPath based on $autoloadPath
|
|
$rootPath = dirname($autoloadPath, 2);
|
|
$argv = new ArgvInput();
|
|
|
|
$filters = [];
|
|
|
|
foreach ($args as $key => $value) {
|
|
if (str_contains($value, '--dirty')) {
|
|
$filters[] = new DirtyTestCaseFilter($rootPath);
|
|
}
|
|
}
|
|
|
|
$testSuite = TestSuite::getInstance(
|
|
$rootPath,
|
|
$argv->getParameterOption('--test-directory', (new ConfigLoader($rootPath))->getTestsDirectory()),
|
|
new TestRepository($filters),
|
|
);
|
|
|
|
$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);
|
|
|
|
$argsToUnset = ['--test-directory', '--compact', '--profile', '--dirty'];
|
|
|
|
foreach ($args as $key => $value) {
|
|
if (in_array($value, $argsToUnset)) {
|
|
unset($args[$key]);
|
|
}
|
|
}
|
|
|
|
$kernel = Kernel::boot();
|
|
|
|
$result = $kernel->handle($args);
|
|
|
|
$kernel->shutdown();
|
|
|
|
exit($result);
|
|
})();
|