Exemplo n.º 1
0
 public function testDispatchAllSchemaRequest()
 {
     $params = [\Magento\Framework\Webapi\Request::REQUEST_PARAM_SERVICES => 'all'];
     $this->_requestMock->expects($this->any())->method('getPathInfo')->willReturn(\Magento\Webapi\Controller\Rest::SCHEMA_PATH);
     $this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap([[\Magento\Framework\Webapi\Request::REQUEST_PARAM_SERVICES, null, 'all']]));
     $this->_requestMock->expects($this->any())->method('getParams')->will($this->returnValue($params));
     $this->_requestMock->expects($this->any())->method('getRequestedServices')->will($this->returnValue('all'));
     $schema = 'Some REST schema content';
     $this->swaggerGeneratorMock->expects($this->any())->method('generate')->willReturn($schema);
     $this->swaggerGeneratorMock->expects($this->once())->method('getListOfServices')->willReturn(['listOfServices']);
     $this->_restController->dispatch($this->_requestMock);
     $this->assertEquals($schema, $this->_responseMock->getBody());
 }
Exemplo n.º 2
0
 /**
  * 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');
 }