justsimpleuser
justsimpleuser

Reputation: 169

Saving data to database in unit testing

Why it's impossible to create dummy data in unit testing like below?

DB::table('users')->insert([
[
'name' => 'test',
],

I saw that in order to create data you need to create factory, but when I try to insert data like this:

User::factory()->count(1)->create([
'name' => 'test'
]);

It also don't insert new data. What is the easiest way to to that? Thank you

Upvotes: 0

Views: 624

Answers (1)

dz0nika
dz0nika

Reputation: 1031

No need for a factory, and you dont need to use DB if you a User model setup. Laravel is great for these types of things and I recommend reading the docs here

For you problem its as simple as this

User::create(['name' => 'test']);

Upvotes: 2

Related Questions