Fix origin value in API Model tests

This commit is contained in:
Timothy Warren 2015-10-15 09:49:38 -04:00
parent 454679626c
commit 5bf46e0840

View File

@ -42,10 +42,16 @@ class BaseApiModelTest extends AnimeClient_TestCase {
$this->assertTrue(empty($baseApiModel->base_url)); $this->assertTrue(empty($baseApiModel->base_url));
} }
protected function getIp()
{
$response = $this->model->get('/ip');
$json = json_decode($response->getBody(), TRUE);
$ip = $json['origin'];
return $ip;
}
public function dataClient() public function dataClient()
{ {
$host = gethostname();
$ip = gethostbyname($host);
$user_agent = "Tim's Anime Client/2.0"; $user_agent = "Tim's Anime Client/2.0";
$headers = [ $headers = [
'User-Agent' => $user_agent 'User-Agent' => $user_agent
@ -76,7 +82,6 @@ class BaseApiModelTest extends AnimeClient_TestCase {
'Host' => 'httpbin.org', 'Host' => 'httpbin.org',
'User-Agent' => $user_agent 'User-Agent' => $user_agent
], ],
'origin' => $ip,
'url' => 'https://httpbin.org/get?foo=bar' 'url' => 'https://httpbin.org/get?foo=bar'
], ],
'is_json' => TRUE 'is_json' => TRUE
@ -106,7 +111,6 @@ class BaseApiModelTest extends AnimeClient_TestCase {
'Content-Type' => 'application/x-www-form-urlencoded' 'Content-Type' => 'application/x-www-form-urlencoded'
], ],
'json' => NULL, 'json' => NULL,
'origin' => $ip,
'url' => 'https://httpbin.org/post' 'url' => 'https://httpbin.org/post'
], ],
'is_json' => TRUE 'is_json' => TRUE
@ -136,7 +140,6 @@ class BaseApiModelTest extends AnimeClient_TestCase {
'Content-Type' => 'application/x-www-form-urlencoded' 'Content-Type' => 'application/x-www-form-urlencoded'
], ],
'json' => NULL, 'json' => NULL,
'origin' => $ip,
'url' => 'https://httpbin.org/put' 'url' => 'https://httpbin.org/put'
], ],
'is_json' => TRUE 'is_json' => TRUE
@ -166,7 +169,6 @@ class BaseApiModelTest extends AnimeClient_TestCase {
'Content-Type' => 'application/x-www-form-urlencoded' 'Content-Type' => 'application/x-www-form-urlencoded'
], ],
'json' => NULL, 'json' => NULL,
'origin' => $ip,
'url' => 'https://httpbin.org/patch' 'url' => 'https://httpbin.org/patch'
], ],
'is_json' => TRUE 'is_json' => TRUE
@ -196,7 +198,6 @@ class BaseApiModelTest extends AnimeClient_TestCase {
'Content-Type' => 'application/x-www-form-urlencoded' 'Content-Type' => 'application/x-www-form-urlencoded'
], ],
'json' => NULL, 'json' => NULL,
'origin' => $ip,
'url' => 'https://httpbin.org/delete' 'url' => 'https://httpbin.org/delete'
], ],
'is_json' => TRUE 'is_json' => TRUE
@ -209,6 +210,7 @@ class BaseApiModelTest extends AnimeClient_TestCase {
*/ */
public function testClient($method, $uri, $options, $expected, $is_json) public function testClient($method, $uri, $options, $expected, $is_json)
{ {
$result = $this->model->$method($uri, $options); $result = $this->model->$method($uri, $options);
if (is_null($result)) if (is_null($result))
@ -217,6 +219,9 @@ class BaseApiModelTest extends AnimeClient_TestCase {
return; return;
} }
// Because you have to make another api call to get the origin ip
// address, it needs to be retreived outside of the dataProvider method
$expected['origin'] = $this->getIp();
$actual = ($is_json) $actual = ($is_json)
? json_decode($result->getBody(), TRUE) ? json_decode($result->getBody(), TRUE)
: (string) $result->getBody(); : (string) $result->getBody();