mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
test: add tests for call() params and REQUEST
This commit is contained in:
parent
d96be52008
commit
63296dedaf
@ -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([
|
||||
|
Loading…
x
Reference in New Issue
Block a user