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