From 9981d44accf9561616a3dfbbe1d9cabb3be502b5 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 21 Jun 2023 17:11:53 +0900 Subject: [PATCH] test: add tests for PUT JSON request and REQUEST --- tests/system/Test/FeatureTestTraitTest.php | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/system/Test/FeatureTestTraitTest.php b/tests/system/Test/FeatureTestTraitTest.php index 2db6bcf964..73a0293e56 100644 --- a/tests/system/Test/FeatureTestTraitTest.php +++ b/tests/system/Test/FeatureTestTraitTest.php @@ -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([