0

I'm using Lumen default Tests only added this line to the test :

$users = \App\Models\User::factory()->count(5)->create();

But i get this error when running the test :

InvalidArgumentException: Unknown format "name"

I did't touch the UserFactory Class i include it below , whats wrong with my code?

public function definition()
    {
        return [
            'name' => $this->faker->name,
            'email' => $this->faker->unique()->safeEmail,
        ];
    }
John
  • 578
  • 1
  • 3
  • 15

4 Answers4

2

Should anybody else end up here looking for a similar issue in Laravel, make sure you include

parent::setUp();

in your setup method (if you have one). For example,

class ManageDocumentTest extends TestCase
{
    public $user;

    public function setUp():void
    {
        parent::setUp();

        $this->user = User::factory()->create();
...
1

Uncommented these lines in app.php and its working now :

$app->withFacades();

 $app->withEloquent();
John
  • 578
  • 1
  • 3
  • 15
1

You have to extend use Tests\TestCase instead of PHPUnit\Framework\TestCase.

At least, it helped me.

1

If you are using Tests\TestCase, calling parent::setUp(); and it still doesn't work, make sure not to call $faker before the actual test - ie. in a @dataProvider it won't work

WellBloud
  • 927
  • 4
  • 13
  • 29