Summer Sale! All accounts are 50% off this week.

Mick79's avatar

Bit of a cowboy... not done much testing

BUT... I am devoting serious time to it now.

I got some tests going but whenever I ran PHPunit I was getting various errors about factories and directories not existing etc (I have been upgrading this project manually since L5, not on L9). I've sorted all that though.

Anyway now I am getting no errors at all, just this:

PHPUnit 9.5.26 by Sebastian Bergmann and contributors.

..

Thats it... it just stalls on those 2 dots in perpetuity. Any ideas how to debug?

0 likes
5 replies
tykus's avatar

Try running with the —testdox option to find the test name that hangs. Then debug that test/implementation

1 like
Mick79's avatar

@tykus Thanks.

I ran with --debug and saw that it was failing on test_user_can_login_with_correct_credentials

So I set about to debug that by adding debug logs and this is the outcome

Test:

public function test_user_can_login_with_correct_credentials()
    {
        $user = User::factory()->create([
            \Log::debug("first"),
            'password' => bcrypt($password = 'i-love-laravel'),
            \Log::debug("first part 2"),
        ]);

        \Log::debug("second");
        $response = $this->post('/login', [
            'email' => $user->email,
            'password' => $password,
        ]);

        \Log::debug("third");
        $response->assertRedirect('/dashboard');
        $this->assertAuthenticatedAs($user);
    }

Logs I'm getting:

[2022-11-17 13:49:45] testing.DEBUG: first  
[2022-11-17 13:49:45] testing.DEBUG: first part 2  

So it's not making it OUT of that first function. I'm stuck.

Mick79's avatar

@tykus

Ok..... I added a log to my UserFactory and can see that it's stuck in an infinite loop. Here is what that looks like.

No idea why this is looping

<?php

declare(strict_types=1);

namespace Database\Factories;

use App\User;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<\App\User>
 */
final 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(): array
    {
        return [
            'fname' => $this->faker->word,
            'sname' => $this->faker->word,
            'email' => $this->faker->safeEmail,
            'password' => bcrypt($this->faker->password),
            'bio' => $this->faker->text,
            'picsource' => $this->faker->word,
            'country' => $this->faker->country,
            'isAdmin' => $this->faker->boolean,
            'status' => $this->faker->randomNumber(),
            'trialExpiry' => $this->faker->dateTime(),
            'env' => $this->faker->word,
            'accountVerificationToken' => $this->faker->word,
            'accountConfirmed' => $this->faker->randomNumber(),
            'remember_token' => Str::random(10),
            'stripe_id' => $this->faker->word,
            'card_brand' => $this->faker->word,
            'card_last_four' => $this->faker->word,
            'trial_ends_at' => $this->faker->dateTime(),
            'phoneNumber' => $this->faker->word,
            'pin' => $this->faker->word,
            'smsVerified' => $this->faker->randomNumber(),
            'currency' => $this->faker->currencyCode,
            'udid' => $this->faker->word,
            'ARN' => $this->faker->word,
            'username' => $this->faker->userName,
            'publicSongboxId' => $this->faker->randomNumber(),
            'url' => $this->faker->url,
            'membertype' => $this->faker->word,
            'sms_active' => $this->faker->randomNumber(),
            'traffic_source' => $this->faker->word,
            'artist_name' => $this->faker->word,
            'name' => $this->faker->name,
            'submissions' => $this->faker->randomNumber(),
            'timezone' => $this->faker->word,
            'referral_code' => $this->faker->word,
            'referee_code' => \App\User::factory(),
            'on_trial' => $this->faker->randomNumber(),
            'web_link' => $this->faker->word,
            'twitter' => $this->faker->word,
            'instagram' => $this->faker->word,
            'facebook' => $this->faker->word,
            'contact_email' => $this->faker->word,
        ];
    }
}

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Mick79 You get an eternal loop.

'referee_code' => \App\User::factory(),

This creates a new user.. Which creates a new user... etc.

1 like

Please or to participate in this conversation.