/** * Test method for the <tt>create(array $json)</tt> function. */ public function testCreate() { // Test with a successful response $createMessageResponse = CreateMessageResponse::create(array('status_code' => 200, 'status_message' => 'OK', 'response' => array('Messages' => array('notificationCode0', 'notificationCode1', 'notificationCode2')))); $createMessageResponseResponse = $createMessageResponse->getResponse(); $this->assertNotNull($createMessageResponseResponse); $messages = $createMessageResponseResponse->getMessages(); $this->assertCount(3, $messages); $this->assertTrue(in_array('notificationCode0', $messages)); $this->assertTrue(in_array('notificationCode1', $messages)); $this->assertTrue(in_array('notificationCode2', $messages)); $this->assertTrue($createMessageResponse->isOk()); $this->assertEquals(200, $createMessageResponse->getStatusCode()); $this->assertEquals('OK', $createMessageResponse->getStatusMessage()); // Test with an error response without any 'response' field $createMessageResponse = CreateMessageResponse::create(array('status_code' => 400, 'status_message' => 'KO')); $createMessageResponseResponse = $createMessageResponse->getResponse(); $this->assertNull($createMessageResponseResponse); $this->assertFalse($createMessageResponse->isOk()); $this->assertEquals(400, $createMessageResponse->getStatusCode()); $this->assertEquals('KO', $createMessageResponse->getStatusMessage()); // Test with an error response with a null 'response' field // Fix https://github.com/gomoob/php-pushwoosh/issues/13 $createMessageResponse = CreateMessageResponse::create(array('status_code' => 400, 'status_message' => 'KO', 'response' => null)); $createMessageResponseResponse = $createMessageResponse->getResponse(); $this->assertNull($createMessageResponseResponse); $this->assertFalse($createMessageResponse->isOk()); $this->assertEquals(400, $createMessageResponse->getStatusCode()); $this->assertEquals('KO', $createMessageResponse->getStatusMessage()); }