Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

joyjas77's avatar

Larabook Lesson 11 codeception error

I've finished Lesson 11 and everything appears to be working as it should be. My only problem is that codecept is throwing errors. It doesn't seem to be able to find my "Sign Up" button on the form (all of which I'm certain is there and works for me physically.). I'm sure it is probably a fairly simple problem but I have spent a while trying to figure it out to no avail.

The following is my out put from doing a functional test. Result is same with t and tf.

vagrant@homestead:~/code/larabook$ tf Codeception PHP Testing Framework v2.0.5 Powered by PHPUnit 4.3.0 by Sebastian Bergmann.

Functional Tests (1) ---------------------------------------------------------------------------------------------

Trying to sign up for a Larabook account (SignUpCept) Error

Time: 1.46 seconds, Memory: 18.75Mb

There was 1 error:


1) Failed to sign up for a larabook account in SignUpCept (/home/vagrant/code/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.

SignUpCert.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->click(['class' => 'btn btn-primary']);

I did try to change the "Sign Up" line in above file to see if this made any difference. It didn't still gave errors of not being able to find it.

The relevant section of create.blade.php

 <div class="form-group">
            {{ Form::submit('Sign Up', ['class' => 'btn btn-primary']) }}
        </div>

        {{ Form::close() }}

alternate create.blade.php

<div class="form-group">
       <input type="submit" value="Sign Up" id="submit">
</div>

Both same result <input type="submit" value="Sign Up" id="submit" /> same result. Any ideas?

0 likes
7 replies
theilen's avatar

The error messages Codeception gives you are a bit confusing at first. At least they were to me.

Your test fails with

Couldn't click "Sign Up": Laracasts\Validation\FormValidationException: Validation failed

That doesn't mean that Codeception was not able to click on the button. It means it clicked on the button but then an FormValidationException was thrown.

So you shouldn't look at your views for an error, but somewhere where you handle validations.

joyjas77's avatar

Thanks, I had been trying every combination here of the form. But looking through my code, I had no errors until lesson 11 towards the end.

As far as I'm aware my validation is working. If I don't populate the form I get 3 errors at the top, and I get errors if my passwords don't match, and if the username/email address is already in the database.

Here is my FormValidator.php file

<?php namespace Laracasts\Validation;

use Laracasts\Validation\FactoryInterface as ValidatorFactory;
use Laracasts\Validation\ValidatorInterface as ValidatorInstance;

abstract class FormValidator {

    /**
     * @var ValidatorFactory
     */
    protected $validator;

    /**
     * @var ValidatorInstance
     */
    protected $validation;

    /**
     * @var array
     */
    protected $messages = [];

    /**
     * @param ValidatorFactory $validator
     */
    function __construct(ValidatorFactory $validator)
    {
        $this->validator = $validator;
    }

    /**
     * Validate the form data
     *
     * @param array $formData
     * @return mixed
     * @throws FormValidationException
     */
    public function validate(array $formData)
    {
        $this->validation = $this->validator->make(
            $formData,
            $this->getValidationRules(),
            $this->getValidationMessages()
        );

        if ($this->validation->fails())
        {
            throw new FormValidationException('Validation failed', $this->getValidationErrors());
        }

        return true;
    }

    /**
     * @return array
     */
    public function getValidationRules()
    {
        return $this->rules;
    }

    /**
     * @return mixed
     */
    public function getValidationErrors()
    {
        return $this->validation->errors();
    }

    /**
     * @return mixed
     */
    public function getValidationMessages()
    {
        return $this->messages;
    }

}

Not quite sure where I'm going wrong as it appears to work.

Will go back over the videos as well.

joyjas77's avatar

Here's my controller

<?php

use Larabook\Forms\RegistrationForm;
use Larabook\Registration\RegisterUserCommand;
use Larabook\Core\CommandBus;

class RegistrationController extends \BaseController {

    use CommandBus;

    /*
     * @var RegistrationForm
     */
    private $registrationForm;
    /*
     * Constructor
     *
     * @param RegistrationForm $registrationForm
     */
    //just added public
    public function __construct(RegistrationForm $registrationForm)
    {
        $this->registrationForm = $registrationForm;
    }

    /**
     * Show the form to register a new user.
     *
     * @return Response
     */
    public function create()
    {
        return View::make('registration.create');
    }

    public function store()
    {
        $this->registrationForm->validate(Input::all());

        extract(Input::only('username', 'email', 'password'));

        $user = $this->execute(
            new RegisterUserCommand($username, $email, $password)
        );

        Auth::login($user);

        Flash::message('Glad to have you as a new Larabook member!');

        return Redirect::home();

    }


}

As I mentioned earlier it all seems to be working for me. It is just that when I run codeception to check if everything is working that I get an error. But as I'm new Laravel just hoping to get off on the right foot.

sitesense's avatar

Are you sure that the username and email that you are supplying are not already in the database?

$I->fillField('Username:', 'JohnDoe');
$I->fillField('Email:', 'john@example.com');
2 likes
joyjas77's avatar

sitesense, I wish I had some of your sense. A quick check and delete of JohnDoe on my database it passed like a charm. :-) Thanks all for you quick responses. Now I can get on with the series.

kavya's avatar

I do have the same problem but there is no records in the DB. Can any one help me.

Please or to participate in this conversation.