feat(pending-higher-order-tests): adds code and tests

This commit is contained in:
Nuno Maduro
2020-06-04 01:34:03 +02:00
parent c81dce0f6d
commit aa1917c28d
6 changed files with 103 additions and 26 deletions

View File

@ -4,17 +4,46 @@ declare(strict_types=1);
namespace Pest\Support;
use Pest\Exceptions\ShouldNotHappen;
/**
* @internal
*/
final class Backtrace
{
/**
* @var string
*/
private const FILE = 'file';
/**
* Returns the current test file.
*/
public static function testFile(): string
{
$current = null;
foreach (debug_backtrace() as $trace) {
if (Str::endsWith($trace[self::FILE], 'vendor/phpunit/phpunit/src/Util/FileLoader.php')) {
break;
}
$current = $trace;
}
if ($current === null) {
throw ShouldNotHappen::fromMessage('Test file not found.');
}
return $current[self::FILE];
}
/**
* Returns the filename that called the current function/method.
*/
public static function file(): string
{
return debug_backtrace()[1]['file'];
return debug_backtrace()[1][self::FILE];
}
/**
@ -22,7 +51,7 @@ final class Backtrace
*/
public static function dirname(): string
{
return dirname(debug_backtrace()[1]['file']);
return dirname(debug_backtrace()[1][self::FILE]);
}
/**