jakeharris's avatar

Only one test will pass at a time (5.1)

I tried to post this a bit ago but I think the original post got lost in the nether thanks to some pasted smart quotes. If this is a double-post I do apologize.

I'm making a point to work on testing early on with a new project, but having a pretty rough time.

If I run either one of the tests below on their own, it will pass. However, when I attempt to run both tests, I am greeted with:

exception 'ErrorException' with message 'Undefined variable: errors’ in <compiled template path>

The views have some basic validation error rendering using this method: {{$errors->first('email')}}

<?php

class AuthTest extends TestCase {

    function __construct()
    {
        parent::setUp();
    }

    protected $baseUrl = "http://portal.dev";

    public function testUserRegistration()
    {
        $this->visit('/register')
             ->type('valid@email.com', 'email')
             ->press('Register')
             ->seePageIs('/login')
             ->see('The supplied email is already in the system. Login?');
    }

    public function testUserLogin()
    {
        $this->visit('/login')
                 ->seePageIs('/login')
                 ->type('valid@email.com', 'email')
                 ->type('goodpass', 'password')
                 ->press('Sign-In')
                 ->seePageIs('/dashboard'));
    }

}

It would appear something is going haywire with middleware and/or sessions, but I'm quite a bit green when it comes to phpunit, let alone testing Laravel.

Any guidance or clues are appreciated. Thanks!

0 likes
3 replies
luceos's avatar
luceos
Best Answer
Level 4

Do not manually call setUp in construct. setUp is ran before each test method. If you need to do some magic just extend the base TestCase and overrule the createApplication method.

Also do not override __construct without calling the parent.

jakeharris's avatar

Thank you so much for responding. I can't remember why I added the __construct(), and I'm certain at some point I was calling the parent-- but eventually took it out in a fit of rage trying to get thing to work. In any case, removing the thing altogether seemed to do the trick.

I'm sure I'll be harassing you in the slack channel again soon enough :)

Please or to participate in this conversation.