*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use function array_keys;
use function array_merge;
use function array_reverse;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionException;
use ReflectionMethod;
/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Reflection
{
/**
* @psalm-param class-string $className
* @psalm-param non-empty-string $methodName
*
* @psalm-return array{file: non-empty-string, line: non-negative-int}
*/
public static function sourceLocationFor(string $className, string $methodName): array
{
try {
$reflector = new ReflectionMethod($className, $methodName);
$file = $reflector->getFileName();
$line = $reflector->getStartLine();
} catch (ReflectionException) {
$file = 'unknown';
$line = 0;
}
return [
'file' => $file,
'line' => $line,
];
}
/**
* @psalm-return list