Skip to content

[9.x] Add assertDatabaseEmpty helper - #44810

Merged
taylorotwell merged 2 commits into
laravel:9.xfrom
christophrumpel:feature/add-assertDatabaseEmpty-testing-helper
Nov 2, 2022
Merged

taylorotwell merged 2 commits into
laravel:9.xfrom
christophrumpel:feature/add-assertDatabaseEmpty-testing-helper

Conversation

@christophrumpel

Copy link
Copy Markdown
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