feat(tia): continues to work on poc

This commit is contained in:
nuno maduro
2026-04-16 14:24:20 -07:00
parent 42d1092a9e
commit 9c8033d60c
17 changed files with 301 additions and 172 deletions

View File

@ -6,81 +6,30 @@ namespace Pest\Subscribers;
use Pest\Plugins\Tia\ResultCollector;
use PHPUnit\Event\Code\TestMethod;
use PHPUnit\Event\Test\ConsideredRisky;
use PHPUnit\Event\Test\ConsideredRiskySubscriber;
use PHPUnit\Event\Test\Errored;
use PHPUnit\Event\Test\ErroredSubscriber;
use PHPUnit\Event\Test\Failed;
use PHPUnit\Event\Test\FailedSubscriber;
use PHPUnit\Event\Test\MarkedIncomplete;
use PHPUnit\Event\Test\MarkedIncompleteSubscriber;
use PHPUnit\Event\Test\Passed;
use PHPUnit\Event\Test\PassedSubscriber;
use PHPUnit\Event\Test\Prepared;
use PHPUnit\Event\Test\PreparedSubscriber;
use PHPUnit\Event\Test\Skipped;
use PHPUnit\Event\Test\SkippedSubscriber;
/**
* Feeds per-test outcomes (status + message + time) into the TIA
* `ResultCollector` so the graph can persist them for faithful replay.
* Starts a per-test recording window on Prepared. Sibling subscribers
* (`EnsureTia*`) close it with the outcome and the assertion count so the
* graph can persist everything needed for faithful replay.
*
* Why one subscriber per event: PHPUnit's `TypeMap::map()` picks only the
* first subscriber interface it finds on a class, so one class cannot fan
* out to multiple events — each event needs its own subscriber class.
*
* @internal
*/
final class EnsureTiaResultsAreCollected implements
ConsideredRiskySubscriber,
ErroredSubscriber,
FailedSubscriber,
MarkedIncompleteSubscriber,
PassedSubscriber,
PreparedSubscriber,
SkippedSubscriber
final class EnsureTiaResultsAreCollected implements PreparedSubscriber
{
public function __construct(private readonly ResultCollector $collector) {}
public function notify(Prepared|Passed|Failed|Errored|Skipped|MarkedIncomplete|ConsideredRisky $event): void
public function notify(Prepared $event): void
{
if ($event instanceof Prepared) {
$test = $event->test();
$test = $event->test();
if ($test instanceof TestMethod) {
$this->collector->testPrepared($test->className().'::'.$test->methodName());
}
return;
if ($test instanceof TestMethod) {
$this->collector->testPrepared($test->className().'::'.$test->methodName());
}
if ($event instanceof Passed) {
$this->collector->testPassed();
return;
}
if ($event instanceof Failed) {
$this->collector->testFailed($event->throwable()->message());
return;
}
if ($event instanceof Errored) {
$this->collector->testErrored($event->throwable()->message());
return;
}
if ($event instanceof Skipped) {
$this->collector->testSkipped($event->message());
return;
}
if ($event instanceof MarkedIncomplete) {
$this->collector->testIncomplete($event->throwable()->message());
return;
}
// Last possible type: ConsideredRisky (all others returned above).
$this->collector->testRisky($event->message()); // @phpstan-ignore method.notFound
}
}