DEF STUDIO srl

Need help with Laravel and web development?

Hire one of our experts for your projects.

We build tailored products, websites and platforms — with care for UX, performance and maintainability.

Booking open for Q4 — limited slots

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,
);
Suggest a change
Last updated 22 August 2025