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 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启