Ejemplo n.º 1
0
 public function testProcessingInvalidMethod()
 {
     $body = CM_Params::jsonEncode(['method' => 'foo']);
     $request = new CM_Http_Request_Post('/rpc/' . CM_Site_Abstract::factory()->getType(), null, null, $body);
     $response = new CM_Http_Response_RPC($request, $this->getServiceManager());
     $response->process();
     $responseData = CM_Params::jsonDecode($response->getContent());
     $this->assertSame(['error' => ['type' => 'CM_Exception_InvalidParam', 'msg' => 'Internal server error', 'isPublic' => false]], $responseData);
 }
Ejemplo n.º 2
0
 public function testProcessExceptionCatching()
 {
     CM_Config::get()->CM_Http_Response_RPC->catchPublicExceptions = true;
     CM_Config::get()->CM_Http_Response_RPC->exceptionsToCatch = ['CM_Exception_Nonexistent' => []];
     $site = $this->getMockSite();
     /** @var CM_Http_Request_Abstract|\Mocka\AbstractClassTrait $request */
     $request = $this->mockObject('CM_Http_Request_Abstract', ['/rpc', ['host' => $site->getHost()]]);
     $request->mockMethod('getQuery')->set(function () {
         throw new CM_Exception_Invalid('foo', null, null, ['messagePublic' => new CM_I18n_Phrase('bar')]);
     });
     $response = CM_Http_Response_RPC::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     $responseData = CM_Params::jsonDecode($response->getContent());
     $this->assertSame(['type' => 'CM_Exception_Invalid', 'msg' => 'bar', 'isPublic' => true], $responseData['error']);
     $request->mockMethod('getQuery')->set(function () {
         throw new CM_Exception_Nonexistent('foo');
     });
     $response = new CM_Http_Response_RPC($request, $site, CMTest_TH::getServiceManager());
     $response->process();
     $responseData = CM_Params::jsonDecode($response->getContent());
     $this->assertSame(['type' => 'CM_Exception_Nonexistent', 'msg' => 'Internal server error', 'isPublic' => false], $responseData['error']);
 }