Created
May 22, 2020 09:13
-
-
Save ziadoz/b68a45adf93aa9e2c94c80de301ac17d to your computer and use it in GitHub Desktop.
PHPUnit Mocking Closures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Closure can't be mocked because it's a final class. | |
// Mock another class instead and add __invoke to it. | |
$mockClosure = $this->getMockBuilder(\stdClass::class) | |
->addMethods(['__invoke']) | |
->getMock(); | |
$mockClosure->expects($this->exactly(1)) | |
->method('__invoke') | |
->willReturn('Hello, World!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment