【发布时间】:2021-04-07 05:52:03
【问题描述】:
我正在学习 codeigniter 4 并尝试为我的控制器构建一些测试。我尝试为我的控制器测试我的 post 方法并创建请求实例并更改为 post 方法,如下面的 CodeIgniter 4 Documentation : withRequest 但我得到了这样的错误:
There was 1 error:
1) Tests\Support\Controllers\UserControllerTest::testCreateUser
InvalidArgumentException: You must supply the parameters: uri, userAgent.
为什么错误说 uri, userAgent 在文档中只给出示例 uri 参数?当我查看 URI 类 _construct 时,我只需要一个参数 $uri。
有什么帮助吗?
这是我在控制器测试中的代码:
$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'));
我的完整controller test
【问题讨论】:
标签: php codeigniter codeigniter-4