Laracasts \ Validation \ FormValidationException:验证失败

时间:2014-10-23 23:41:07

标签: php validation laravel functional-testing

Build Larabook from the scratch Laracasts教程的第10个视频中,作者运行了一个变为绿色的功能测试:

enter image description here

其中t是Vagrant vendor/bin/codecept run functionalvm的别名。

但是,当我运行相同的测试时,它会变为红色:

vagrant@homestead:~/larabook$ vendor/bin/codecept run functional
Codeception PHP Testing Framework v2.0.7
Powered by PHPUnit 4.3.4 by Sebastian Bergmann.

Functional Tests (1) ----------------------------------------------------------------------------------------
Trying to sign up for a Larabook account (SignUpCept)                                                   Error
-------------------------------------------------------------------------------------------------------------


Time: 3.56 seconds, Memory: 18.75Mb

There was 1 error:

---------
1) Failed to sign up for a larabook account in SignUpCept (/home/vagrant/larabook/tests/functional/SignUpCept.php)
Couldn't click "Sign Up":
Laracasts\Validation\FormValidationException: Validation failed

Scenario Steps:
9. I click "Sign Up"
8. I fill field "Password Confirmation:","demo"
7. I fill field "Password:","demo"
6. I fill field "Email:","john@example.com"
5. I fill field "Username:","JohnDoe"
4. I see current url equals "/register"
3. I click "Sign Up!"


FAILURES!                          
Tests: 1, Assertions: 1, Errors: 1.

以下是我的SignUpCept.php文件的内容:

<?php

$I = new FunctionalTester($scenario);
$I->am('a guest');
$I->wantTo('sign up for a Larabook account');

$I->amOnPage('/');
$I->click('Sign Up!');
$I->seeCurrentUrlEquals('/register');

$I->fillField('Username:', "JohnDoe");
$I->fillField('Email:', "john@example.com");
$I->fillField('Password:', "demo");
$I->fillField('Password Confirmation:', "demo");
$I->click('Sign Up');

$I->seeCurrentUrlEquals('');
$I->see('Welcome to Larabook!');
$I->seeRecord('users', [
    'username' => 'JohnDoe',
    'email' => 'john@example.com'
]);

$I->assertTrue(Auth::check());

我必须遗漏一些东西,但我无法弄清楚是什么。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

问题来自于测试使用的数据(用户名,电子邮件和密码)与数据库中已有的用户相同。

由于验证检查每个新用户的唯一性,因此测试失败。

我刚刚从数据库中删除了现有用户并且测试通过了。

相关问题