I'm learning codeigniter 4 and trying to build some test to my controller. I try to test my post method for my controller and create request instance and change to post method like the following CodeIgniter 4 Documentation : withRequest but I got errors like this:
There was 1 error:
1) Tests\Support\Controllers\UserControllerTest::testCreateUser
InvalidArgumentException: You must supply the parameters: uri, userAgent.
Why the error says uri, userAgent that in documentation just give example uri parameter? And when I look in URI class _construct I just need one argument $uri.
Any help?
Here is my code in controller test :
$request = new IncomingRequest(new \Config\App(), new URI("http://localhost:8080/users/create"));
$criteria = $this->fabricator->make()->toArray();
$criteria['password'] = 'masdika00';
$request->setMethod('post');
$request->setGlobal('post', $criteria);
$postresult = $this->withRequest($request)
->controller(Users::class)
->execute('create');
var_dump($request);
$this->assertTrue($result->isOK());
$this->assertTrue($result->see('welcome'));
My full controller test