Skip to content

[9.x] Adds database query count test expectation helper - #45932

Merged
taylorotwell merged 2 commits into
laravel:9.xfrom
timacdonald:expect-query-count
Feb 3, 2023
Merged

[9.x] Adds database query count test expectation helper#45932
taylorotwell merged 2 commits into
laravel:9.xfrom
timacdonald:expect-query-count

Conversation

@timacdonald

Copy link
Copy Markdown
Member

New testing helper. Useful when you want to ensure the code doesn't inadvertantly introduce new database queries.

public function testItWorksEfficiently()
{
    $this->expectsDatabaseQueryCount(5);

    // do stuff...

    // throws an exception on tearDown if more than 5 queries have run
    // since the expectation was created.
}

@taylorotwell
taylorotwell merged commit dc4bbd3 into laravel:9.x Feb 3, 2023
@timacdonald
timacdonald deleted the expect-query-count branch February 6, 2023 22:14
taylorotwell added a commit that referenced this pull request Feb 23, 2023
* Fix expectsDatabaseQueryCount() $connection parameter

The listen() function was assuming that the event was being dispatched for just that connection, rather than globally.

Instead, we now check the connection name matches if it was provided.

Fixes #45932

* fixes

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants