Exemplo n.º 1
0
 /**
  * Test method for the <tt>setBadge($setBadgeRequest)</tt> function.
  *
  * @group PushwooshTest.setBadge
  */
 public function testSetBadge()
 {
     // 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);
     $setBadgeRequest = SetBadgeRequest::create()->setBadge(5)->setHwid('hwid');
     // Test with the 'application' parameter not defined
     try {
         $pushwoosh->setBadge($setBadgeRequest);
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with the 'application' parameter defined in the Pushwoosh client
     $pushwoosh->setApplication('APPLICATION');
     $setBadgeRequest->setApplication(null);
     $pushwoosh->setBadge($setBadgeRequest);
     // Test with the 'application' parameter definied in the request
     $pushwoosh->setApplication(null);
     $setBadgeRequest->setApplication('APPLICATION');
     $setBadgeResponse = $pushwoosh->setBadge($setBadgeRequest);
     $this->assertTrue($setBadgeResponse->isOk());
     $this->assertEquals(200, $setBadgeResponse->getStatusCode());
     $this->assertEquals('OK', $setBadgeResponse->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);
     $setBadgeResponse = $pushwoosh->setBadge($setBadgeRequest);
     $this->assertFalse($setBadgeResponse->isOk());
     $this->assertEquals(400, $setBadgeResponse->getStatusCode());
     $this->assertEquals('KO', $setBadgeResponse->getStatusMessage());
 }