mirror of
https://github.com/pestphp/pest.git
synced 2026-12-05 15:22:17 +01:00
fix: avoid passing an object when invoking static methods via reflection (#1988)
* fix: avoid passing an object when invoking static methods via reflection
PHP 8.6 deprecates passing an object to `ReflectionMethod::invoke()` for
static methods, which breaks higher-order assertions such as
`it('...')->assertTrue(true)` since `Assert::assertTrue()` is static.
* test: update visual snapshots for new reflection tests
This commit is contained in:
@@ -74,3 +74,29 @@ it('gets methods from classes', function (): void {
|
||||
'getBar',
|
||||
]);
|
||||
});
|
||||
|
||||
it('calls instance methods', function (): void {
|
||||
$class = new class
|
||||
{
|
||||
private string $foo = 'bar';
|
||||
|
||||
private function getFoo(): string
|
||||
{
|
||||
return $this->foo;
|
||||
}
|
||||
};
|
||||
|
||||
expect(Reflection::call($class, 'getFoo'))->toBe('bar');
|
||||
});
|
||||
|
||||
it('calls static methods without passing an object', function (): void {
|
||||
$class = new class
|
||||
{
|
||||
private static function concat(string $a, string $b): string
|
||||
{
|
||||
return $a.$b;
|
||||
}
|
||||
};
|
||||
|
||||
expect(Reflection::call($class, 'concat', ['foo', 'bar']))->toBe('foobar');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user