2
votes

I'm completely new in testing. I'm trying to test the login using Laracasts/Integrated

/** @test */
public function it_should_login_user()
{
    $credentials = [
        'email'    => '[email protected]',
        'password' => '12345'
    ];
    $this->visit('/auth/login')
        ->submitForm('Login',  $credentials)
        ->andSee('Dashboard')->onPage('/');
}

I have an H1 header with the legend "Dashboard" but I get this error

1) ExampleTest::it_should_login_user A GET request to 'http://localhost/auth/login' failed. Got a 500 code instead.

PDOException on /Users/marionava/Code/ilencuentro/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php line 47

Could you help me?

1

1 Answers

-3
votes

I solved this using a method call be() on the TestCase file. Then I create a login method with it and that's all.

//TestCase.php

use Ilencuentro\User;
use Laracasts\Integrated\Extensions\Laravel as IntegrationTest;
use Laracasts\Integrated\Services\Laravel\DatabaseTransactions;

class TestCase extends IntegrationTest {

    use DatabaseTransactions;

    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';

        $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

        return $app;
    }

    public function login()
    {
        $user = User::first();
        $this->be($user);
    }

}

Then I use this method in the place that I need.