Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function setTags(SetTagsRequest $setTagsRequest)
 {
     // If the 'application' attribute is not set in the request we try to get a default one from the Pushwoosh
     // client
     if ($setTagsRequest->getApplication() === null) {
         // The 'application' must be set
         if (!isset($this->application)) {
             throw new PushwooshException('The  \'application\' property is not set !');
         }
         $setTagsRequest->setApplication($this->application);
     }
     $response = $this->cURLClient->pushwooshCall('setTags', $setTagsRequest->jsonSerialize());
     return SetTagsResponse::create($response);
 }
Exemplo n.º 2
0
 /**
  * Test method for the <tt>toJSON()</tt> function.
  */
 public function testToJSON()
 {
     $setTagsRequest = new SetTagsRequest();
     // Test without the 'application' parameter set
     try {
         $setTagsRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'hwid' parameter set
     $setTagsRequest->setApplication('APPLICATION');
     try {
         $setTagsRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'tags' parameter set
     $setTagsRequest->setHwid('HWID');
     try {
         $setTagsRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     $setTagsRequest->setTags(array('tag0' => 'tag0_value', 'tag1' => 'tag1_value', 'tag2' => 'tag2_value'));
     // Test with valid values
     $array = $setTagsRequest->toJSON();
     $this->assertEquals('APPLICATION', $setTagsRequest->getApplication());
     $this->assertEquals('HWID', $setTagsRequest->getHwid());
     $tags = $array['tags'];
     $this->assertCount(3, $tags);
     $this->assertTrue(array_key_exists('tag0', $tags));
     $this->assertTrue(array_key_exists('tag1', $tags));
     $this->assertTrue(array_key_exists('tag2', $tags));
     $this->assertEquals('tag0_value', $tags['tag0']);
     $this->assertEquals('tag1_value', $tags['tag1']);
     $this->assertEquals('tag2_value', $tags['tag2']);
 }