test: add tests for PUT JSON request and REQUEST

This commit is contained in:
kenjis 2023-06-21 17:11:53 +09:00
parent 63296dedaf
commit 9981d44acc
No known key found for this signature in database
GPG Key ID: BD254878922AF198

View File

@ -466,6 +466,54 @@ final class FeatureTestTraitTest extends CIUnitTestCase
);
}
public function testCallPutWithJsonRequest()
{
$this->withRoutes([
[
'put',
'home',
'\Tests\Support\Controllers\Popcorn::echoJson',
],
]);
$data = [
'true' => true,
'false' => false,
'int' => 2,
'null' => null,
'float' => 1.23,
'string' => 'foo',
];
$response = $this->withBodyFormat('json')
->call('put', 'home', $data);
$response->assertOK();
$response->assertJSONExact($data);
}
public function testCallPutWithJsonRequestAndREQUEST()
{
$this->withRoutes([
[
'put',
'home',
static fn () => json_encode(Services::request()->fetchGlobal('request')),
],
]);
$data = [
'true' => true,
'false' => false,
'int' => 2,
'null' => null,
'float' => 1.23,
'string' => 'foo',
];
$response = $this->withBodyFormat('json')
->call('put', 'home', $data);
$response->assertOK();
$this->assertStringContainsString('[]', $response->getBody());
}
public function testCallWithJsonRequest()
{
$this->withRoutes([