getMockBuilder(Client::class)->onlyMethods(['send'])->getMock(); $callback = function(Request $value) { return (string)$value->getBody() === 'message=Test%3A+It+%2Aworks%2A+with+some+error+%5Bmarkup%5D%28https%3A%2F%2Fmy-url.com%29%21&level=error'; }; $mockClient->expects($this->once())->method('send')->with($this->callback($callback)); $gitterLog = $this->getMockBuilder(GitterLog::class)->onlyMethods(['getClient'])->getMock(); $gitterLog->expects($this->once())->method('getClient')->willReturn($mockClient); $gitterLog->write('Test: It *works* with some error [markup](https://my-url.com)!', LogLevel::ERROR); } }