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

[8.x] Add model support for database assertions #37459

Merged
merged 1 commit into from
May 24, 2021
Merged

[8.x] Add model support for database assertions #37459

merged 1 commit into from
May 24, 2021

Conversation

nuernbergerA
Copy link
Contributor

Hey Guys!

A good thing when working with Eloquent, you never ever have to care about the table name.
But when it comes to testing there are some nice assertions assertDatabase*()

Currently, I have to "hardcode" the table name in my tests (which makes it hard to rename a model and its table name later) $this->assertDatabaseCount('users', 5);

Wouldnt it be great to just pass the model?
This PR adds exactly this!

$this->assertDatabaseCount('users', 5);
$this->assertDatabaseCount(Users::class, 5);
$this->assertDatabaseCount(new User, 5);

I know we could also resolve the connection from the model but this could be done in a follow-up PR.

Cheers Adrian

@Wulfheart
Copy link

This would be really helpful.

@bhushan
Copy link

bhushan commented May 23, 2021

Yes for sure, imagine in the model i have used custom table name, i dont have to remember it if it fetches automatically in the test based on class

@Wulfheart
Copy link

Does this also support things like assertDatabaseHas and assertDatabaseMissing?

@bhushan
Copy link

bhushan commented May 23, 2021

Yes @Wulfheart .. check PR ..

@taylorotwell taylorotwell merged commit bed4033 into laravel:8.x May 24, 2021
@nuernbergerA nuernbergerA deleted the model-support-for-database-assertions branch May 24, 2021 13:42
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.

4 participants