Database Expectations
toBeInDatabase()
Assert that the given where condition exists in the database.
expect(['name' => 'Fabio'])->toBeInDatabase(table: 'users');
toMatchQuery()
Assert that sql query/bindings match with the one generated by the ones generated by the given query builder
$query = User::query()->where('name' => 'Luke')->where('email' => '[email protected]'); expect($query)->toMatchQuery( 'select * from "users" where "name" = ? and "email" = ?', //sql query ['Luke', '[email protected]'], //bindings );
if needed, a third param allows to do a partial match
$query = User::query() ->where('name' => 'Luke') ->where('email' => '[email protected]') ->where('role' => 'developer'); expect($query)->toMatchQuery( 'and "email" = ?', ['[email protected]'], false, );