I would like to use Model factories, but I get this error:
1) Tests\Factory\UserFactoryTest::testUserCount
Error: Call to undefined method App\Entities\User::newCollection()
C:\Projects\factory_test\vendor\laravel\framework\src\Illuminate\Database\Eloquent\FactoryBuilder.php:228
C:\Projects\factory_test\vendor\laravel\framework\src\Illuminate\Database\Eloquent\FactoryBuilder.php:178
C:\Projects\factory_test\tests\Factory\UserFactoryTest.php:21
The factory code was copied from the Laravel-Doctrine example project :
$factory->define(App\Entities\User::class, function (Faker\Generator $faker) {
return [
'name' => $faker->title,
];
});
What do I wrong? Do I need additional configurations, before using factories? Doctrine works perfectly, I only have issue with factory()
The test class looks like this:
class UserFactoryTest extends TestCase {
private $users = array();
protected function setUp(): void
{
parent::setUp();
$this->users = factory(User::class, 3)->create();
}
// ...
}