Skip to content

PHP8 named arguments are not supported #547

Open

Description

@jorgsowa

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.

Activity

  1. changed the title [-]PHP8 named arguemnts are not supported[/-] [+]PHP8 named arguments are not supported[/+] on Nov 26, 2021
  2. jorgsowa commented on Feb 9, 2022

    @jorgsowa
    Author

    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')
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions