【发布时间】:2016-10-18 03:51:34
【问题描述】:
我有一个带有系统验证帐户的应用程序(注册 -> 获取带有激活链接的电子邮件 -> 帐户验证)。该验证流程是可选的,可以使用配置值关闭:
// config/auth.php
return [
// ...
'enable_verification' => true
];
我要测试注册控制器:
- 在这两种情况下都应该重定向到主页
- 启用验证时,主页应显示消息“已发送电子邮件”
- 验证关闭时,主页应显示消息“帐户已创建”
- 等
我的测试方法:
public function test_UserProperlyCreated_WithVerificationDisabled()
{
$this->app['config']->set('auth.verification.enabled', false);
$this
->visit(route('frontend.auth.register.form'))
->type('Test', 'name')
->type('test@example.com', 'email')
->type('123123', 'password')
->type('123123', 'password_confirmation')
->press('Register');
$this
->seePageIs('/')
->see(trans('auth.registration.complete'));
}
public function test_UserProperlyCreated_WithVerificationEnabled()
{
$this->app['config']->set('auth.verification.enabled', true);
$this
->visit(route('frontend.auth.register.form'))
->type('Test', 'name')
->type('test@example.com', 'email')
->type('123123', 'password')
->type('123123', 'password_confirmation')
->press('Register');
$this
->seePageIs('/')
->see(trans('auth.registration.needs_verification'));
}
在调试时,我注意到在控制器方法中的配置值总是设置为配置文件中的值,无论我用我的$this->app['config']->set...设置什么
我对用户存储库本身进行了其他测试,以检查它在验证打开或关闭时是否都有效。那里的测试按预期运行。
知道为什么控制器会失败以及如何解决这个问题吗?
【问题讨论】:
标签: php unit-testing laravel phpunit