mirror of
https://github.com/wallabag/wallabag.git
synced 2026-11-03 19:11:07 +01:00
98 lines
2.4 KiB
PHP
98 lines
2.4 KiB
PHP
<?php
|
|
|
|
use Symfony\Component\Process\Exception\ProcessFailedException;
|
|
use Symfony\Component\Process\Process;
|
|
|
|
/*
|
|
* This files contains functions that are used in the tests, especially the bootstrap.php file.
|
|
*/
|
|
|
|
function getCurrentTestSuite(): ?string
|
|
{
|
|
foreach ($_SERVER['argv'] ?? [] as $index => $arg) {
|
|
if ('--testsuite' === $arg) {
|
|
$suite = $_SERVER['argv'][$index + 1] ?? null;
|
|
|
|
return null === $suite ? null : (string) $suite;
|
|
}
|
|
|
|
if (str_starts_with((string) $arg, '--testsuite=')) {
|
|
return substr((string) $arg, strlen('--testsuite='));
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns true if the current test run is a partial run.
|
|
* A partial run is a run that only runs a subset of the tests using the --filter, --group or --exclude-group options.
|
|
*/
|
|
function isPartialRun(): bool
|
|
{
|
|
foreach ($_SERVER['argv'] as $arg) {
|
|
if (str_starts_with((string) $arg, '--filter')) {
|
|
return true;
|
|
}
|
|
|
|
if (str_starts_with((string) $arg, '--group')) {
|
|
return true;
|
|
}
|
|
|
|
if (str_starts_with((string) $arg, '--exclude-group')) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* In CI, bootstrap commands keep logs quiet on success but still print buffered output on failure.
|
|
*/
|
|
function runBootstrapCommand(array $command, bool $mustSucceed = true): void
|
|
{
|
|
echo '$ ' . implode(' ', array_map(static function ($argument): string {
|
|
$argument = (string) $argument;
|
|
|
|
return preg_match('#^[A-Za-z0-9_@%+=:,./-]+$#', $argument) ? $argument : escapeshellarg($argument);
|
|
}, $command)) . \PHP_EOL;
|
|
|
|
$process = new Process($command);
|
|
$isCi = filter_var((string) getenv('CI'), \FILTER_VALIDATE_BOOL);
|
|
|
|
if (!$isCi) {
|
|
if ($mustSucceed) {
|
|
$process->mustRun(static function ($type, $buffer): void {
|
|
echo $buffer;
|
|
});
|
|
|
|
return;
|
|
}
|
|
|
|
$process->run(static function ($type, $buffer): void {
|
|
echo $buffer;
|
|
});
|
|
|
|
return;
|
|
}
|
|
|
|
$process->run();
|
|
|
|
if ($process->isSuccessful()) {
|
|
return;
|
|
}
|
|
|
|
if ('' !== $process->getOutput()) {
|
|
echo $process->getOutput();
|
|
}
|
|
|
|
if ('' !== $process->getErrorOutput()) {
|
|
echo $process->getErrorOutput();
|
|
}
|
|
|
|
if ($mustSucceed) {
|
|
throw new ProcessFailedException($process);
|
|
}
|
|
}
|