Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Feb 3, 2023

Conversation

timacdonald
Copy link
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 <[email protected]>
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