dtyyrt4545 2014-10-23 23:41
浏览 63
已采纳

Laracasts \ Validation \ FormValidationException:验证失败

In the 10th video of the Build Larabook from scratch Laracasts tutorial, the author runs a functional test that turns green:

enter image description here

where t is an alias for vendor/bin/codecept run functional in the Vagrant vm.

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:

<?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?

  • 写回答

1条回答 默认 最新

  • duanjianqu3685 2014-10-24 00:52
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?