Skip to content

Commit 5f2cdd2

Browse files
committed
test: add tests for $params in call()
1 parent e62b539 commit 5f2cdd2

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

tests/system/Test/FeatureTestTraitTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,60 @@ public function testIsOkWithRedirects()
358358
$this->assertTrue($response->isOK());
359359
}
360360

361+
public function testCallGetWithParams()
362+
{
363+
$this->withRoutes([
364+
[
365+
'get',
366+
'home',
367+
static fn () => json_encode(Services::request()->getGet()),
368+
],
369+
]);
370+
$data = [
371+
'true' => true,
372+
'false' => false,
373+
'int' => 2,
374+
'null' => null,
375+
'float' => 1.23,
376+
'string' => 'foo',
377+
];
378+
$response = $this->get('home', $data);
379+
380+
$response->assertOK();
381+
$this->assertStringContainsString(
382+
// All GET values will be strings.
383+
'{"true":"1","false":"","int":"2","null":"","float":"1.23","string":"foo"}',
384+
$response->getBody()
385+
);
386+
}
387+
388+
public function testCallPostWithParams()
389+
{
390+
$this->withRoutes([
391+
[
392+
'post',
393+
'home',
394+
static fn () => json_encode(Services::request()->getPost()),
395+
],
396+
]);
397+
$data = [
398+
'true' => true,
399+
'false' => false,
400+
'int' => 2,
401+
'null' => null,
402+
'float' => 1.23,
403+
'string' => 'foo',
404+
];
405+
$response = $this->post('home', $data);
406+
407+
$response->assertOK();
408+
$this->assertStringContainsString(
409+
// All POST values will be strings.
410+
'{"true":"1","false":"","int":"2","null":"","float":"1.23","string":"foo"}',
411+
$response->getBody()
412+
);
413+
}
414+
361415
public function testCallWithJsonRequest()
362416
{
363417
$this->withRoutes([

0 commit comments

Comments
 (0)