[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

@ -42,6 +42,30 @@ final class Backtrace
return $current[self::FILE];
}
/**
* Returns the current datasets file.
*/
public static function datasetsFile(): string
{
$current = null;
foreach (debug_backtrace(self::BACKTRACE_OPTIONS) as $trace) {
assert(array_key_exists(self::FILE, $trace));
if (Str::endsWith($trace['file'], 'Bootstrappers/BootFiles.php') || Str::endsWith($trace[self::FILE], 'overrides/Runner/TestSuiteLoader.php')) {
break;
}
$current = $trace;
}
if ($current === null) {
throw ShouldNotHappen::fromMessage('Dataset file not found.');
}
return $current[self::FILE];
}
/**
* Returns the filename that called the current function/method.
*/

View File

@ -59,6 +59,24 @@ 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.
*/