@@ -71,14 +71,16 @@ public function getRequestParts(): array
71
71
[ 'GET ' , 'http://localhost:9200 ' , ['Foo ' => 'bar ' , 'Content-Type ' => 'application/json ' ], []],
72
72
[ 'GET ' , 'http://localhost ' , ['Foo ' => 'bar ' , 'Content-Type ' => 'application/json ' ], []],
73
73
[ 'POST ' , 'http://localhost:9200 ' , ['Content-Type ' => 'application/json ' ], ['foo ' => 'bar ' ]],
74
- [ 'POST ' , 'http://localhost:9200 ' , ['Content-Type ' => 'application/x-ndjson ' ], [[ 'foo ' => 'bar ' ], ['bar ' => 'baz ' ]]]
74
+ [ 'POST ' , 'http://localhost:9200 ' , ['Content-Type ' => 'application/x-ndjson ' ], [[ 'foo ' => 'bar ' ], ['bar ' => 'baz ' ]]],
75
+ // test body as string
76
+ [ 'POST ' , 'http://localhost ' , ['Content-Type ' => 'application/x-ndjson ' ], '{"foo":"bar"} ' ]
75
77
];
76
78
}
77
79
78
80
/**
79
81
* @dataProvider getRequestParts
80
82
*/
81
- public function testCreateRequest (string $ method , string $ url , array $ headers , array $ body )
83
+ public function testCreateRequest (string $ method , string $ url , array $ headers , $ body )
82
84
{
83
85
$ request = $ this ->createRequest ($ method , $ url , $ headers , $ body );
84
86
$ this ->assertEquals ($ method , $ request ->getMethod ());
@@ -91,7 +93,11 @@ public function testCreateRequest(string $method, string $url, array $headers, a
91
93
$ this ->assertEquals ($ value , implode (', ' , $ header ));
92
94
}
93
95
if (!empty ($ body )) {
94
- $ this ->assertEquals ($ this ->bodySerialize ($ body , $ headers ['Content-Type ' ]), (string ) $ request ->getBody ());
96
+ if (is_array ($ body )) {
97
+ $ this ->assertEquals ($ this ->bodySerialize ($ body , $ headers ['Content-Type ' ]), (string ) $ request ->getBody ());
98
+ } else {
99
+ $ this ->assertEquals ($ body , (string ) $ request ->getBody ());
100
+ }
95
101
}
96
102
}
97
103
0 commit comments