/**
  * Test method for the <tt>create()</tt> function.
  */
 public function testCreate()
 {
     $pushStatRequest = PushStatRequest::create();
     $this->assertNotNull($pushStatRequest);
 }
示例#2
0
 /**
  * Test method for the <tt>pushStat($pushStatRequest)</tt> function.
  */
 public function testPushStat()
 {
     // 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);
     $pushStatRequest = PushStatRequest::create()->setHwid('HWID')->setHash('hash');
     // Test with the 'application' parameter not defined
     try {
         $pushwoosh->pushStat($pushStatRequest);
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with the 'application' parameter defined in the Pushwoosh client
     $pushwoosh->setApplication('APPLICATION');
     $pushStatRequest->setApplication(null);
     $pushwoosh->pushStat($pushStatRequest);
     // Test with the 'application' parameter definied in the request
     $pushwoosh->setApplication(null);
     $pushStatRequest->setApplication('APPLICATION');
     $pushStatResponse = $pushwoosh->pushStat($pushStatRequest);
     $this->assertTrue($pushStatResponse->isOk());
     $this->assertEquals(200, $pushStatResponse->getStatusCode());
     $this->assertEquals('OK', $pushStatResponse->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);
     $pushStatResponse = $pushwoosh->pushStat($pushStatRequest);
     $this->assertFalse($pushStatResponse->isOk());
     $this->assertEquals(400, $pushStatResponse->getStatusCode());
     $this->assertEquals('KO', $pushStatResponse->getStatusMessage());
 }