我在Laravel 5.0,在我的请求类我使用的是不同的袋子来显示验证错误消息编写单元测试assertSessionHasErrors。LARAVEL 5.0 +单元测试 - 用不同的包装袋
我使用这在我的文件:
/* ExampleTest.php */
class ExampleTest extends TestCase {
public function testPostWithoutData(){
$response = $this->call('POST', 'url/to/post',[
'my_field' => ''
]);
$this->assertSessionHasErrors('my_field');
}
}
如果我运行测试,就不能得到正确的:
/* ExampleRequest.php */
namespace App\Http\Requests;
use App\Http\Requests\Request;
use Illuminate\Support\Facades\Auth;
class ExampleRequest extends Request {
protected $errorBag = 'otherbag';
public function rules(){
return [
'my_field' => 'required'
];
}
}
在我的测试文件,我使用的这个测试断言和返回这个问题:
Session missing error:
my_field
Failed asserting thatfalse
istrue
.
如果我拿出从请求文件中$errorBag
属性,我没有问题。
我可以根据需要提供更多细节。
你能解释一下为什么你的对象中有'protected $ errorBag ='otherbag';'?这是做什么的,为什么? –
因为我有两个地方可以显示erros im我的看法...并且我处理它与不同的袋子.... – giordanolima