mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 02:37:22 +01:00
fix: ensures --retry works with errored tests
This commit is contained in:
@ -23,7 +23,8 @@ final class BootSubscribers implements Bootstrapper
|
|||||||
Subscribers\EnsureConfigurationIsValid::class,
|
Subscribers\EnsureConfigurationIsValid::class,
|
||||||
Subscribers\EnsureConfigurationDefaults::class,
|
Subscribers\EnsureConfigurationDefaults::class,
|
||||||
Subscribers\EnsureRetryRepositoryExists::class,
|
Subscribers\EnsureRetryRepositoryExists::class,
|
||||||
Subscribers\EnsureFailedTestsAreStoredForRetry::class,
|
Subscribers\EnsureErroredTestsAreRetryable::class,
|
||||||
|
Subscribers\EnsureFailedTestsAreRetryable::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -123,7 +123,7 @@ final class TestCaseMethodFactory
|
|||||||
|
|
||||||
$methodName = Str::evaluable($this->description);
|
$methodName = Str::evaluable($this->description);
|
||||||
|
|
||||||
$retryRepository = TestSuite::getInstance()->retryTempRepository;
|
$retryRepository = TestSuite::getInstance()->retryRepository;
|
||||||
|
|
||||||
if (Retry::$retrying && ! $retryRepository->isEmpty() && ! $retryRepository->exists(sprintf('%s::%s', $classFQN, $methodName))) {
|
if (Retry::$retrying && ! $retryRepository->isEmpty() && ! $retryRepository->exists(sprintf('%s::%s', $classFQN, $methodName))) {
|
||||||
return '';
|
return '';
|
||||||
|
|||||||
@ -7,9 +7,15 @@ namespace Pest\Repositories;
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class TempRepository
|
final class RetryRepository
|
||||||
{
|
{
|
||||||
private const FOLDER = __DIR__.'/../../.temp';
|
private const TEMPORARY_FOLDER = __DIR__
|
||||||
|
.DIRECTORY_SEPARATOR
|
||||||
|
.'..'
|
||||||
|
.DIRECTORY_SEPARATOR
|
||||||
|
.'..'
|
||||||
|
.DIRECTORY_SEPARATOR
|
||||||
|
.'.temp';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Temp Repository instance.
|
* Creates a new Temp Repository instance.
|
||||||
@ -32,7 +38,7 @@ final class TempRepository
|
|||||||
*/
|
*/
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
@unlink(self::FOLDER.'/'.$this->filename.'.json'); // @phpstan-ignore-line
|
@unlink(self::TEMPORARY_FOLDER.'/'.$this->filename.'.json'); // @phpstan-ignore-line
|
||||||
|
|
||||||
$this->save([]);
|
$this->save([]);
|
||||||
}
|
}
|
||||||
@ -60,7 +66,7 @@ final class TempRepository
|
|||||||
*/
|
*/
|
||||||
private function all(): array
|
private function all(): array
|
||||||
{
|
{
|
||||||
$path = self::FOLDER.'/'.$this->filename.'.json';
|
$path = self::TEMPORARY_FOLDER.'/'.$this->filename.'.json';
|
||||||
|
|
||||||
$contents = file_exists($path) ? file_get_contents($path) : '{}';
|
$contents = file_exists($path) ? file_get_contents($path) : '{}';
|
||||||
|
|
||||||
@ -80,6 +86,6 @@ final class TempRepository
|
|||||||
{
|
{
|
||||||
$contents = json_encode($elements, JSON_THROW_ON_ERROR);
|
$contents = json_encode($elements, JSON_THROW_ON_ERROR);
|
||||||
|
|
||||||
file_put_contents(self::FOLDER.'/'.$this->filename.'.json', $contents);
|
file_put_contents(self::TEMPORARY_FOLDER.'/'.$this->filename.'.json', $contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
23
src/Subscribers/EnsureErroredTestsAreRetryable.php
Normal file
23
src/Subscribers/EnsureErroredTestsAreRetryable.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Subscribers;
|
||||||
|
|
||||||
|
use Pest\TestSuite;
|
||||||
|
use PHPUnit\Event\Test\Errored;
|
||||||
|
use PHPUnit\Event\Test\ErroredSubscriber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class EnsureErroredTestsAreRetryable implements ErroredSubscriber
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Runs the subscriber.
|
||||||
|
*/
|
||||||
|
public function notify(Errored $event): void
|
||||||
|
{
|
||||||
|
TestSuite::getInstance()->retryRepository->add($event->test()->id());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,13 +11,13 @@ use PHPUnit\Event\Test\FailedSubscriber;
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class EnsureFailedTestsAreStoredForRetry implements FailedSubscriber
|
final class EnsureFailedTestsAreRetryable implements FailedSubscriber
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Runs the subscriber.
|
* Runs the subscriber.
|
||||||
*/
|
*/
|
||||||
public function notify(Failed $event): void
|
public function notify(Failed $event): void
|
||||||
{
|
{
|
||||||
TestSuite::getInstance()->retryTempRepository->add($event->test()->id());
|
TestSuite::getInstance()->retryRepository->add($event->test()->id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,6 +18,6 @@ final class EnsureRetryRepositoryExists implements StartedSubscriber
|
|||||||
*/
|
*/
|
||||||
public function notify(Started $event): void
|
public function notify(Started $event): void
|
||||||
{
|
{
|
||||||
TestSuite::getInstance()->retryTempRepository->boot();
|
TestSuite::getInstance()->retryRepository->boot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use Pest\Repositories\AfterAllRepository;
|
|||||||
use Pest\Repositories\AfterEachRepository;
|
use Pest\Repositories\AfterEachRepository;
|
||||||
use Pest\Repositories\BeforeAllRepository;
|
use Pest\Repositories\BeforeAllRepository;
|
||||||
use Pest\Repositories\BeforeEachRepository;
|
use Pest\Repositories\BeforeEachRepository;
|
||||||
use Pest\Repositories\TempRepository;
|
use Pest\Repositories\RetryRepository;
|
||||||
use Pest\Repositories\TestRepository;
|
use Pest\Repositories\TestRepository;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
@ -49,9 +49,9 @@ final class TestSuite
|
|||||||
public AfterAllRepository $afterAll;
|
public AfterAllRepository $afterAll;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the retry temp repository.
|
* Holds the retry repository.
|
||||||
*/
|
*/
|
||||||
public TempRepository $retryTempRepository;
|
public RetryRepository $retryRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the root path.
|
* Holds the root path.
|
||||||
@ -75,7 +75,7 @@ final class TestSuite
|
|||||||
$this->tests = new TestRepository();
|
$this->tests = new TestRepository();
|
||||||
$this->afterEach = new AfterEachRepository();
|
$this->afterEach = new AfterEachRepository();
|
||||||
$this->afterAll = new AfterAllRepository();
|
$this->afterAll = new AfterAllRepository();
|
||||||
$this->retryTempRepository = new TempRepository('retry');
|
$this->retryRepository = new RetryRepository('retry');
|
||||||
|
|
||||||
$this->rootPath = (string) realpath($rootPath);
|
$this->rootPath = (string) realpath($rootPath);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user