More tests

This commit is contained in:
Nuno Maduro
2023-05-27 14:08:38 +01:00
parent a90b90ad29
commit 26a6e7d712
12 changed files with 101 additions and 15 deletions

View File

@ -347,7 +347,7 @@ final class TestCall
{
if (! is_null($this->describing)) {
$this->testCaseMethod->describing = $this->describing;
$this->testCaseMethod->description = sprintf('`%s` > %s', $this->describing, $this->testCaseMethod->description);
$this->testCaseMethod->description = sprintf('`%s` %s', $this->describing, $this->testCaseMethod->description);
}
$this->testSuite->tests->set($this->testCaseMethod);

View File

@ -78,9 +78,7 @@ final class Backtrace
*/
public static function file(): string
{
$trace = debug_backtrace(self::BACKTRACE_OPTIONS)[1];
assert(array_key_exists(self::FILE, $trace));
$trace = self::backtrace();
return $trace[self::FILE];
}
@ -90,9 +88,7 @@ final class Backtrace
*/
public static function dirname(): string
{
$trace = debug_backtrace(self::BACKTRACE_OPTIONS)[1];
assert(array_key_exists(self::FILE, $trace));
$trace = self::backtrace();
return dirname($trace[self::FILE]);
}
@ -102,8 +98,30 @@ final class Backtrace
*/
public static function line(): int
{
$trace = debug_backtrace(self::BACKTRACE_OPTIONS)[1];
$trace = self::backtrace();
return $trace['line'] ?? 0;
}
/**
* @return array{function: string, line?: int, file: string, class?: class-string, type?: string, args?: mixed[], object?: object}
*/
private static function backtrace(): array
{
$backtrace = debug_backtrace(self::BACKTRACE_OPTIONS);
foreach ($backtrace as $trace) {
if (! isset($trace['file'])) {
continue;
}
if (str_contains($trace['file'], 'pest/src')) {
continue;
}
return $trace;
}
throw ShouldNotHappen::fromMessage('Backtrace not found.');
}
}