mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 04:01:47 +00:00
Refactor json request test to add additional tests
This commit is contained in:
@@ -644,31 +644,40 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testJSONRequest()
|
||||
{
|
||||
$data = array('key' => 'value');
|
||||
$expected_response = '{"key":"value"}';
|
||||
foreach (
|
||||
array(
|
||||
array(
|
||||
array(
|
||||
'key' => 'value',
|
||||
),
|
||||
'{"key":"value"}',
|
||||
),
|
||||
) as $test) {
|
||||
list($data, $expected_response) = $test;
|
||||
|
||||
$test = new Test();
|
||||
$this->assertEquals($expected_response, $test->server('post_json', 'POST', json_encode($data)));
|
||||
$test = new Test();
|
||||
$this->assertEquals($expected_response, $test->server('post_json', 'POST', json_encode($data)));
|
||||
|
||||
foreach (array(
|
||||
'Content-Type',
|
||||
'content-type',
|
||||
'CONTENT-TYPE') as $key) {
|
||||
foreach (array(
|
||||
'APPLICATION/JSON',
|
||||
'APPLICATION/JSON; CHARSET=UTF-8',
|
||||
'APPLICATION/JSON;CHARSET=UTF-8',
|
||||
'application/json',
|
||||
'application/json; charset=utf-8',
|
||||
'application/json;charset=UTF-8',
|
||||
) as $value) {
|
||||
$test = new Test();
|
||||
$test->curl->setHeader($key, $value);
|
||||
$this->assertEquals($expected_response, $test->server('post_json', 'POST', json_encode($data)));
|
||||
'Content-Type',
|
||||
'content-type',
|
||||
'CONTENT-TYPE') as $key) {
|
||||
foreach (array(
|
||||
'APPLICATION/JSON',
|
||||
'APPLICATION/JSON; CHARSET=UTF-8',
|
||||
'APPLICATION/JSON;CHARSET=UTF-8',
|
||||
'application/json',
|
||||
'application/json; charset=utf-8',
|
||||
'application/json;charset=UTF-8',
|
||||
) as $value) {
|
||||
$test = new Test();
|
||||
$test->curl->setHeader($key, $value);
|
||||
$this->assertEquals($expected_response, $test->server('post_json', 'POST', json_encode($data)));
|
||||
|
||||
$test = new Test();
|
||||
$test->curl->setHeader($key, $value);
|
||||
$this->assertEquals($expected_response, $test->server('post_json', 'POST', $data));
|
||||
$test = new Test();
|
||||
$test->curl->setHeader($key, $value);
|
||||
$this->assertEquals($expected_response, $test->server('post_json', 'POST', $data));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user