LARAVEL UNIT TEST - opposite seeInDatabase

In Laravel 5.1, there is a method that is active if some data is in the database using seeInDatabase ($ table, $ fields) ...

Is there any way to assert if some data arent in the database? Something like dontSeeInDatabase ... Compatible with dontSeeJson

+5
source share
2 answers

Laravel v5.6

Confirmation Name Changed

->assertDatabaseMissing(string $table, array $data, string $connection = null) 

the opposite would be

 ->assertDatabaseHas(string $table, array $data, string $connection = null) 

Previous versions of Laravel

There are two ways:

 ->notSeeInDatabase($table, array $data) 

and

 ->missingFromDatabase($table, array $data) 

One is just an alias for the other.

For a complete list of available testing methods, check out the features located at vendor/laravel/framework/src/Illuminate/Foundation/Testing

+13
source

In recent versions of Laravel (5.4 at the moment), the seeInDatabase and missingFromDatabase not available. Instead, there are the assertDatabaseHas and assertDatabaseMissing . Usage is the same:

->assertDatabaseHas($table, array $data)

->assertDatabaseMissing($table, array $data)

So, if you are using the latest versions of Laravel at the moment and are testing, you should try assertDatabaseMissing() .

+6
source

All Articles