Skip to content

Deprecate InvocationMocker::willReturnOnConsecutiveCalls() #5425

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

Closed
sebastianbergmann opened this issue Jun 24, 2023 · 4 comments
Closed

Deprecate InvocationMocker::willReturnOnConsecutiveCalls() #5425

sebastianbergmann opened this issue Jun 24, 2023 · 4 comments
Assignees
Labels
feature/test-doubles Test Stubs and Mock Objects type/deprecation Something will be/is deprecated

Comments

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Jun 24, 2023

To reduce complexity inside PHPUnit's test double functionality, InvocationMocker::willReturnOnConsecutiveCalls() will be deprecated and then removed:

  • soft deprecation in PHPUnit 10.3 (add @deprecated annotation to the method declaration)
  • deprecation in PHPUnit 11 (using the method will trigger a deprecation)
  • removal in PHPUnit 12
@sebastianbergmann sebastianbergmann added feature/test-doubles Test Stubs and Mock Objects type/deprecation Something will be/is deprecated labels Jun 24, 2023
@sebastianbergmann sebastianbergmann added this to the PHPUnit 11.0 milestone Jun 24, 2023
@sebastianbergmann sebastianbergmann self-assigned this Jun 24, 2023
sebastianbergmann added a commit that referenced this issue Jun 24, 2023

Verified

This commit was signed with the committer’s verified signature.
sebastianbergmann Sebastian Bergmann
@sebastianbergmann sebastianbergmann removed this from the PHPUnit 11.0 milestone Aug 14, 2023
sebastianbergmann added a commit that referenced this issue Aug 14, 2023

Verified

This commit was signed with the committer’s verified signature.
sebastianbergmann Sebastian Bergmann
This reverts commit af70ca0.
@TechhDan
Copy link

Hi! If anyone is looking for a replacement for this method this one has helped me out.

$userCallCount = 0;
$this->user->expects($this->exactly(2))
    ->method('__get')
    ->willReturnCallback(function ($name) use (&$userCallCount) {
        $userCallCount++;
        switch ($userCallCount) {
            case 1:
                return 1;
            case 2:
                return 2;
        }
    });

@sebastianbergmann
Copy link
Owner Author

Apparently ...

grafik

... was not enough and an explicit comment is needed: InvocationStubber::willReturnOnConsecutiveCalls() is no longer deprecated.

@nicolas-grekas
Copy link
Contributor

Thank you, I missed it indeed :)

@m-strzalka
Copy link

So it is no longer deprecated and will stay as a feature for the foreseeable future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-doubles Test Stubs and Mock Objects type/deprecation Something will be/is deprecated
Projects
None yet
Development

No branches or pull requests

4 participants