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:
Owen Voke
2026-10-23 17:35:56 +01:00
committed by GitHub
parent 1b3ca5ba41
commit d534cb2c40
4 changed files with 31 additions and 3 deletions
+26
View File
@@ -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');
});