Пример #1
0
 /**
  * {@inheritDoc}
  */
 public function registerDevice(RegisterDeviceRequest $registerDeviceRequest)
 {
     // If the 'application' attribute is not set in the request we try to get a default one from the Pushwoosh
     // client
     if ($registerDeviceRequest->getApplication() === null) {
         // The 'application' must be set
         if (!isset($this->application)) {
             throw new PushwooshException('The  \'application\' property is not set !');
         }
         $registerDeviceRequest->setApplication($this->application);
     }
     $response = $this->cURLClient->pushwooshCall('registerDevice', $registerDeviceRequest->jsonSerialize());
     return RegisterDeviceResponse::create($response);
 }
 /**
  * Test method for the <tt>toJSON()</tt> function.
  */
 public function testToJSON()
 {
     $registerDeviceRequest = new RegisterDeviceRequest();
     // Test without the 'application' parameter set
     try {
         $registerDeviceRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'deviceType' parameter set
     $registerDeviceRequest->setApplication('APPLICATION');
     try {
         $registerDeviceRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with a bad 'deviceType' parameter set (special value 6)
     $registerDeviceRequest->setDeviceType(6);
     try {
         $registerDeviceRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with a bad 'deviceType' parameter set
     $registerDeviceRequest->setDeviceType(100);
     try {
         $registerDeviceRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'hwid' parameter set
     $registerDeviceRequest->setDeviceType(1);
     try {
         $registerDeviceRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'pushToken' parameter set
     $registerDeviceRequest->setHwid('HWID');
     try {
         $registerDeviceRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'timezone' parameter set
     $registerDeviceRequest->setPushToken('PUSH_TOKEN');
     $registerDeviceRequest->setTimezone(3600);
     // Test without the 'language' parameter set
     $array = $registerDeviceRequest->toJSON();
     $this->assertEquals('APPLICATION', $array['application']);
     $this->assertEquals(1, $array['device_type']);
     $this->assertEquals('HWID', $array['hwid']);
     $this->assertNull($array['language']);
     $this->assertEquals('PUSH_TOKEN', $array['push_token']);
     $this->assertEquals(3600, $array['timezone']);
     // Test with the 'language' parameter set
     $registerDeviceRequest->setLanguage('fr');
     $array = $registerDeviceRequest->toJSON();
     $this->assertEquals('APPLICATION', $array['application']);
     $this->assertEquals(1, $array['device_type']);
     $this->assertEquals('HWID', $array['hwid']);
     $this->assertEquals('fr', $array['language']);
     $this->assertEquals('PUSH_TOKEN', $array['push_token']);
     $this->assertEquals(3600, $array['timezone']);
     // Test that all the supported device types does not fail
     $registerDeviceRequest->setDeviceType(1)->toJSON();
     $registerDeviceRequest->setDeviceType(2)->toJSON();
     $registerDeviceRequest->setDeviceType(3)->toJSON();
     $registerDeviceRequest->setDeviceType(4)->toJSON();
     $registerDeviceRequest->setDeviceType(5)->toJSON();
     $registerDeviceRequest->setDeviceType(7)->toJSON();
     $registerDeviceRequest->setDeviceType(8)->toJSON();
     $registerDeviceRequest->setDeviceType(9)->toJSON();
     $registerDeviceRequest->setDeviceType(10)->toJSON();
 }
Пример #3
0
 /**
  * Test method for the <tt>registerDevice($registerDevice)</tt> function.
  *
  * @group PushwooshTest.testRegisterDevice
  */
 public function testRegisterDevice()
 {
     // 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);
     $registerDeviceRequest = RegisterDeviceRequest::create()->setPushToken('PUSH_TOKEN')->setLanguage('en')->setHwid('hwid')->setTimezone(3600)->setDeviceType(1);
     // Test with the 'application' parameter not defined
     try {
         $pushwoosh->registerDevice($registerDeviceRequest);
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with the 'application' parameter defined in the Pushwoosh client
     $pushwoosh->setApplication('APPLICATION');
     $registerDeviceRequest->setApplication(null);
     $pushwoosh->registerDevice($registerDeviceRequest);
     // Test with the 'application' parameter definied in the request
     $pushwoosh->setApplication(null);
     $registerDeviceRequest->setApplication('APPLICATION');
     $registerDeviceResponse = $pushwoosh->registerDevice($registerDeviceRequest);
     $this->assertTrue($registerDeviceResponse->isOk());
     $this->assertEquals(200, $registerDeviceResponse->getStatusCode());
     $this->assertEquals('OK', $registerDeviceResponse->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);
     $registerDeviceResponse = $pushwoosh->registerDevice($registerDeviceRequest);
     $this->assertFalse($registerDeviceResponse->isOk());
     $this->assertEquals(400, $registerDeviceResponse->getStatusCode());
     $this->assertEquals('KO', $registerDeviceResponse->getStatusMessage());
 }