-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add support for stubbing and mocking closures #3536
Comments
I cannot promise acceptance of such a pull request but would, of course, consider it. |
This is already possible by mocking public function testClosureIsCalled() : void
{
$closure = $this->createPartialMock(stdClass::class, ['__invoke']);
$closure->expects(
$this->exactly(2)
)->method('__invoke');
$closure();
$closure();
} Unlike this workaround, the proposed API is not really flexible, however, it'd be nice if the workaround was formalized as a feature. |
@morozov
An API for this might be nice indeed! |
After some experimentation there still seems to be a method which works: $mock = $this
->getMockBuilder(\stdclass::class)
->addMethods(['__invoke'])
->getMock();
$mock
->expects(self::once())
->method('__invoke')); (Tested on PHPUnit 9 / PHP 7.3) |
Following up on this: #5759 |
Would you accept a PR to support mocking closure, to ease checking that one is called?
I.e : https://3v4l.org/Yaq5A
The text was updated successfully, but these errors were encountered: