Summer Sale! All accounts are 50% off this week.

sebasspf's avatar

Testing if a record is not in the database

Hi to All, im trying to test in my app if i deleted a database record correctly. The problem is, in the documentation i only see a "assertDatabaseHas" method, but not the oposite, like the old "notSeeInDatabase".

Is a way to use a oposite of "assertDatabaseHas"? Thanks to all.

0 likes
3 replies
tykus's avatar

You have this new method in the InteractsWithDatabase trait which is opposite of the assertDatabaseHas method:

assertDatabaseMissing($table, array $data, $connection = null)
2 likes
eugenefvdm's avatar

@tykus Thanks for sending me in the right direction. In my case this was better:

$this->assertDatabaseCount('jobs', 0);
jlrdw's avatar

Or the old way, this is just quick test

    public function addTest()
    {
        $username = 'timmmzzz';
        $password = 'rob12458mzzzz999';
        $users = Admin::where('username', '=', $username)->first();
        if (!empty($users)) {
            echo $users->username;
        } else {
            echo "Not there";
        }
    }

Please or to participate in this conversation.