Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ protected function assertDatabaseHas($table, array $data = [], $connection = nul
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

foreach ($data as $row) {
$this->assertDatabaseHas($table, $row, $connection);
}

return $this;
}

if ($table instanceof Model) {
$data = [
$table->getKeyName() => $table->getKey(),
Expand Down Expand Up @@ -65,6 +73,14 @@ protected function assertDatabaseMissing($table, array $data = [], $connection =
return $this;
}

if (array_is_list($data) && array_all($data, fn ($row) => is_array($row))) {
foreach ($data as $row) {
$this->assertDatabaseMissing($table, $row, $connection);
}

return $this;
}

if ($table instanceof Model) {
$data = [
$table->getKeyName() => $table->getKey(),
Expand Down
30 changes: 30 additions & 0 deletions tests/Foundation/FoundationInteractsWithDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ public function testAssertDatabaseHasConstrainsToModel()
$this->assertDatabaseHas(new ProductStub(['id' => 1]), $data);
}

public function testAssertDatabaseSupportsArrays()
{
$builder = m::mock(Builder::class);
$builder->shouldReceive('where')->with(['title' => 'Spark', 'name' => 'Laravel'])->once()->andReturnSelf();
$builder->shouldReceive('where')->with(['title' => 'Forge', 'name' => 'Laravel'])->once()->andReturnSelf();
$builder->shouldReceive('exists')->twice()->andReturn(true);

$this->connection->shouldReceive('table')->with($this->table)->andReturn($builder);

$this->assertDatabaseHas($this->table, [
['title' => 'Spark', 'name' => 'Laravel'],
['title' => 'Forge', 'name' => 'Laravel'],
]);
}

public function testSeeInDatabaseDoesNotFindResults()
{
$this->expectException(ExpectationFailedException::class);
Expand Down Expand Up @@ -103,6 +118,21 @@ public function testSeeInDatabaseFindsManyNotMatchingResults()
$this->assertDatabaseHas($this->table, $this->data);
}

public function testAssertDatabaseMissingSupportsArrays()
{
$builder = m::mock(Builder::class);
$builder->shouldReceive('where')->with(['title' => 'Spark', 'name' => 'Laravel'])->once()->andReturnSelf();
$builder->shouldReceive('where')->with(['title' => 'Forge', 'name' => 'Laravel'])->once()->andReturnSelf();
$builder->shouldReceive('exists')->twice()->andReturn(false);

$this->connection->shouldReceive('table')->with($this->table)->andReturn($builder);

$this->assertDatabaseMissing($this->table, [
['title' => 'Spark', 'name' => 'Laravel'],
['title' => 'Forge', 'name' => 'Laravel'],
]);
}

public function testDontSeeInDatabaseDoesNotFindResults()
{
$this->mockCountBuilder(false);
Expand Down
Loading