/** * Test method for the <tt>toJSON()</tt> function. */ public function testToJSON() { $deleteMessageRequest = new DeleteMessageRequest(); // Test without the 'auth' parameter set try { $deleteMessageRequest->toJSON(); $this->fail('Must have thrown a PushwooshException !'); } catch (PushwooshException $pe) { // Expected } // Test without the 'message' parameter set $deleteMessageRequest->setAuth('XXXX'); try { $deleteMessageRequest->toJSON(); $this->fail('Must have thrown a PushwooshException !'); } catch (PushwooshException $pe) { // Expected } // Test with valid values $deleteMessageRequest->setMessage('MESSAGE'); $array = $deleteMessageRequest->toJSON(); $this->assertEquals('XXXX', $array['auth']); $this->assertEquals('MESSAGE', $array['message']); }
/** * {@inheritDoc} */ public function deleteMessage(DeleteMessageRequest $deleteMessageRequest) { // If the 'auth' parameter is not set in the request we try to get it from the Pushwoosh client if ($deleteMessageRequest->getAuth() === null) { // The 'auth' parameter is expected here if (!isset($this->auth)) { throw new PushwooshException('The \'auth\' parameter is not set !'); // Use the 'auth' parameter defined in the Pushwoosh client } else { $deleteMessageRequest->setAuth($this->auth); } } $response = $this->cURLClient->pushwooshCall('deleteMessage', $deleteMessageRequest->jsonSerialize()); return DeleteMessageResponse::create($response); }
/** * Test method for the <tt>deleteMessage($deleteMessageRequest)</tt> function. * * @group PushwooshTest.deleteMessage */ public function testDeleteMessage() { // 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); $deleteMessageRequest = DeleteMessageRequest::create()->setMessage('MESSAGE'); // Test with the 'auth' parameter not defined try { $pushwoosh->deleteMessage($deleteMessageRequest); $this->fail('Must have thrown a PushwooshException !'); } catch (PushwooshException $pe) { // Expected } // Test with the 'auth' parameter defined in the Pushwoosh client $pushwoosh->setAuth('AUTH'); $deleteMessageRequest->setAuth(null); $pushwoosh->deleteMessage($deleteMessageRequest); // Test with the 'auth' parameter definied in the request $pushwoosh->setAuth(null); $deleteMessageRequest->setAuth('AUTH'); $deleteMessageResponse = $pushwoosh->deleteMessage($deleteMessageRequest); $this->assertTrue($deleteMessageResponse->isOk()); $this->assertEquals(200, $deleteMessageResponse->getStatusCode()); $this->assertEquals('OK', $deleteMessageResponse->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); $deleteMessageResponse = $pushwoosh->deleteMessage($deleteMessageRequest); $this->assertFalse($deleteMessageResponse->isOk()); $this->assertEquals(400, $deleteMessageResponse->getStatusCode()); $this->assertEquals('KO', $deleteMessageResponse->getStatusMessage()); }