/** * Test sendResponse method with exception rendering. */ public function testSendResponseWithException() { /** Mock all required objects. */ $this->rendererMock->expects($this->any())->method('getMimeType')->will($this->returnValue('application/json')); $this->rendererMock->expects($this->any())->method('render')->will($this->returnCallback([$this, 'callbackForSendResponseTest'], $this->returnArgument(0))); $exceptionMessage = 'Message'; $exceptionHttpCode = \Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST; $exception = new \Magento\Framework\Webapi\Exception(new Phrase($exceptionMessage), 0, $exceptionHttpCode); $this->errorProcessorMock->expects($this->any())->method('maskException')->will($this->returnValue($exception)); $this->responseRest->setException($exception); /** Start output buffering. */ ob_start(); $this->responseRest->sendResponse(); /** Clear output buffering. */ ob_end_clean(); $actualResponse = $this->responseRest->getBody(); $expectedResult = '{"message":"' . $exceptionMessage . '"}'; $this->assertStringStartsWith($expectedResult, $actualResponse, 'Response body is invalid'); }
/** * Test GetMimeType method. */ public function testGetMimeType() { $exceptedMimeType = 'application/xml'; $this->assertEquals($exceptedMimeType, $this->_restXmlRenderer->getMimeType(), 'Unexpected mime type.'); }