/** * 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']); }
/** * {@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->toJSON()); return GetNearestZoneResponse::create($response); }