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

[7.x] Add assertDatabaseCount assertion #32597

Merged
merged 3 commits into from
Apr 29, 2020
Merged

[7.x] Add assertDatabaseCount assertion #32597

merged 3 commits into from
Apr 29, 2020

Conversation

christophrumpel
Copy link
Contributor

This PR adds a new database assertion called assertDatabaseCount($count).

Next to the given assertDatabaseHas or assertDatabaseMissing assertions, it is often useful to just check the number of entries in a database table. This is possible in different workarounds already, but it would be more convenient to provide a simple helper through Laravel as well.

Here is an example of how to use it inside a test:

MyCustomUserFactory::new()
    ->times(50)
    ->create();

$this->assertDatabaseCount('users', 50);

And this is how a failure message would look like:

Failed asserting that table [products] matches expected entries count of 3. Entries found: 1.

@christophrumpel christophrumpel changed the title Add assertDatabaseCount assertion [7.x] Add assertDatabaseCount assertion Apr 29, 2020
@taylorotwell taylorotwell merged commit d922f2d into laravel:7.x Apr 29, 2020
@taylorotwell
Copy link
Member

Thanks

@christophrumpel
Copy link
Contributor Author

👍Do you want it to be added to the docs as well? https://laravel.com/docs/master/database-testing

@veneliniliev
Copy link
Contributor

this is good feature but can you add array $data for additional wheres for count like other assertDatabase* methods?

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.

3 participants