Пример #1
0
 /**
  * Test method for the <tt>toJSON()</tt> function.
  */
 public function testToJSON()
 {
     $pushStatRequest = new PushStatRequest();
     // Test without the 'application' parameter set
     try {
         $pushStatRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'hash' parameter set
     $pushStatRequest->setApplication('APPLICATION');
     try {
         $pushStatRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'hwid' parameter set
     $pushStatRequest->setHash('hash');
     try {
         $pushStatRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with valid values
     $pushStatRequest->setHwid('HWID');
     $array = $pushStatRequest->toJSON();
     $this->assertEquals('APPLICATION', $array['application']);
     $this->assertEquals('hash', $array['hash']);
     $this->assertEquals('HWID', $array['hwid']);
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function pushStat(PushStatRequest $pushStatRequest)
 {
     // If the 'application' attribute is not set in the request we try to get a default one from the Pushwoosh
     // client
     if ($pushStatRequest->getApplication() === null) {
         // The 'application' must be set
         if (!isset($this->application)) {
             throw new PushwooshException('The  \'application\' property is not set !');
         }
         $pushStatRequest->setApplication($this->application);
     }
     $response = $this->cURLClient->pushwooshCall('pushState', $pushStatRequest->jsonSerialize());
     return PushStatResponse::create($response);
 }
Пример #3
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());
 }