Skip to content

[13.x] Allow assertDatabase has & missing to accept arrays#59752

Open
jackbayliss wants to merge 6 commits intolaravel:13.xfrom
jackbayliss:assertDatabase-with-arrays
Open

[13.x] Allow assertDatabase has & missing to accept arrays#59752
jackbayliss wants to merge 6 commits intolaravel:13.xfrom
jackbayliss:assertDatabase-with-arrays

Conversation

@jackbayliss
Copy link
Copy Markdown
Contributor

@jackbayliss jackbayliss commented Apr 17, 2026

Happy Friday,

Going through tests atm, so sat here thinking of nice things I can give back to Laravel.

We have loads of assertDatabaseHas / assertDatabaseMissing tests in a row such as:

 $this->assertDatabaseHas(User::class, ['name' => 'Jack', 'email' => 'jack@example.com']);                                                                                                                   
 $this->assertDatabaseHas(User::class, ['name' => 'Taylor', 'email' => 'taylor@laravel.com']);
 
 $this->assertDatabaseMissing(User::class, ['name' => 'Dr Dre', 'email' => 'dre@laravel.com']);
 $this->assertDatabaseMissing(User::class, ['name' => 'Gucci Mane', 'email' => 'gman@laravel.com']);                                                                                                   

But, it would be nice for it to allow:

  $this->assertDatabaseHas(User::class, [                                                                                                                                                                     
      ['name' => 'Jack', 'email' => 'jack@example.com'],    
      ['name' => 'Taylor', 'email' => 'taylor@example.com'],                                                                                                                                           
  ]);       
  
  $this->assertDatabaseMissing(User::class, [                                                                                                                                                                     
    ['name' => 'Dr Dre', 'email' => 'dre@laravel.com'],    
    ['name' => 'Gucci Mane', 'email' => 'gman@laravel.com'],                                                                                                                                           
]);                                                                                                                                                                                                                   

This just calls the method internally, so no big brain functions as not bothered about performance atm, more dx.

I couldn't reuse mockCountBuilder due to the data, so just did normal mocking.

I don't think this is a b/c as currently you cant pass an araray of arrays..

@github-actions
Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@jackbayliss jackbayliss marked this pull request as ready for review April 17, 2026 15:00
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.

1 participant