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

lat4732's avatar
Level 12

Running php artisan test results in 3 failed, 4 skipped, 26 passed

Hey!

This is the first time I have run the php artisan test since working on the application (Laravel 8) and the result is

Tests:  3 failed, 4 skipped, 26 passed

I haven't touched anything in the tests folder ever which makes me think that these tests should actually be 100% passed no matter what, because they are provided out of the box and for reason. Here are the 3 failed tests

  • Tests\Feature\RegistrationTest > new users can register
  The user is not authenticated
  Failed asserting that false is true.


  • Tests\Feature\EmailVerificationTest > email can be verified
  Failed asserting that two strings are equal.


  • Tests\Feature\AuthenticationTest > users can authenticate using the login screen
  The user is not authenticated
  Failed asserting that false is true.

I have no idea how to fix these failed tests. What are they about? I can't clearly understand what's the meaning of them. What to do with the 4 skipped and why they are skipped?

0 likes
15 replies
rodrigo.pedra's avatar

Did you change any logic on the related controllers?

Or removed any of them, due to not using a feature, such the one which verifies emails?

Test cases test the code, even if you didn't touch the test cases before, but if you changed the code they are testing, some could fail due to the changes made.

You should run your test cases when making changes to your app, and then either fix your code if the changes break the test cases, or update the test cases directly affected by the changes, if the changes are about the test case's subjects.

lat4732's avatar
Level 12

@rodrigo.pedra I haven't touched anything on the related controllers. I've never removed any controller. What can I do? I feel confused..

lat4732's avatar
Level 12

@rodrigo.pedra This is how my for example AuthenticationTest looks like

<?php

namespace Tests\Feature;

use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class AuthenticationTest extends TestCase
{
    use RefreshDatabase;

    public function test_login_screen_can_be_rendered()
    {
        $response = $this->get('/login');

        $response->assertStatus(200);
    }

    public function test_users_can_authenticate_using_the_login_screen()
    {
        $user = User::factory()->create();

        $response = $this->post('/login', [
            'email' => $user->email,
            'password' => 'password',
        ]);

        $this->assertAuthenticated();
        $response->assertRedirect(RouteServiceProvider::HOME);
    }

    public function test_users_can_not_authenticate_with_invalid_password()
    {
        $user = User::factory()->create();

        $this->post('/login', [
            'email' => $user->email,
            'password' => 'wrong-password',
        ]);

        $this->assertGuest();
    }
}

it is untouched. Out of the box. Should I edit something?

lat4732's avatar
Level 12

I really need help. I am grateful for any guidance.

migsAV's avatar

@laralex the tests may have been untouched but have you changed any database structure or added logic for when a user logins or registers?

lat4732's avatar
Level 12

@migsAV Yeah, I've changed some simple logic like where to redirect after login based on user type. Also added some additional columns to the users table.

rodrigo.pedra's avatar

@Laralex

The redirect change already explains the AuthenticationTest failure.

On the test case that is failing test_users_can_authenticate_using_the_login_screen, the last assertion checks if the response redirects the user to the path defined in RouteServiceProvider::HOME.

If you changed where the controller redirects after logging an user in, this assertion will fail until you fix it.

There are the kind of changes I referred to on my first answer. If you change the code being testes, most likely some tests will start failing.

migsAV's avatar

Also, try adding $this->withoutExceptionHandling(); and see if it can give you a more clear error

public function test_users_can_authenticate_using_the_login_screen()
    {
$this->withoutExceptionHandling();
        $user = User::factory()->create();

        $response = $this->post('/login', [
            'email' => $user->email,
            'password' => 'password',
        ]);

        $this->assertAuthenticated();
        $response->assertRedirect(RouteServiceProvider::HOME);
}
lat4732's avatar
Level 12

@migsAV I'm getting

  • Tests\Feature\AuthenticationTest > users can authenticate using the login screen
   Illuminate\Validation\ValidationException

  The given data was invalid.
lat4732's avatar
Level 12

That's how my user factory looks

<?php

namespace Database\Factories;

use App\Models\Team;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use Laravel\Jetstream\Features;

class UserFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = User::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        $arr = config('app.colors');
        $rand = array_rand($arr);
        return [
            'name' => $this->faker->name(),
            'email' => $this->faker->unique()->safeEmail(),
            'email_verified_at' => now(),
            'password' => 'yIXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
            'remember_token' => Str::random(10),
            'bgColor' => $arr[$rand]['background'],
            'textColor' => $arr[$rand]['text'],
        ];
    }

    /**
     * Indicate that the model's email address should be unverified.
     *
     * @return \Illuminate\Database\Eloquent\Factories\Factory
     */
    public function unverified()
    {
        return $this->state(function (array $attributes) {
            return [
                'email_verified_at' => null,
            ];
        });
    }

    /**
     * Indicate that the user should have a personal team.
     *
     * @return $this
     */
    public function withPersonalTeam()
    {
        if (! Features::hasTeamFeatures()) {
            return $this->state([]);
        }

        return $this->has(
            Team::factory()
                ->state(function (array $attributes, User $user) {
                    return ['name' => $user->name.'\'s Team', 'user_id' => $user->id, 'personal_team' => true];
                }),
            'ownedTeams'
        );
    }
}
migsAV's avatar

@Laralex try this and see it the authentication test passes

public function definition()
    {
       // $arr = config('app.colors');
       // $rand = array_rand($arr);
        return [
            'name' => $this->faker->name(),
            'email' => $this->faker->unique()->safeEmail(),
            'email_verified_at' => now(),
            'password' => 'yIXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
            'remember_token' => Str::random(10),
         //   'bgColor' => $arr[$rand]['background'],
          //  'textColor' => $arr[$rand]['text'],
        ];
    }
migsAV's avatar

@laralex then you need to retrace your steps because you have changed something that is affecting your tests.

You mentioned you changed the redirect, this will affect your tests

@migsAV Yeah, I've changed some simple logic like where to redirect after login based on user type. Also added some additional columns to the users table.

You got to remember that a slight change in how the login works will sometimes cause failed tests

Please or to participate in this conversation.