Example #1
0
 /**
  * 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');
 }
Example #2
0
 public function testErrorDetection()
 {
     $response = Response::fromString($this->getTestOkResponse());
     $this->assertFalse($response->isError());
     $response->setCode(400);
     $this->assertTrue($response->isError());
     $response = new Response();
     $this->assertTrue($response->isError());
     $response = new Response();
     // Curl timeout
     $response->setErrorCode(68);
     $this->assertTrue($response->isError());
 }
Example #3
0
 /**
  * For paged response fetch next result
  *
  * @return \Zuora\Response
  */
 public function nextPage()
 {
     $data = $this->response->getData();
     if (isset($data['nextPage'])) {
         if (false !== strpos($data['nextPage'], $this->client->getEnvironment()->getUrl(''))) {
             $url = substr($data['nextPage'], strlen($this->client->getEnvironment()->getUrl('')));
             $url = parse_url($url);
             $path = $url['path'];
             parse_str($url['query'], $query);
             return $this->client->request($path, 'GET', $query);
         }
     }
     return null;
 }
 public function testApiExceptionToString()
 {
     $response = new Response();
     $response->setData(json_decode($this->error_data, true));
     $exception = new ApiException($response);
     $this->assertEquals($exception->getProcessId(), '3F7EA3FD706C7E7C');
     $this->assertCount(2, $exception->getReasons());
     foreach ($exception->getReasons() as $reason) {
         $this->assertTrue(in_array($reason->getCode(), array(53100020, 53100320)));
     }
     $string = $exception->__toString();
     $this->assertContains('3F7EA3FD706C7E7C', $string);
     foreach ($exception->getReasons() as $reason) {
         $this->assertContains((string) $reason->getCode(), $string);
         $this->assertContains($reason->getMessage(), $string);
     }
 }
Example #5
0
 /**
  * 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());
 }
 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());
 }