/** * 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()); }