Skip to content

Commit ec8b782

Browse files
committed
Refactor json request test to add additional tests
1 parent f6b626d commit ec8b782

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -644,31 +644,40 @@ public function testPostCurlFileFormDataContentType()
644644

645645
public function testJSONRequest()
646646
{
647-
$data = array('key' => 'value');
648-
$expected_response = '{"key":"value"}';
647+
foreach (
648+
array(
649+
array(
650+
array(
651+
'key' => 'value',
652+
),
653+
'{"key":"value"}',
654+
),
655+
) as $test) {
656+
list($data, $expected_response) = $test;
649657

650-
$test = new Test();
651-
$this->assertEquals($expected_response, $test->server('post_json', 'POST', json_encode($data)));
658+
$test = new Test();
659+
$this->assertEquals($expected_response, $test->server('post_json', 'POST', json_encode($data)));
652660

653-
foreach (array(
654-
'Content-Type',
655-
'content-type',
656-
'CONTENT-TYPE') as $key) {
657661
foreach (array(
658-
'APPLICATION/JSON',
659-
'APPLICATION/JSON; CHARSET=UTF-8',
660-
'APPLICATION/JSON;CHARSET=UTF-8',
661-
'application/json',
662-
'application/json; charset=utf-8',
663-
'application/json;charset=UTF-8',
664-
) as $value) {
665-
$test = new Test();
666-
$test->curl->setHeader($key, $value);
667-
$this->assertEquals($expected_response, $test->server('post_json', 'POST', json_encode($data)));
668-
669-
$test = new Test();
670-
$test->curl->setHeader($key, $value);
671-
$this->assertEquals($expected_response, $test->server('post_json', 'POST', $data));
662+
'Content-Type',
663+
'content-type',
664+
'CONTENT-TYPE') as $key) {
665+
foreach (array(
666+
'APPLICATION/JSON',
667+
'APPLICATION/JSON; CHARSET=UTF-8',
668+
'APPLICATION/JSON;CHARSET=UTF-8',
669+
'application/json',
670+
'application/json; charset=utf-8',
671+
'application/json;charset=UTF-8',
672+
) as $value) {
673+
$test = new Test();
674+
$test->curl->setHeader($key, $value);
675+
$this->assertEquals($expected_response, $test->server('post_json', 'POST', json_encode($data)));
676+
677+
$test = new Test();
678+
$test->curl->setHeader($key, $value);
679+
$this->assertEquals($expected_response, $test->server('post_json', 'POST', $data));
680+
}
672681
}
673682
}
674683
}

0 commit comments

Comments
 (0)