コード例 #1
0
 /**
  * Test method for the <tt>create(array $json)</tt> function.
  */
 public function testCreate()
 {
     // Test with a success response
     $getNearestZoneResponse = GetNearestZoneResponse::create(array('status_code' => 200, 'status_message' => 'OK', 'response' => array('name' => 'zoneName', 'lat' => 42, 'lng' => 13, 'range' => 100, 'distance' => 4715784)));
     $this->assertTrue($getNearestZoneResponse->isOk());
     $this->assertEquals(200, $getNearestZoneResponse->getStatusCode());
     $this->assertEquals('OK', $getNearestZoneResponse->getStatusMessage());
     $getNearestZoneResponseResponse = $getNearestZoneResponse->getResponse();
     $this->assertNotNull($getNearestZoneResponseResponse);
     $this->assertEquals('zoneName', $getNearestZoneResponseResponse->getName());
     $this->assertEquals(42, $getNearestZoneResponseResponse->getLat());
     $this->assertEquals(13, $getNearestZoneResponseResponse->getLng());
     $this->assertEquals(100, $getNearestZoneResponseResponse->getRange());
     $this->assertEquals(4715784, $getNearestZoneResponseResponse->getDistance());
     // Test with an error response without any 'response' field
     $getNearestZoneResponse = GetNearestZoneResponse::create(array('status_code' => 400, 'status_message' => 'KO'));
     $this->assertFalse($getNearestZoneResponse->isOk());
     $this->assertEquals(400, $getNearestZoneResponse->getStatusCode());
     $this->assertEquals('KO', $getNearestZoneResponse->getStatusMessage());
     // Test with an error response with a null 'response' field
     // Fix https://github.com/gomoob/php-pushwoosh/issues/13
     $getNearestZoneResponse = GetNearestZoneResponse::create(array('status_code' => 400, 'status_message' => 'KO', 'response' => null));
     $this->assertFalse($getNearestZoneResponse->isOk());
     $this->assertEquals(400, $getNearestZoneResponse->getStatusCode());
     $this->assertEquals('KO', $getNearestZoneResponse->getStatusMessage());
 }
コード例 #2
0
 /**
  * Utility function used to create a new instance from a JSON string.
  *
  * @param array $json a PHP array which contains the result of a 'json_decode' execution.
  *
  * @return \Gomoob\Pushwoosh\Model\Response\GetNearestZoneResponse the resulting instance.
  */
 public static function create(array $json)
 {
     $getNearestZoneResponse = new GetNearestZoneResponse();
     $getNearestZoneResponse->setStatusCode($json['status_code']);
     $getNearestZoneResponse->setStatusMessage($json['status_message']);
     // If a 'response' is provided
     if (array_key_exists('response', $json) && isset($json['response'])) {
         $getNearestZoneResponseResponse = new GetNearestZoneResponseResponse();
         $getNearestZoneResponseResponse->setDistance($json['response']['distance']);
         $getNearestZoneResponseResponse->setLat($json['response']['lat']);
         $getNearestZoneResponseResponse->setLng($json['response']['lng']);
         $getNearestZoneResponseResponse->setName($json['response']['name']);
         $getNearestZoneResponseResponse->setRange($json['response']['range']);
         $getNearestZoneResponse->setResponse($getNearestZoneResponseResponse);
     }
     return $getNearestZoneResponse;
 }