mirror of
https://github.com/pestphp/pest.git
synced 2026-04-24 07:57:29 +02:00
feat(tia): continues to work on poc
This commit is contained in:
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Tia;
|
||||
|
||||
/**
|
||||
* Immutable snapshot of a previous test run's outcome. Stored in the TIA
|
||||
* graph and returned by `BeforeEachable::beforeEach` so `Testable` can
|
||||
* faithfully replay the exact status — pass, fail, skip, todo, incomplete,
|
||||
* risky, etc. — without executing the test body.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final readonly class CachedTestResult
|
||||
{
|
||||
/**
|
||||
* PHPUnit TestStatus int constants:
|
||||
* 0 = success, 1 = skipped, 2 = incomplete,
|
||||
* 3 = notice, 4 = deprecation, 5 = risky,
|
||||
* 6 = warning, 7 = failure, 8 = error.
|
||||
*/
|
||||
public function __construct(
|
||||
public int $status,
|
||||
public string $message = '',
|
||||
public float $time = 0.0,
|
||||
) {}
|
||||
|
||||
public function isSuccess(): bool
|
||||
{
|
||||
return $this->status === 0;
|
||||
}
|
||||
}
|
||||
@ -60,8 +60,13 @@ final readonly class ChangedFiles
|
||||
$absolute = $this->projectRoot.DIRECTORY_SEPARATOR.$file;
|
||||
|
||||
if (! is_file($absolute)) {
|
||||
// File deleted since last run — definitely changed.
|
||||
$remaining[] = $file;
|
||||
// File is absent now. If the snapshot recorded it as absent
|
||||
// too (sentinel ''), state is identical to last run — treat
|
||||
// as unchanged. Otherwise it was present last run and got
|
||||
// deleted since — that's a real change.
|
||||
if ($lastRunTree[$file] !== '') {
|
||||
$remaining[] = $file;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -92,6 +97,11 @@ final readonly class ChangedFiles
|
||||
$absolute = $this->projectRoot.DIRECTORY_SEPARATOR.$file;
|
||||
|
||||
if (! is_file($absolute)) {
|
||||
// Record the deletion with an empty-string sentinel so the
|
||||
// next run recognises "still deleted" as unchanged rather
|
||||
// than re-flagging the file as a fresh change.
|
||||
$out[$file] = '';
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Pest\Plugins\Tia;
|
||||
|
||||
use Pest\Support\Container;
|
||||
use PHPUnit\Framework\TestStatus\TestStatus;
|
||||
|
||||
/**
|
||||
* File-level Test Impact Analysis graph.
|
||||
@ -264,7 +265,7 @@ final class Graph
|
||||
];
|
||||
}
|
||||
|
||||
public function getResult(string $branch, string $testId, string $fallbackBranch = 'main'): ?CachedTestResult
|
||||
public function getResult(string $branch, string $testId, string $fallbackBranch = 'main'): ?TestStatus
|
||||
{
|
||||
$baseline = $this->baselineFor($branch, $fallbackBranch);
|
||||
|
||||
@ -274,7 +275,21 @@ final class Graph
|
||||
|
||||
$r = $baseline['results'][$testId];
|
||||
|
||||
return new CachedTestResult($r['status'], $r['message'], $r['time']);
|
||||
// PHPUnit's `TestStatus::from(int)` ignores messages, so reconstruct
|
||||
// each variant via its specific factory. Keeps the stored message
|
||||
// intact (important for skips/failures shown to the user).
|
||||
return match ($r['status']) {
|
||||
0 => TestStatus::success(),
|
||||
1 => TestStatus::skipped($r['message']),
|
||||
2 => TestStatus::incomplete($r['message']),
|
||||
3 => TestStatus::notice($r['message']),
|
||||
4 => TestStatus::deprecation($r['message']),
|
||||
5 => TestStatus::risky($r['message']),
|
||||
6 => TestStatus::warning($r['message']),
|
||||
7 => TestStatus::failure($r['message']),
|
||||
8 => TestStatus::error($r['message']),
|
||||
default => TestStatus::unknown(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -14,7 +14,7 @@ namespace Pest\Plugins\Tia;
|
||||
final class ResultCollector
|
||||
{
|
||||
/**
|
||||
* @var array<string, array{status: int, message: string, time: float}>
|
||||
* @var array<string, array{status: int, message: string, time: float, assertions: int}>
|
||||
*/
|
||||
private array $results = [];
|
||||
|
||||
@ -83,13 +83,20 @@ final class ResultCollector
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{status: int, message: string, time: float}>
|
||||
* @return array<string, array{status: int, message: string, time: float, assertions: int}>
|
||||
*/
|
||||
public function all(): array
|
||||
{
|
||||
return $this->results;
|
||||
}
|
||||
|
||||
public function recordAssertions(string $testId, int $assertions): void
|
||||
{
|
||||
if (isset($this->results[$testId])) {
|
||||
$this->results[$testId]['assertions'] = $assertions;
|
||||
}
|
||||
}
|
||||
|
||||
public function reset(): void
|
||||
{
|
||||
$this->results = [];
|
||||
@ -111,6 +118,7 @@ final class ResultCollector
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
'time' => $time,
|
||||
'assertions' => 0,
|
||||
];
|
||||
|
||||
$this->currentTestId = null;
|
||||
|
||||
Reference in New Issue
Block a user