Support the ongoing development of Laravel.io →
posted 6 years ago
Last updated 2 years ago.
0
moderator

Doe the FaqCategory has the SoftDeletes trait? Then it exist in the database but with the deleted_at filled.

You can fix the assert with adding that field:

$this->assertDatabaseMissing('faq_categories', ['id' => 1, 'deleted_at' => null]);
0

It does not. I know about softDeletes. I think that there is some kind of cacheing, and assertDatabaseMissing actually do not check database, but it gets a data from cache, but it is tight theory.

0
moderator

I now just see that you don't use the id in the assert. And you can for debugging dump what is inside the table.

// with the model
dump(\App\Models\FaqCategory::all());
// or with all the data
dump(DB::table('faq_categories')->get());
$this->assertDatabaseMissing('faq_categories', ['id' => $fc->id, 'deleted_at' => null]);

That is the way I sometimes debug why I didn't get what I want (and most of the time it was a simple mistake from my side)

Last updated 6 years ago.
0

Yeah, i tried lots of things, i put there 1 becouse i was out of ideas. Of course i started from code with $fc->id in assertion, still the same issue. I am using RefreshDatabase trait so "1" is no problem here.

EDIT: I figured it out. I am using model binding in my controllers, so i can not just put $this->withoutMiddleware() in test, becouse route model binding will not work (something needs to be done in middlewares). In addition looks like laravel caches config, so before test i have to run artisan cach:clear. VerifyCsrf middleware is disabled in test env.

Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.