mirror of
https://github.com/pestphp/pest.git
synced 2026-03-09 09:17:23 +01:00
remove hardcoded string
This commit is contained in:
@ -136,43 +136,6 @@ final class DatasetsRepository
|
||||
return $namedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Closure|iterable<int|string, mixed>
|
||||
*/
|
||||
private static function getScopedDataset(string $name, string $currentTestFile)
|
||||
{
|
||||
$matchingDatasets = array_filter(self::$datasets, function (string $key) use ($name, $currentTestFile) {
|
||||
[$datasetScope, $datasetName] = explode(self::SEPARATOR, $key);
|
||||
|
||||
if ($name !== $datasetName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! str_starts_with($currentTestFile, $datasetScope)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
|
||||
$closestScopeDatasetKey = array_reduce(
|
||||
array_keys($matchingDatasets),
|
||||
fn ($keyA, $keyB) => $keyA !== null && strlen($keyA) > strlen($keyB) ? $keyA : $keyB
|
||||
);
|
||||
if ($keyA === null) {
|
||||
return $keyB;
|
||||
}
|
||||
|
||||
return strlen($keyA) > strlen($keyB) ? $keyA : $keyB;
|
||||
});
|
||||
|
||||
if ($closestScopeDatasetKey === null) {
|
||||
throw new DatasetDoesNotExist($name);
|
||||
}
|
||||
|
||||
return $matchingDatasets[$closestScopeDatasetKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $datasets
|
||||
* @return array<array<mixed>>
|
||||
@ -211,6 +174,37 @@ final class DatasetsRepository
|
||||
return $processedDatasets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Closure|iterable<int|string, mixed>
|
||||
*/
|
||||
private static function getScopedDataset(string $name, string $currentTestFile)
|
||||
{
|
||||
$matchingDatasets = array_filter(self::$datasets, function (string $key) use ($name, $currentTestFile) {
|
||||
[$datasetScope, $datasetName] = explode(self::SEPARATOR, $key);
|
||||
|
||||
if ($name !== $datasetName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! str_starts_with($currentTestFile, $datasetScope)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
|
||||
$closestScopeDatasetKey = array_reduce(
|
||||
array_keys($matchingDatasets),
|
||||
fn ($keyA, $keyB) => $keyA !== null && strlen($keyA) > strlen($keyB) ? $keyA : $keyB
|
||||
);
|
||||
|
||||
if ($closestScopeDatasetKey === null) {
|
||||
throw new DatasetDoesNotExist($name);
|
||||
}
|
||||
|
||||
return $matchingDatasets[$closestScopeDatasetKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array<mixed>> $combinations
|
||||
* @return array<array<array<mixed>>>
|
||||
|
||||
Reference in New Issue
Block a user