[feat] scoped datasets

This commit is contained in:
Fabio Ivona
2022-09-19 17:45:27 +02:00
parent 12618ff8b3
commit cbee6e76b0
16 changed files with 267 additions and 40 deletions

View File

@ -10,6 +10,7 @@ use Pest\PendingCalls\UsesCall;
use Pest\Repositories\DatasetsRepository;
use Pest\Support\Backtrace;
use Pest\Support\HigherOrderTapProxy;
use Pest\Support\Str;
use Pest\TestSuite;
use PHPUnit\Framework\TestCase;
@ -60,7 +61,17 @@ if (! function_exists('dataset')) {
*/
function dataset(string $name, Closure|iterable $dataset): void
{
DatasetsRepository::set($name, $dataset);
$file = Backtrace::datasetsFile();
$filename = Str::afterLast($file, DIRECTORY_SEPARATOR);
$scope = Str::beforeLast($file, DIRECTORY_SEPARATOR);
if (Str::afterLast($scope, DIRECTORY_SEPARATOR) === 'Datasets') {
$scope = Str::beforeLast($scope, DIRECTORY_SEPARATOR);
} elseif ($filename !== 'Datasets.php') {
$scope = $file;
}
DatasetsRepository::set($name, $dataset, $scope);
}
}