简体   繁体   English

Laracasts \\ Validation \\ FormValidationException:验证失败

[英]Laracasts\Validation\FormValidationException: Validation failed

In the 10th video of the Build Larabook from scratch Laracasts tutorial, the author runs a functional test that turns green: 从头开始构建Larabooks Laracasts教程的第10个视频中,作者运行了一个变为绿色的功能测试:

在此处输入图片说明

where t is an alias for vendor/bin/codecept run functional in the Vagrant vm . 其中t是Vagrant vm vendor/bin/codecept run functional的别名。

However, when I run the same test, it turns red: 但是,当我运行相同的测试时,它变成红色:

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.

Here is the content of my SignUpCept.php file: 这是我的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());

I must be missing something, but I cannot figure out what. 我一定想念什么,但我不知道是什么。

Any idea? 任何想法?

The problem was coming from the fact that the test was using the same data (username, email and password) as a user that was already in the database. 问题出在以下事实:测试使用的数据与数据库中已有的用户使用相同的数据(用户名,电子邮件和密码)。

Since the validation checks the uniqueness of each new user, the test was failing. 由于验证检查每个新用户的唯一性,因此测试失败。

I just removed the existing user from the database and the test passed. 我只是从数据库中删除了现有用户,并通过了测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM