/** * Test method for the <tt>toJSON()</tt> function. */ public function testToJSON() { $unregisterDeviceRequest = new UnregisterDeviceRequest(); // Test without the 'application' parameter set try { $unregisterDeviceRequest->toJSON(); $this->fail('Must have thrown a PushwooshException !'); } catch (PushwooshException $pe) { // Expected } // Test without the 'hwid' parameter set $unregisterDeviceRequest->setApplication('APPLICATION'); try { $unregisterDeviceRequest->toJSON(); $this->fail('Must have thrown a PushwooshException !'); } catch (PushwooshException $pe) { // Expected } $unregisterDeviceRequest->setHwid('HWID'); // Test with valid values $array = $unregisterDeviceRequest->toJSON(); $this->assertEquals('APPLICATION', $unregisterDeviceRequest->getApplication()); $this->assertEquals('HWID', $unregisterDeviceRequest->getHwid()); }
/** * {@inheritDoc} */ public function unregisterDevice(UnregisterDeviceRequest $unregisterDeviceRequest) { // If the 'application' attribute is not set in the request we try to get a default one from the Pushwoosh // client if ($unregisterDeviceRequest->getApplication() === null) { // The 'application' must be set if (!isset($this->application)) { throw new PushwooshException('The \'application\' property is not set !'); } $unregisterDeviceRequest->setApplication($this->application); } $response = $this->cURLClient->pushwooshCall('unregisterDevice', $unregisterDeviceRequest->jsonSerialize()); return UnregisterDeviceResponse::create($response); }
/** * Test method for the <tt>unregisterDevice($unregisterDeviceRequest)</tt> function. * * @group PushwooshTest.testUnregisterDevice */ public function testUnregisterDevice() { // 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); $unregisterDeviceRequest = UnregisterDeviceRequest::create()->setHwid('hwid'); // Test with the 'application' parameter not defined try { $pushwoosh->unregisterDevice($unregisterDeviceRequest); $this->fail('Must have thrown a PushwooshException !'); } catch (PushwooshException $pe) { // Expected } // Test with the 'application' parameter defined in the Pushwoosh client $pushwoosh->setApplication('APPLICATION'); $unregisterDeviceRequest->setApplication(null); $pushwoosh->unregisterDevice($unregisterDeviceRequest); // Test with the 'application' parameter definied in the request $pushwoosh->setApplication(null); $unregisterDeviceRequest->setApplication('APPLICATION'); $unregisterDeviceResponse = $pushwoosh->unregisterDevice($unregisterDeviceRequest); $this->assertTrue($unregisterDeviceResponse->isOk()); $this->assertEquals(200, $unregisterDeviceResponse->getStatusCode()); $this->assertEquals('OK', $unregisterDeviceResponse->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); $unregisterDeviceResponse = $pushwoosh->unregisterDevice($unregisterDeviceRequest); $this->assertFalse($unregisterDeviceResponse->isOk()); $this->assertEquals(400, $unregisterDeviceResponse->getStatusCode()); $this->assertEquals('KO', $unregisterDeviceResponse->getStatusMessage()); }