Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP8 named arguments are not supported #547

Open
jorgsowa opened this issue Nov 26, 2021 · 1 comment
Open

PHP8 named arguments are not supported #547

jorgsowa opened this issue Nov 26, 2021 · 1 comment
Labels

Comments

@jorgsowa
Copy link

jorgsowa commented Nov 26, 2021

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.

@stof stof transferred this issue from phpspec/prophecy-phpunit Nov 26, 2021
@jorgsowa jorgsowa changed the title PHP8 named arguemnts are not supported PHP8 named arguments are not supported Nov 26, 2021
@jorgsowa
Copy link
Author

jorgsowa commented Feb 9, 2022

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')

@stof stof added the PHP8.0 label Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants