/**
  * Test method for the <tt>toJSON()</tt> function.
  */
 public function testToJSON()
 {
     $getNearestZoneRequest = new GetNearestZoneRequest();
     // Test without the 'application' parameter set
     try {
         $getNearestZoneRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'hwid' parameter set
     $getNearestZoneRequest->setApplication('APPLICATION');
     try {
         $getNearestZoneRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'lat' parameter set
     $getNearestZoneRequest->setHwid('HWID');
     try {
         $getNearestZoneRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'lng' parameter set
     $getNearestZoneRequest->setLat(10.12345);
     try {
         $getNearestZoneRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with valid values
     $getNearestZoneRequest->setLng(28.12345);
     $array = $getNearestZoneRequest->toJSON();
     $this->assertEquals('APPLICATION', $array['application']);
     $this->assertEquals('HWID', $array['hwid']);
     $this->assertEquals(10.12345, $array['lat']);
     $this->assertEquals(28.12345, $array['lng']);
 }
Beispiel #2
0
 /**
  * {@inheritDoc}
  */
 public function getNearestZone(GetNearestZoneRequest $getNearestZoneRequest)
 {
     // If the 'application' attribute is not set in the request we try to get a default one from the Pushwoosh
     // client
     if ($getNearestZoneRequest->getApplication() === null) {
         // The 'application' must be set
         if (!isset($this->application)) {
             throw new PushwooshException('The  \'application\' property is not set !');
         }
         $getNearestZoneRequest->setApplication($this->application);
     }
     $response = $this->cURLClient->pushwooshCall('getNearestZone', $getNearestZoneRequest->jsonSerialize());
     return GetNearestZoneResponse::create($response);
 }
Beispiel #3
0
 /**
  * Test method for the <tt>getNearestZone($nearestZoneRequest)</tt> function.
  */
 public function testGetNearestZone()
 {
     // Create a fake CURL client
     $cURLClient = $this->getMock('Gomoob\\Pushwoosh\\ICURLClient');
     $cURLClient->expects($this->any())->method('pushwooshCall')->will($this->returnValue(array('status_code' => 200, 'status_message' => 'OK')));
     $pushwoosh = new Pushwoosh();
     $pushwoosh->setCURLClient($cURLClient);
     $getNearestZoneRequest = GetNearestZoneRequest::create()->setHwid('HWID')->setLat(1.0)->setLng(2.0);
     // Test with the 'application' parameter not defined
     try {
         $pushwoosh->getNearestZone($getNearestZoneRequest);
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with the 'application' parameter defined in the Pushwoosh client
     $pushwoosh->setApplication('APPLICATION');
     $getNearestZoneRequest->setApplication(null);
     $pushwoosh->getNearestZone($getNearestZoneRequest);
     // Test with the 'application' parameter definied in the request
     $pushwoosh->setApplication(null);
     $getNearestZoneRequest->setApplication('APPLICATION');
     $getNearestZoneResponse = $pushwoosh->getNearestZone($getNearestZoneRequest);
     $this->assertTrue($getNearestZoneResponse->isOk());
     $this->assertEquals(200, $getNearestZoneResponse->getStatusCode());
     $this->assertEquals('OK', $getNearestZoneResponse->getStatusMessage());
     // Test a call with an error response
     $cURLClient = $this->getMock('Gomoob\\Pushwoosh\\ICURLClient');
     $cURLClient->expects($this->any())->method('pushwooshCall')->will($this->returnValue(array('status_code' => 400, 'status_message' => 'KO')));
     $pushwoosh->setCURLClient($cURLClient);
     $getNearestZoneResponse = $pushwoosh->getNearestZone($getNearestZoneRequest);
     $this->assertFalse($getNearestZoneResponse->isOk());
     $this->assertEquals(400, $getNearestZoneResponse->getStatusCode());
     $this->assertEquals('KO', $getNearestZoneResponse->getStatusMessage());
 }