Add DatasetInfo support class

This commit is contained in:
Fabio Ivona
2022-09-22 10:33:15 +02:00
parent cbee6e76b0
commit 80854d5f87
6 changed files with 101 additions and 44 deletions

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Pest\Support;
/**
* @internal
*/
final class DatasetInfo
{
public const DATASETS_DIR_NAME = 'Datasets';
public const DATASETS_FILE_NAME = 'Datasets.php';
public static function isInsideADatasetsDirectory(string $file): bool
{
return basename(dirname($file)) === self::DATASETS_DIR_NAME;
}
public static function isADatasetsFile(string $file): bool
{
return basename($file) === self::DATASETS_FILE_NAME;
}
public static function scope(string $file): string
{
if (self::isInsideADatasetsDirectory($file)) {
return dirname($file, 2);
}
if (self::isADatasetsFile($file)) {
return dirname($file);
}
return $file;
}
}

View File

@ -59,24 +59,6 @@ final class Str
return (string) preg_replace('/[^A-Z_a-z0-9\\\\]/', '', $code);
}
/**
* Return the remainder of a string after the last occurrence of a given value.
*/
public static function afterLast(string $subject, string $search): string
{
if ($search === '') {
return $subject;
}
$position = strrpos($subject, $search);
if ($position === false) {
return $subject;
}
return substr($subject, $position + strlen($search));
}
/**
* Get the portion of a string before the last occurrence of a given value.
*/