コード例 #1
0
 /**
  * Test method for the <tt>toJSON()</tt> function.
  */
 public function testToJSON()
 {
     $setBadgeRequest = new SetBadgeRequest();
     // Test without the 'application' parameter set
     try {
         $setBadgeRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'badge' parameter set
     $setBadgeRequest->setApplication('APPLICATION');
     try {
         $setBadgeRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'hwid' parameter set
     $setBadgeRequest->setBadge(5);
     try {
         $setBadgeRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     $setBadgeRequest->setHwid('HWID');
     // Test with valid values
     $array = $setBadgeRequest->toJSON();
     $this->assertEquals('APPLICATION', $array['application']);
     $this->assertEquals(5, $array['badge']);
     $this->assertEquals('HWID', $array['hwid']);
 }
コード例 #2
0
 /**
  * {@inheritDoc}
  */
 public function setBadge(SetBadgeRequest $setBadgeRequest)
 {
     // If the 'application' attribute is not set in the request we try to get a default one from the Pushwoosh
     // client
     if ($setBadgeRequest->getApplication() === null) {
         // The 'application' must be set
         if (!isset($this->application)) {
             throw new PushwooshException('The  \'application\' property is not set !');
         }
         $setBadgeRequest->setApplication($this->application);
     }
     $response = $this->cURLClient->pushwooshCall('setBadge', $setBadgeRequest->jsonSerialize());
     return SetBadgeResponse::create($response);
 }