Example #1
0
 public function testParseResponse()
 {
     $results = json_decode('{
         "multicast_id": 216,
         "success": 3,
         "failure": 3,
         "canonical_ids": 1,
         "results": [
             { "message_id": "1:0408" },
             { "error": "Unavailable" },
             { "error": "InvalidRegistration" },
             { "message_id": "1:1516" },
             { "message_id": "1:2342", "registration_id": "32" },
             { "error": "NotRegistered"}
         ]
     }', true);
     $response = new Response($results, new Notification(array(new Device(1), new Device(2), new Device(3), new Device(4), new Device(5), new Device(6))));
     $this->assertEquals(216, $response->getMulticastId());
     $this->assertEquals(3, $response->getNumSuccessful());
     $this->assertEquals(3, $response->getNumFailures());
     $this->assertEquals(1, $response->getNumCanonicalIds());
     $results = $response->getResults();
     $this->assertEquals('1:0408', $results[0]->getMessageId());
     $this->assertEquals(1, $results[0]->getDevice()->getRegistrationId());
     $this->assertTrue($results[0]->isSuccess());
     $this->assertEquals('Unavailable', $results[1]->getError());
     $this->assertEquals(2, $results[1]->getDevice()->getRegistrationId());
     $this->assertTrue($results[1]->hasError());
     $this->assertFalse($results[1]->isSuccess());
     $this->assertTrue($results[1]->isResendable());
     $this->assertEquals('InvalidRegistration', $results[2]->getError());
     $this->assertEquals(3, $results[2]->getDevice()->getRegistrationId());
     $this->assertTrue($results[2]->hasError());
     $this->assertFalse($results[2]->isSuccess());
     $this->assertFalse($results[2]->isResendable());
     $this->assertEquals('1:1516', $results[3]->getMessageId());
     $this->assertEquals(4, $results[3]->getDevice()->getRegistrationId());
     $this->assertTrue($results[3]->isSuccess());
     $this->assertEquals('1:2342', $results[4]->getMessageId());
     $this->assertEquals(32, $results[4]->getCanonicalId());
     $this->assertEquals(5, $results[4]->getDevice()->getRegistrationId());
     $this->assertTrue($results[4]->isSuccess());
     $this->assertEquals('NotRegistered', $results[5]->getError());
     $this->assertEquals(6, $results[5]->getDevice()->getRegistrationId());
     $this->assertTrue($results[5]->hasError());
     $this->assertFalse($results[5]->isSuccess());
     $this->assertFalse($results[5]->isResendable());
 }