LARAVEL UNIT TEST - Opposite of seeInDatabase

本小妞迷上赌 提交于 2019-12-22 05:26:09

问题


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


回答1:


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




回答2:


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().



来源:https://stackoverflow.com/questions/32355020/laravel-unit-test-opposite-of-seeindatabase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!