mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
feat(pending-higher-order-tests): adds code and tests
This commit is contained in:
@ -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]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -78,7 +78,9 @@ final class HigherOrderMessage
|
||||
|
||||
if ($throwable->getMessage() === sprintf(self::UNDEFINED_METHOD, $this->methodName)) {
|
||||
/** @var \ReflectionClass $reflection */
|
||||
$reflection = (new ReflectionClass($target))->getParentClass();
|
||||
$reflection = new ReflectionClass($target);
|
||||
/* @phpstan-ignore-next-line */
|
||||
$reflection = $reflection->getParentClass() ?: $reflection;
|
||||
Reflection::setPropertyValue($throwable, 'message', sprintf('Call to undefined method %s::%s()', $reflection->getName(), $this->methodName));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user