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

Mocking callables by mocking __invoke() on stdClass #3873

Closed
morozov opened this issue Sep 20, 2019 · 1 comment
Closed

Mocking callables by mocking __invoke() on stdClass #3873

morozov opened this issue Sep 20, 2019 · 1 comment

Comments

@morozov
Copy link
Contributor

morozov commented Sep 20, 2019

Q A
PHPUnit version 8.3.0
PHP version 7.3.8
Installation Method Composer

As of 20b0b21, PHPUnit triggers a warning when a partial mock is created with a non-existing method. While this behavior looks reasonable per se, it breaks the technique of mocking callables which is not natively supported by PHPUnit:

public function testClosureIsCalled() : void
{
    $closure = $this->createPartialMock(stdClass::class, ['__invoke']);

    $closure->expects(
        $this->exactly(2)
    )->method('__invoke');

    $closure();
    $closure();
}

While I'm not proposing any specific solution to the problem, I'd like the developers to be aware of it. Escalating this warning to a failure in a future PHPUnit version will break existing tests without a known way to rework them.

@sebastianbergmann
Copy link
Owner

If at all, this should be taken care of in #3536.

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

2 participants