/** * Test zuora response error * * @expectedException \Zuora\Exception\ApiException */ public function testClientLogicErrorResponse() { $enviroment = $this->getEnvironment(); $error_response = new Response(); $error_response->setCode(200)->setData(array('success' => false, 'processId' => '3F7EA3FD706C7E7C', 'reasons' => array(array('code' => 53100020, 'message' => ' {com.zuora.constraints.either_or_both}'), array('code' => 53100320, 'message' => "'termType' value should be one of: TERMED, EVERGREEN")))); $request = $this->getMock('\\Zuora\\Http\\RequestInterface'); $request->expects($this->once())->method('call')->will($this->returnValue($error_response)); $client = new Client($enviroment, $request); $client->request('test'); }
public function testResponseException() { $response = new Response(); $response->setData('test'); $exception = new ResponseException($response); $this->assertEquals($response->getData(), $exception->getData()); // Test default stack trace $this->assertContains('Stack trace', $exception->__toString()); // HTTP code $response->setCode(400); $this->assertEquals($exception->__toString(), '400'); $response->setCode(0); // cURL code $response->setErrorCode(68); $this->assertEquals($exception->__toString(), '(68)'); $response->setErrorCode(0); // cURL message $response->setErrorMessage('remote host timed out'); $this->assertContains($response->getErrorMessage(), $exception->__toString()); $this->assertContains($response->getErrorMessage(), $exception->getMessageFromResponse()); }
/** * Tests Response pagination and class mapping */ public function testResponseMethods() { $environment = $this->getEnvironment(); $response_data = array('success' => true, 'creditCards' => array(array('id' => md5(rand()))), 'nextPage' => $environment->getUrl('accounts') . '?page=2'); $http_response = new Response(); $http_response->setData($response_data)->setCode(200)->setHeaders(array()); $next_response = new Response(); $next_response->setCode(200)->setHeaders(array())->setData(array('nextPage' => $environment->getUrl('accounts') . '?page=3') + $response_data); $request = $this->getMock('\\Zuora\\Http\\RequestInterface'); $request->expects($this->once())->method('call')->with($this->equalTo($environment->getUrl('accounts')), $this->equalTo('GET'), $this->equalTo(array('page' => 2)), $this->anything(), $this->equalTo(array('apiAccessKeyId' => $environment->getUsername(), 'apiSecretAccessKey' => $environment->getPassword())))->will($this->returnValue($next_response)); $client = new Client($environment, $request); $response = new \Zuora\Response($http_response, $client); $next = $response->nextPage(); $this->assertEquals($next->getData(), $next_response->getData()); $cards = $response->map('creditCards', '\\Zuora\\Object\\CreditCard'); $this->assertInternalType('array', $cards); $response = new \Zuora\Response($http_response->setData(array()), $client); $this->assertNull($response->nextPage()); }