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

Mockery spy doesn't seem to work with named arguments #1188

Open
ipontt opened this issue Jul 23, 2022 · 0 comments
Open

Mockery spy doesn't seem to work with named arguments #1188

ipontt opened this issue Jul 23, 2022 · 0 comments

Comments

@ipontt
Copy link

ipontt commented Jul 23, 2022

I'm working on a PHP8.1 codebase and there's a simple test that is failing when I use named arguments. I couldn't find anything in the docs about this particular issue. Is Mockery not compatible with named arguments?

The test

$spy = Mockery::spy(SomeClass::class);
$param = ...

someFunction($spy, $param);

$spy->shouldHaveReceived(method: 'test', args: [$param]);

The function

function someFunction(SomeClass $sc, $param) {
    ...
    $sc->test(a: $param);
    ...
}

The spied class

class SomeClass {
    public function test($a) { ... }
}

test function result error
$spy->shouldHaveReceived(
    method: 'test',
    args: [$param]
);
$sc->test($param) $$\textcolor{green}{\text{PASS}}$$
$spy->shouldHaveReceived(
    method: 'test',
    args: [$param]
);
$sc->test(a: $param) $$\textcolor{red}{\text{FAIL}}$$ InvalidCountException ... should be called at least 1 times but callled 0 times
$spy->shouldHaveReceived(
    method: 'test',
    args: ['a' => $param]
);
$sc->test($param) $$\textcolor{red}{\text{FAIL}}$$ ErrorException Undefined array key 0
$spy->shouldHaveReceived(
    method: 'test',
    args: ['a' => $param]
);
$sc->test(a: $param) $$\textcolor{red}{\text{FAIL}}$$ ErrorException Undefined array key 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant