Larave 单元测试,Call 方法传递的参数,Request 无法接收
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class TestUser extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testStoreUser()
{
$response = $this->call('POST','/api/users',[
'name'=>str_random(10),
'true_name'=>str_random(5),
'email'=>str_random('10').'@gmail.com',
'department_id'=>0,
'password'=>123456,
'address'=>'',
'phone'=>'0551-8959125',
'mobile_phone'=>'13214789512',
'usb_key'=>'',
]);
$this->assertEquals(200,$response->getStatusCode());
//$this->assertTrue(true);
}
}
class UserController {
public function store(Request $request)
{
//.....
return $request->input('name')
}
}
返回的却是如下图:
真是奇怪,不知道是什么原因?有遇到过的朋友吗?
PS:打印出来的log,获取的$request->all()
也是空。
@lx1036 感觉你的回答,use Illum.....肯定写了,我用的是api,在api.php里面定义的resource路由,找不到原因,好奇怪,也用了json同样的都是提交不了参数
@lx1036 感谢,打错了!