Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LARAVEL UNIT TEST - Opposite of seeInDatabase

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

Is there a way to assert if the some data arent in database? Something like dontSeeInDatabase... Similiar to dontSeeJson

like image 963
giordanolima Avatar asked Sep 02 '15 13:09

giordanolima


2 Answers

Laravel v5.6

Assertion name has changed

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

the opposite would be

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

Previous Laravel versions

There are two ways:

->notSeeInDatabase($table, array $data)  

and

->missingFromDatabase($table, array $data)

One is just an alias for the other.

For a full list of available testing methods take a look at the traits located at vendor/laravel/framework/src/Illuminate/Foundation/Testing

like image 108
Javi Stolz Avatar answered Oct 08 '22 12:10

Javi Stolz


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

->assertDatabaseHas($table, array $data)

->assertDatabaseMissing($table, array $data)

So, if you're using recent versions of Laravel as of now and doing testing, you should try assertDatabaseMissing().

like image 30
Arda Avatar answered Oct 08 '22 13:10

Arda