mirror of
https://github.com/pestphp/pest.git
synced 2026-04-22 23:17:28 +02:00
chore: improves feedback
This commit is contained in:
@ -19,7 +19,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^8.3.0",
|
"php": "^8.3.0",
|
||||||
"brianium/paratest": "^7.20.0",
|
"brianium/paratest": "^7.20.0",
|
||||||
"nunomaduro/collision": "^8.9.3",
|
"nunomaduro/collision": "^8.9.4",
|
||||||
"nunomaduro/termwind": "^2.4.0",
|
"nunomaduro/termwind": "^2.4.0",
|
||||||
"pestphp/pest-plugin": "^4.0.0",
|
"pestphp/pest-plugin": "^4.0.0",
|
||||||
"pestphp/pest-plugin-arch": "^4.0.2",
|
"pestphp/pest-plugin-arch": "^4.0.2",
|
||||||
|
|||||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Plugins;
|
namespace Pest\Plugins;
|
||||||
|
|
||||||
|
use NunoMaduro\Collision\Adapters\Phpunit\Printers\DefaultPrinter;
|
||||||
use Pest\Contracts\Plugins\AddsOutput;
|
use Pest\Contracts\Plugins\AddsOutput;
|
||||||
use Pest\Contracts\Plugins\HandlesArguments;
|
use Pest\Contracts\Plugins\HandlesArguments;
|
||||||
use Pest\Contracts\Plugins\Terminable;
|
use Pest\Contracts\Plugins\Terminable;
|
||||||
@ -152,12 +153,6 @@ final class Tia implements AddsOutput, HandlesArguments, Terminable
|
|||||||
*/
|
*/
|
||||||
private array $cachedAssertionsByTestId = [];
|
private array $cachedAssertionsByTestId = [];
|
||||||
|
|
||||||
/**
|
|
||||||
* Captured at replay setup so the end-of-run summary can report the
|
|
||||||
* scope of the changes that drove the run.
|
|
||||||
*/
|
|
||||||
private int $changedFileCount = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the graph during replay so `beforeEach` can look up cached
|
* Holds the graph during replay so `beforeEach` can look up cached
|
||||||
* results without re-loading from disk on every test.
|
* results without re-loading from disk on every test.
|
||||||
@ -460,7 +455,6 @@ final class Tia implements AddsOutput, HandlesArguments, Terminable
|
|||||||
|
|
||||||
if ($this->replayRan) {
|
if ($this->replayRan) {
|
||||||
$this->bumpRecordedSha();
|
$this->bumpRecordedSha();
|
||||||
$this->emitReplaySummary();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((string) Parallel::getGlobal(self::RECORDING_GLOBAL) !== '1') {
|
if ((string) Parallel::getGlobal(self::RECORDING_GLOBAL) !== '1') {
|
||||||
@ -737,14 +731,14 @@ final class Tia implements AddsOutput, HandlesArguments, Terminable
|
|||||||
|
|
||||||
$affected = $changed === [] ? [] : $graph->affected($changed);
|
$affected = $changed === [] ? [] : $graph->affected($changed);
|
||||||
|
|
||||||
$this->changedFileCount = count($changed);
|
|
||||||
|
|
||||||
$affectedSet = array_fill_keys($affected, true);
|
$affectedSet = array_fill_keys($affected, true);
|
||||||
|
|
||||||
$this->replayRan = true;
|
$this->replayRan = true;
|
||||||
$this->replayGraph = $graph;
|
$this->replayGraph = $graph;
|
||||||
$this->affectedFiles = $affectedSet;
|
$this->affectedFiles = $affectedSet;
|
||||||
|
|
||||||
|
$this->registerRecap();
|
||||||
|
|
||||||
if (! Parallel::isEnabled()) {
|
if (! Parallel::isEnabled()) {
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
@ -1057,23 +1051,28 @@ final class Tia implements AddsOutput, HandlesArguments, Terminable
|
|||||||
* git still reports them as modified.
|
* git still reports them as modified.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Prints the post-run TIA summary. Runs after the test report so the
|
* Hooks a recap callback into Collision's `DefaultPrinter` so TIA's
|
||||||
* replayed count reflects what actually happened (cache hits counted
|
* counts ride along the "Tests: N passed (M assertions, ...)" line
|
||||||
* inside `getCachedResult`) rather than a graph-level estimate that
|
* instead of printing on their own block. Collision joins each
|
||||||
* ignores any CLI path filter the user passed in.
|
* callback's return value with a gray `, ` separator, so we return
|
||||||
|
* a single fragment like `728 replayed via tia` (or nothing when
|
||||||
|
* there's no replay activity to report).
|
||||||
*/
|
*/
|
||||||
private function emitReplaySummary(): void
|
private function registerRecap(): void
|
||||||
{
|
{
|
||||||
// `$executedCount` and `$replayedCount` are maintained in lockstep
|
DefaultPrinter::addRecap(function (): string {
|
||||||
// by `getCachedResult()` — every test id that hits that method bumps
|
$fragments = [];
|
||||||
// exactly one of them. Summing the two gives the test-method total
|
|
||||||
// that lines up with Pest's "Tests: N" banner directly above.
|
if ($this->executedCount > 0) {
|
||||||
$this->output->writeln(sprintf(
|
$fragments[] = $this->executedCount.' affected';
|
||||||
' <fg=green>TIA</> %d changed file(s) → %d affected, %d replayed.',
|
}
|
||||||
$this->changedFileCount,
|
|
||||||
$this->executedCount,
|
if ($this->replayedCount > 0) {
|
||||||
$this->replayedCount,
|
$fragments[] = $this->replayedCount.' replayed';
|
||||||
));
|
}
|
||||||
|
|
||||||
|
return $fragments === [] ? '' : implode(', ', $fragments);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function bumpRecordedSha(): void
|
private function bumpRecordedSha(): void
|
||||||
|
|||||||
@ -69,10 +69,6 @@ final class BaselineSync
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->confirm($repo)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->output->writeln(sprintf(
|
$this->output->writeln(sprintf(
|
||||||
' <fg=cyan>TIA</> fetching baseline from <fg=white>%s</>…',
|
' <fg=cyan>TIA</> fetching baseline from <fg=white>%s</>…',
|
||||||
$repo,
|
$repo,
|
||||||
@ -337,41 +333,6 @@ final class BaselineSync
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* One-shot Y/n prompt. Defaults to Y. In non-interactive shells (CI,
|
|
||||||
* piped input) returns false so scripted runs never hang waiting for
|
|
||||||
* input.
|
|
||||||
*/
|
|
||||||
private function confirm(string $repo): bool
|
|
||||||
{
|
|
||||||
if (! $this->isTerminal()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->output->writeln('');
|
|
||||||
$this->output->writeln(sprintf(
|
|
||||||
' <fg=cyan>TIA</> no local cache — fetch baseline from <fg=white>%s</>? <fg=gray>[Y/n]</>',
|
|
||||||
$repo,
|
|
||||||
));
|
|
||||||
|
|
||||||
$handle = @fopen('php://stdin', 'r');
|
|
||||||
|
|
||||||
if ($handle === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$line = fgets($handle);
|
|
||||||
fclose($handle);
|
|
||||||
|
|
||||||
if ($line === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$line = strtolower(trim($line));
|
|
||||||
|
|
||||||
return $line === '' || $line === 'y' || $line === 'yes';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Real-TTY check for STDIN. Symfony's `isInteractive()` defaults to true
|
* Real-TTY check for STDIN. Symfony's `isInteractive()` defaults to true
|
||||||
* unless `--no-interaction` is explicitly passed, which would make
|
* unless `--no-interaction` is explicitly passed, which would make
|
||||||
|
|||||||
Reference in New Issue
Block a user