phpspec / prophecy

Highly opinionated mocking framework for PHP 5.3+
MIT License
8.53k stars 241 forks source link

PHP8 named arguments are not supported #547

Open jorgsowa opened 2 years ago

jorgsowa commented 2 years ago

I found out that it's not possible to mock methods which are using named parameters. Example:

$this->repository = $this->prophesize(Repository::class);
$this->repository
            ->get([self::ID], orderBy: 'sort, id')
            ->willReturn($objects)
            ->shouldBeCalledOnce();

The same parameters are used in the referenced method, but still, I can't mock this function and receive the error: Return value must be of type Objects, null returned.

When I provide defaults values for all the preceding parameters it works fine.

jorgsowa commented 2 years ago

Workaround for this issue. Just add all missing parameters with the default value preceding the named arguments (any named arguments. Those must be in the correct order.

$this->repository
            ->get([self::ID], false, true, false, orderBy: 'sort, id')