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] Add assertDatabaseEmpty helper #44810

Merged
merged 2 commits into from
Nov 2, 2022
Merged

[9.x] Add assertDatabaseEmpty helper #44810

merged 2 commits into from
Nov 2, 2022

Conversation

christophrumpel
Copy link
Contributor

This PR adds a new testing helper assertDatabaseEmpty which checks if a specific table has no entires.

Why do we need it?

When testing against the database you often also need to check if a table is empty before or after a specific action:

    // Assert
    $this->assertDatabaseCount(MyModel::class, 0);

    // Act
    // Call a specific action or request

    // Assert
    $this->assertDatabaseCount(MyModel::class, 1);

This new testing helper is a bit shorter to write, descriptive, and better to read:

    // Assert
    $this->assertDatabaseEmpty(MyModel::class);

    // Act
    // Call a specific action or request

    // Assert
    $this->assertDatabaseCount(MyModel::class, 1);

@taylorotwell taylorotwell merged commit 0fa97f6 into laravel:9.x Nov 2, 2022
@christophrumpel christophrumpel deleted the feature/add-assertDatabaseEmpty-testing-helper branch November 2, 2022 14:30
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