mirror of
https://github.com/pestphp/pest.git
synced 2026-03-09 09:17:23 +01:00
Migrates to Pint
This commit is contained in:
@ -9,9 +9,7 @@ use Pest\Exceptions\DatasetAlreadyExist;
|
||||
use Pest\Exceptions\DatasetDoesNotExist;
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
@ -36,7 +34,7 @@ final class DatasetsRepository
|
||||
/**
|
||||
* Sets the given.
|
||||
*
|
||||
* @param Closure|iterable<int|string, mixed> $data
|
||||
* @param Closure|iterable<int|string, mixed> $data
|
||||
*/
|
||||
public static function set(string $name, Closure|iterable $data): void
|
||||
{
|
||||
@ -50,16 +48,16 @@ final class DatasetsRepository
|
||||
/**
|
||||
* Sets the given "with".
|
||||
*
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $with
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $with
|
||||
*/
|
||||
public static function with(string $filename, string $description, array $with): void
|
||||
{
|
||||
self::$withs[$filename . '>>>' . $description] = $with;
|
||||
self::$withs[$filename.'>>>'.$description] = $with;
|
||||
}
|
||||
|
||||
public static function has(string $filename, string $description): bool
|
||||
{
|
||||
return array_key_exists($filename . '>>>' . $description, self::$withs);
|
||||
return array_key_exists($filename.'>>>'.$description, self::$withs);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,7 +67,7 @@ final class DatasetsRepository
|
||||
*/
|
||||
public static function get(string $filename, string $description): Closure|iterable
|
||||
{
|
||||
$dataset = self::$withs[$filename . '>>>' . $description];
|
||||
$dataset = self::$withs[$filename.'>>>'.$description];
|
||||
|
||||
$dataset = self::resolve($description, $dataset);
|
||||
|
||||
@ -83,8 +81,7 @@ final class DatasetsRepository
|
||||
/**
|
||||
* Resolves the current dataset to an array value.
|
||||
*
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $dataset
|
||||
*
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $dataset
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public static function resolve(string $description, array $dataset): array|null
|
||||
@ -99,11 +96,11 @@ final class DatasetsRepository
|
||||
$datasetCombinations = self::getDatasetsCombinations($dataset);
|
||||
|
||||
$datasetDescriptions = [];
|
||||
$datasetValues = [];
|
||||
$datasetValues = [];
|
||||
|
||||
foreach ($datasetCombinations as $datasetCombination) {
|
||||
$partialDescriptions = [];
|
||||
$values = [];
|
||||
$values = [];
|
||||
|
||||
foreach ($datasetCombination as $datasetCombinationElement) {
|
||||
$partialDescriptions[] = $datasetCombinationElement['label'];
|
||||
@ -113,7 +110,7 @@ final class DatasetsRepository
|
||||
}
|
||||
|
||||
$datasetDescriptions[] = implode(' / ', $partialDescriptions);
|
||||
$datasetValues[] = $values;
|
||||
$datasetValues[] = $values;
|
||||
}
|
||||
|
||||
foreach (array_count_values($datasetDescriptions) as $descriptionToCheck => $count) {
|
||||
@ -136,8 +133,7 @@ final class DatasetsRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $datasets
|
||||
*
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $datasets
|
||||
* @return array<array<mixed>>
|
||||
*/
|
||||
private static function processDatasets(array $datasets): array
|
||||
@ -148,7 +144,7 @@ final class DatasetsRepository
|
||||
$processedDataset = [];
|
||||
|
||||
if (is_string($data)) {
|
||||
if (!array_key_exists($data, self::$datasets)) {
|
||||
if (! array_key_exists($data, self::$datasets)) {
|
||||
throw new DatasetDoesNotExist($data);
|
||||
}
|
||||
|
||||
@ -165,9 +161,9 @@ final class DatasetsRepository
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
foreach ($datasets[$index] as $key => $values) {
|
||||
$values = is_array($values) ? $values : [$values];
|
||||
$values = is_array($values) ? $values : [$values];
|
||||
$processedDataset[] = [
|
||||
'label' => self::getDatasetDescription($key, $values), // @phpstan-ignore-line
|
||||
'label' => self::getDatasetDescription($key, $values), // @phpstan-ignore-line
|
||||
'values' => $values,
|
||||
];
|
||||
}
|
||||
@ -179,8 +175,7 @@ final class DatasetsRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array<mixed>> $combinations
|
||||
*
|
||||
* @param array<array<mixed>> $combinations
|
||||
* @return array<array<array<mixed>>>
|
||||
*/
|
||||
private static function getDatasetsCombinations(array $combinations): array
|
||||
@ -201,7 +196,7 @@ final class DatasetsRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, mixed> $data
|
||||
* @param array<int, mixed> $data
|
||||
*/
|
||||
private static function getDatasetDescription(int|string $key, array $data): string
|
||||
{
|
||||
|
||||
@ -9,7 +9,7 @@ namespace Pest\Repositories;
|
||||
*/
|
||||
final class TempRepository
|
||||
{
|
||||
private const FOLDER = __DIR__ . '/../../.temp';
|
||||
private const FOLDER = __DIR__.'/../../.temp';
|
||||
|
||||
/**
|
||||
* Creates a new Temp Repository instance.
|
||||
@ -35,7 +35,7 @@ final class TempRepository
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
@unlink(self::FOLDER . '/' . $this->filename . '.json'); // @phpstan-ignore-line
|
||||
@unlink(self::FOLDER.'/'.$this->filename.'.json'); // @phpstan-ignore-line
|
||||
|
||||
$this->save([]);
|
||||
}
|
||||
@ -55,7 +55,7 @@ final class TempRepository
|
||||
*/
|
||||
private function all(): array
|
||||
{
|
||||
$contents = file_get_contents(self::FOLDER . '/' . $this->filename . '.json');
|
||||
$contents = file_get_contents(self::FOLDER.'/'.$this->filename.'.json');
|
||||
|
||||
assert(is_string($contents));
|
||||
|
||||
@ -67,12 +67,12 @@ final class TempRepository
|
||||
/**
|
||||
* Save the given elements.
|
||||
*
|
||||
* @param array<int, string> $elements
|
||||
* @param array<int, string> $elements
|
||||
*/
|
||||
private function save(array $elements): void
|
||||
{
|
||||
$contents = json_encode($elements);
|
||||
|
||||
file_put_contents(self::FOLDER . '/' . $this->filename . '.json', $contents);
|
||||
file_put_contents(self::FOLDER.'/'.$this->filename.'.json', $contents);
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,15 +54,15 @@ final class TestRepository
|
||||
/**
|
||||
* Uses the given `$testCaseClass` on the given `$paths`.
|
||||
*
|
||||
* @param array<int, string> $classOrTraits
|
||||
* @param array<int, string> $groups
|
||||
* @param array<int, string> $paths
|
||||
* @param array<int, Closure> $hooks
|
||||
* @param array<int, string> $classOrTraits
|
||||
* @param array<int, string> $groups
|
||||
* @param array<int, string> $paths
|
||||
* @param array<int, Closure> $hooks
|
||||
*/
|
||||
public function use(array $classOrTraits, array $groups, array $paths, array $hooks): void
|
||||
{
|
||||
foreach ($classOrTraits as $classOrTrait) {
|
||||
if (!class_exists($classOrTrait) && !trait_exists($classOrTrait)) {
|
||||
if (! class_exists($classOrTrait) && ! trait_exists($classOrTrait)) {
|
||||
throw new TestCaseClassOrTraitNotFound($classOrTrait);
|
||||
}
|
||||
}
|
||||
@ -90,7 +90,7 @@ final class TestRepository
|
||||
*/
|
||||
public function set(TestCaseMethodFactory $method): void
|
||||
{
|
||||
if (!array_key_exists($method->filename, $this->testCases)) {
|
||||
if (! array_key_exists($method->filename, $this->testCases)) {
|
||||
$this->testCases[$method->filename] = new TestCaseFactory($method->filename);
|
||||
}
|
||||
|
||||
@ -112,12 +112,12 @@ final class TestRepository
|
||||
*/
|
||||
private function make(TestCaseFactory $testCase): void
|
||||
{
|
||||
$startsWith = static fn (string $target, string $directory): bool => Str::startsWith($target, $directory . DIRECTORY_SEPARATOR);
|
||||
$startsWith = static fn (string $target, string $directory): bool => Str::startsWith($target, $directory.DIRECTORY_SEPARATOR);
|
||||
|
||||
foreach ($this->uses as $path => $uses) {
|
||||
[$classOrTraits, $groups, $hooks] = $uses;
|
||||
|
||||
if ((!is_dir($path) && $testCase->filename === $path) || (is_dir($path) && $startsWith($testCase->filename, $path))) {
|
||||
if ((! is_dir($path) && $testCase->filename === $path) || (is_dir($path) && $startsWith($testCase->filename, $path))) {
|
||||
foreach ($classOrTraits as $class) {
|
||||
/** @var string $class */
|
||||
if (class_exists($class)) {
|
||||
|
||||
Reference in New Issue
Block a user