Laravel 5.1单元测试对用户进行身份验证

时间:2018-07-31 12:13:29

标签: php laravel unit-testing phpunit phpunit-testing

我想在我的系统中测试用户的身份验证,在那里我有一些个性化的路由。

这是我测试的功能(在这种情况下,我为用户键入了错误的凭据,但始终成功:

public function testLoginFalse()
{
    $this->visit('/session/create')
        ->type('test@test.test', 'login')
        ->type('wrong-password', 'password')
        ->press('Login')
        ->seePageIs(route('pages.home'));
}

在这种情况下,测试的问题总是返回true,这应该是错误的地方!

我尝试了另一种方法来测试登录名,但似乎总是使用错误的凭据(相同的问题)进行工作:

public function testLoginFalse()
{
    $response = $this->route('POST', 'session.store', [
        'email' => 'test@test.test',
        'password' => 'wrong-password'
    ]);
    $this->assertEquals(302, $response->getStatusCode());
}

我看了其他同样主题的问题,但是没人能解决我的问题。

还有其他方法或更好的方法来测试用户的身份验证吗?

PS::用户test@test.test已存在于数据库中。
我正在使用Laravel 5.1

0 个答案:

没有答案
相关问题