Skip to content

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

Merged
taylorotwell merged 6 commits intolaravel:13.xfrom
jackbayliss:assertDatabase-with-arrays
Apr 18, 2026
Merged

[13.x] Allow assertDatabase has & missing to accept arrays#59752
taylorotwell merged 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
@taylorotwell taylorotwell merged commit f15ba6d into laravel:13.x Apr 18, 2026
54 checks passed
return $this;
}

if (array_is_list($data) && array_all($data, fn ($row) => is_array($row))) {
Copy link
Copy Markdown
Contributor

@ghabriel25 ghabriel25 Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_all was introduced in php 8.4 while Laravel 13 minimum requirement is php 8.3. Correct me if I'm wrong about this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's poly filled and used in the framework already😉

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the information 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No probs man! Thanks for asking

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