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

ReturnValueMap is invalid when trying to call with same arguments but different return #5794

Closed
SidoniaVidican-eagleeye opened this issue Apr 4, 2024 · 1 comment
Labels
feature/test-doubles Stubs and Mock Objects

Comments

@SidoniaVidican-eagleeye
Copy link

->willReturnMap([
    ['SELECT * from Cars limit 100', 100],
    ['SELECT * from Cars limit 100', 20],
]);

Trying this will always return 100, because the argument is the same in both invocations.
Could be easily fixed by changing public function invoke(Invocation $invocation): mixed inside ReturnValueMap to:

 foreach ($this->valueMap as **$key =>** $map) {
        if (!is_array($map) || $parameterCount !== (count($map) - 1)) {
            continue;
        }

        $return = array_pop($map);

        if ($invocation->parameters() === $map) {
            **unset($this->valueMap[$key]);**
            return $return;
        }
    }
@SidoniaVidican-eagleeye SidoniaVidican-eagleeye added the type/bug Something is broken label Apr 4, 2024
@sebastianbergmann sebastianbergmann added the feature/test-doubles Stubs and Mock Objects label Apr 4, 2024
@sebastianbergmann
Copy link
Owner

This is working as intended.

@sebastianbergmann sebastianbergmann removed the type/bug Something is broken label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-doubles Stubs and Mock Objects
Projects
None yet
Development

No branches or pull requests

2 participants