mirror of
https://github.com/pestphp/pest.git
synced 2026-06-05 02:52:12 +02:00
wip
This commit is contained in:
@ -82,11 +82,15 @@ trait Testable
|
|||||||
public bool $__ran = false;
|
public bool $__ran = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True while this test is being replayed as a cached pass — set in
|
* The active replay mode for this test, set in `setUp()` and checked
|
||||||
* `setUp()`, checked in `__runTest()` and `tearDown()` to skip the body
|
* in `__runTest()` / `tearDown()` to skip the body and after-each.
|
||||||
* and after-each cleanup.
|
|
||||||
*/
|
*/
|
||||||
private bool $__replayingPass = false;
|
private Replay $__replay = Replay::No;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The cached assertion count to replay, captured when entering replay mode.
|
||||||
|
*/
|
||||||
|
private int $__replayAssertions = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The test's test closure.
|
* The test's test closure.
|
||||||
@ -240,8 +244,6 @@ trait Testable
|
|||||||
{
|
{
|
||||||
TestSuite::getInstance()->test = $this;
|
TestSuite::getInstance()->test = $this;
|
||||||
|
|
||||||
$this->__replayingPass = false;
|
|
||||||
|
|
||||||
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
|
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
|
||||||
|
|
||||||
$description = $method->description;
|
$description = $method->description;
|
||||||
@ -283,11 +285,10 @@ trait Testable
|
|||||||
assert($status !== null);
|
assert($status !== null);
|
||||||
|
|
||||||
match ($replay) {
|
match ($replay) {
|
||||||
Replay::Pass => $this->__replayPass(),
|
Replay::Pass, Replay::Risky => $this->__beginReplay($replay, $tia),
|
||||||
Replay::Skipped => $this->markTestSkipped($status->message()),
|
Replay::Skipped => $this->markTestSkipped($status->message()),
|
||||||
Replay::Incomplete => $this->markTestIncomplete($status->message()),
|
Replay::Incomplete => $this->markTestIncomplete($status->message()),
|
||||||
Replay::Failure => throw new AssertionFailedError($status->message() ?: 'Cached failure'),
|
Replay::Failure => throw new AssertionFailedError($status->message() ?: 'Cached failure'),
|
||||||
Replay::No => null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -313,9 +314,10 @@ trait Testable
|
|||||||
$this->__callClosure($beforeEach, $arguments);
|
$this->__callClosure($beforeEach, $arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function __replayPass(): void
|
private function __beginReplay(Replay $replay, Tia $tia): void
|
||||||
{
|
{
|
||||||
$this->__replayingPass = true;
|
$this->__replay = $replay;
|
||||||
|
$this->__replayAssertions = $tia->getAssertionCount($this::class.'::'.$this->name());
|
||||||
$this->__ran = true;
|
$this->__ran = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +353,7 @@ trait Testable
|
|||||||
*/
|
*/
|
||||||
protected function tearDown(...$arguments): void
|
protected function tearDown(...$arguments): void
|
||||||
{
|
{
|
||||||
if ($this->__replayingPass) {
|
if ($this->__replay !== Replay::No) {
|
||||||
TestSuite::getInstance()->test = null;
|
TestSuite::getInstance()->test = null;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -382,19 +384,12 @@ trait Testable
|
|||||||
*/
|
*/
|
||||||
private function __runTest(Closure $closure, ...$args): mixed
|
private function __runTest(Closure $closure, ...$args): mixed
|
||||||
{
|
{
|
||||||
if ($this->__replayingPass) {
|
if ($this->__replay === Replay::Pass || $this->__replay === Replay::Risky) {
|
||||||
// Feed the exact assertion count captured during the recorded
|
if ($this->__replay === Replay::Pass && $this->__replayAssertions === 0) {
|
||||||
// run so Pest's "Tests: N passed (M assertions)" banner stays
|
|
||||||
// accurate on replay instead of collapsing to 1-per-test.
|
|
||||||
/** @var Tia $tia */
|
|
||||||
$tia = Container::getInstance()->get(Tia::class);
|
|
||||||
$assertions = $tia->getAssertionCount($this::class.'::'.$this->name());
|
|
||||||
|
|
||||||
if ($assertions === 0) {
|
|
||||||
$this->expectNotToPerformAssertions();
|
$this->expectNotToPerformAssertions();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addToAssertionCount($assertions);
|
$this->addToAssertionCount($this->__replayAssertions);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ enum Replay
|
|||||||
{
|
{
|
||||||
case No;
|
case No;
|
||||||
case Pass;
|
case Pass;
|
||||||
|
case Risky;
|
||||||
case Skipped;
|
case Skipped;
|
||||||
case Incomplete;
|
case Incomplete;
|
||||||
case Failure;
|
case Failure;
|
||||||
@ -24,7 +25,8 @@ enum Replay
|
|||||||
}
|
}
|
||||||
|
|
||||||
return match (true) {
|
return match (true) {
|
||||||
$status->isSuccess(), $status->isRisky() => self::Pass,
|
$status->isSuccess() => self::Pass,
|
||||||
|
$status->isRisky() => self::Risky,
|
||||||
$status->isSkipped() => self::Skipped,
|
$status->isSkipped() => self::Skipped,
|
||||||
$status->isIncomplete() => self::Incomplete,
|
$status->isIncomplete() => self::Incomplete,
|
||||||
default => self::Failure,
|
default => self::Failure,
|
||||||
|
|||||||
Reference in New Issue
Block a user