Merge branch '2.x' into feature/compact-dataset-description

This commit is contained in:
Nuno Maduro
2023-02-13 23:32:02 +00:00
committed by GitHub
66 changed files with 1904 additions and 452 deletions

View File

@ -33,7 +33,7 @@ final class AfterEachRepository
}
/**
* Gets a after each closure by the given filename.
* Gets an after each closure by the given filename.
*/
public function get(string $filename): Closure
{

View File

@ -1,91 +0,0 @@
<?php
declare(strict_types=1);
namespace Pest\Repositories;
/**
* @internal
*/
final class RetryRepository
{
private const TEMPORARY_FOLDER = __DIR__
.DIRECTORY_SEPARATOR
.'..'
.DIRECTORY_SEPARATOR
.'..'
.DIRECTORY_SEPARATOR
.'.temp';
/**
* Creates a new Temp Repository instance.
*/
public function __construct(private readonly string $filename)
{
// ..
}
/**
* Adds a new element.
*/
public function add(string $element): void
{
$this->save([...$this->all(), ...[$element]]);
}
/**
* Clears the existing file, if any, and re-creates it.
*/
public function boot(): void
{
@unlink(self::TEMPORARY_FOLDER.'/'.$this->filename.'.json'); // @phpstan-ignore-line
$this->save([]);
}
/**
* Checks if there is any element.
*/
public function isEmpty(): bool
{
return $this->all() === [];
}
/**
* Checks if the given element exists.
*/
public function exists(string $element): bool
{
return in_array($element, $this->all(), true);
}
/**
* Gets all elements.
*
* @return array<int, string>
*/
private function all(): array
{
$path = self::TEMPORARY_FOLDER.'/'.$this->filename.'.json';
$contents = file_exists($path) ? file_get_contents($path) : '{}';
assert(is_string($contents));
$all = json_decode($contents, true, 512, JSON_THROW_ON_ERROR);
return is_array($all) ? $all : [];
}
/**
* Save the given elements.
*
* @param array<int, string> $elements
*/
private function save(array $elements): void
{
$contents = json_encode($elements, JSON_THROW_ON_ERROR);
file_put_contents(self::TEMPORARY_FOLDER.'/'.$this->filename.'.json', $contents);
}
}

View File

@ -125,6 +125,12 @@ final class TestRepository
*/
public function set(TestCaseMethodFactory $method): void
{
foreach ($this->testCaseFilters as $filter) {
if (! $filter->accept($method->filename)) {
return;
}
}
foreach ($this->testCaseMethodFilters as $filter) {
if (! $filter->accept($method)) {
return;
@ -147,15 +153,13 @@ final class TestRepository
return;
}
$accepted = array_reduce(
$this->testCaseFilters,
fn (bool $carry, TestCaseFilter $filter): bool => $carry && $filter->accept($filename),
true,
);
if ($accepted) {
$this->make($this->testCases[$filename]);
foreach ($this->testCaseFilters as $filter) {
if (! $filter->accept($filename)) {
return;
}
}
$this->make($this->testCases[$filename]);
}
/**