test: add tests for call() params and REQUEST

This commit is contained in:
kenjis 2023-06-21 16:52:48 +09:00
parent d96be52008
commit 63296dedaf
No known key found for this signature in database
GPG Key ID: BD254878922AF198

View File

@ -385,6 +385,33 @@ final class FeatureTestTraitTest extends CIUnitTestCase
);
}
public function testCallGetWithParamsAndREQEST()
{
$this->withRoutes([
[
'get',
'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->get('home', $data);
$response->assertOK();
$this->assertStringContainsString(
// All GET values will be strings.
'{"true":"1","false":"","int":"2","null":"","float":"1.23","string":"foo"}',
$response->getBody()
);
}
public function testCallPostWithParams()
{
$this->withRoutes([
@ -412,6 +439,33 @@ final class FeatureTestTraitTest extends CIUnitTestCase
);
}
public function testCallPostWithParamsAndREQUEST()
{
$this->withRoutes([
[
'post',
'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->post('home', $data);
$response->assertOK();
$this->assertStringContainsString(
// All POST values will be strings.
'{"true":"1","false":"","int":"2","null":"","float":"1.23","string":"foo"}',
$response->getBody()
);
}
public function testCallWithJsonRequest()
{
$this->withRoutes([