getMockBuilder(BrowserErrorPagePlugin::class)->setMethods(['sendResponse', 'generateBody'])->getMock(); $plugin->expects($this->once())->method('generateBody')->willReturn(':boom:'); $plugin->expects($this->once())->method('sendResponse'); /** @var \Sabre\DAV\Server | \PHPUnit\Framework\MockObject\MockObject $server */ $server = $this->getMockBuilder('Sabre\DAV\Server')->disableOriginalConstructor()->getMock(); $server->expects($this->once())->method('on'); $httpResponse = $this->getMockBuilder(Response::class)->disableOriginalConstructor()->getMock(); $httpResponse->expects($this->once())->method('addHeaders'); $httpResponse->expects($this->once())->method('setStatus')->with($expectedCode); $httpResponse->expects($this->once())->method('setBody')->with(':boom:'); $server->httpResponse = $httpResponse; $plugin->initialize($server); $plugin->logException($exception); } public function providesExceptions() { return [ [ 404, new NotFound()], [ 500, new \RuntimeException()], ]; } }