Any attempt to use Model::factory()->create() where $this->faker is used in the definition() method will result in Faker complaining of an unknown formatter. It appears that by default there are no providers loaded.
Write a test in a fresh Laravel 8 installation that uses the User factory that ships with it and run it.
public function testBasicTest()
{
User::factory()->create();
}
Results in
Unknown formatter "name"
at vendor/fzaninotto/faker/src/Faker/Generator.php:248
You are attempting to do this in a unit test class. Unit test classes do not boot the framework at all. Use the tests in the Feature test directory.
@taylorotwell @JeffreyWay
this is the source of confussion:
What's new in laravel 8, episode 8
Jeffrey creates a unit test in tests/Unit but use Test/TestCase instead of the PHPUnit\Framework\TestCase used when
php artisan make:test --unit
If you want your unit tests to boot the framework, yes you need to extend Tests\TestCase. 馃憤
Most helpful comment
If you want your unit tests to boot the framework, yes you need to extend
Tests\TestCase. 馃憤