Hi,
I am following Build Larabook from Scracth, by Laracasts.
At the end of Lesson 10, the author runs a functional test that turns green.
However, when I run the same test (and everything is perfectly working up to that point), 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 doing something wrong, 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 check the uniqueness of each new user, the test was failing.
I just removed the existing user from the database and the test passed.
Same error but there is no records in db.
just change the username and email with different data. and should passed it. and no need to insert data on db;
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community