Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHPUnit Mocking Closures
<?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
You can’t perform that action at this time.