mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
100 lines
2.5 KiB
PHP
Executable File
100 lines
2.5 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php declare(strict_types=1);
|
|
|
|
use Pest\Kernel;
|
|
use Pest\Panic;
|
|
use Pest\TestCaseFilters\GitDirtyTestCaseFilter;
|
|
use Pest\TestCaseMethodFilters\TodoTestCaseFilter;
|
|
use Pest\TestSuite;
|
|
use Symfony\Component\Console\Input\ArgvInput;
|
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
|
|
|
(static function () {
|
|
// Ensures Collision's Printer is registered.
|
|
$_SERVER['COLLISION_PRINTER'] = 'DefaultPrinter';
|
|
|
|
$args = $_SERVER['argv'];
|
|
|
|
$dirty = false;
|
|
$todo = false;
|
|
|
|
foreach ($args as $key => $value) {
|
|
if ($value === '--compact') {
|
|
$_SERVER['COLLISION_PRINTER_COMPACT'] = 'true';
|
|
unset($args[$key]);
|
|
}
|
|
|
|
if ($value === '--profile') {
|
|
$_SERVER['COLLISION_PRINTER_PROFILE'] = 'true';
|
|
unset($args[$key]);
|
|
}
|
|
|
|
if (str_contains($value, '--test-directory')) {
|
|
unset($args[$key]);
|
|
}
|
|
|
|
if ($value === '--dirty') {
|
|
$dirty = true;
|
|
unset($args[$key]);
|
|
}
|
|
|
|
if ($value === '--todos') {
|
|
$todo = true;
|
|
unset($args[$key]);
|
|
}
|
|
|
|
if (str_contains($value, '--teamcity')) {
|
|
unset($args[$key]);
|
|
$args[] = '--no-output';
|
|
unset($_SERVER['COLLISION_PRINTER']);
|
|
}
|
|
}
|
|
|
|
// 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);
|
|
$input = new ArgvInput();
|
|
|
|
$testSuite = TestSuite::getInstance(
|
|
$rootPath,
|
|
$input->getParameterOption('--test-directory', 'tests'),
|
|
);
|
|
|
|
if ($dirty) {
|
|
$testSuite->tests->addTestCaseFilter(new GitDirtyTestCaseFilter($rootPath));
|
|
}
|
|
|
|
if ($todo) {
|
|
$testSuite->tests->addTestCaseMethodFilter(new TodoTestCaseFilter());
|
|
}
|
|
|
|
$isDecorated = $input->getParameterOption('--colors', 'always') !== 'never';
|
|
|
|
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, $isDecorated);
|
|
|
|
try {
|
|
$kernel = Kernel::boot($testSuite, $input, $output);
|
|
|
|
$result = $kernel->handle($args);
|
|
|
|
$kernel->shutdown();
|
|
} catch (Throwable|Error $e) {
|
|
Panic::with($e);
|
|
}
|
|
|
|
exit($result);
|
|
})();
|