From 7b031935a1f071ac3874cd21246fe4804cf6127c Mon Sep 17 00:00:00 2001 From: Jack Bayliss Date: Fri, 17 Apr 2026 15:18:56 +0100 Subject: [PATCH 1/6] apply logic --- .../Testing/Concerns/InteractsWithDatabase.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php index 73d5f9771b5b..175b11cf81ce 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php @@ -33,6 +33,14 @@ protected function assertDatabaseHas($table, array $data = [], $connection = nul return $this; } + if (array_is_list($data) && count($data) > 0 && array_all($data, fn ($row) => is_array($row))) { + foreach ($data as $row) { + $this->assertDatabaseHas($table, $row, $connection); + } + + return $this; + } + if ($table instanceof Model) { $data = [ $table->getKeyName() => $table->getKey(), @@ -65,6 +73,14 @@ protected function assertDatabaseMissing($table, array $data = [], $connection = return $this; } + if (array_is_list($data) && count($data) > 0 && 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(), From 8f7f22751261bcdfdb2a98a848ea791048d2d0ca Mon Sep 17 00:00:00 2001 From: Jack Bayliss Date: Fri, 17 Apr 2026 15:19:11 +0100 Subject: [PATCH 2/6] tests --- .../FoundationInteractsWithDatabaseTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Foundation/FoundationInteractsWithDatabaseTest.php b/tests/Foundation/FoundationInteractsWithDatabaseTest.php index 9253952fda0c..41acba17810f 100644 --- a/tests/Foundation/FoundationInteractsWithDatabaseTest.php +++ b/tests/Foundation/FoundationInteractsWithDatabaseTest.php @@ -61,6 +61,21 @@ public function testAssertDatabaseHasConstrainsToModel() $this->assertDatabaseHas(new ProductStub(['id' => 1]), $data); } + public function testAssertDatabaseHasWithArrays() + { + $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); @@ -103,6 +118,21 @@ public function testSeeInDatabaseFindsManyNotMatchingResults() $this->assertDatabaseHas($this->table, $this->data); } + public function testAssertDatabaseMissingWithArrays() + { + $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); From 67e363dee33597463748fabf66a9637b035b8ffb Mon Sep 17 00:00:00 2001 From: Jack Bayliss Date: Fri, 17 Apr 2026 15:22:53 +0100 Subject: [PATCH 3/6] use brain --- .../FoundationInteractsWithDatabaseTest.php | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/tests/Foundation/FoundationInteractsWithDatabaseTest.php b/tests/Foundation/FoundationInteractsWithDatabaseTest.php index 41acba17810f..7bbf9c649561 100644 --- a/tests/Foundation/FoundationInteractsWithDatabaseTest.php +++ b/tests/Foundation/FoundationInteractsWithDatabaseTest.php @@ -63,17 +63,9 @@ public function testAssertDatabaseHasConstrainsToModel() public function testAssertDatabaseHasWithArrays() { - $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->mockCountBuilder(true); - $this->assertDatabaseHas($this->table, [ - ['title' => 'Spark', 'name' => 'Laravel'], - ['title' => 'Forge', 'name' => 'Laravel'], - ]); + $this->assertDatabaseHas($this->table, [$this->data, $this->data]); } public function testSeeInDatabaseDoesNotFindResults() @@ -120,17 +112,9 @@ public function testSeeInDatabaseFindsManyNotMatchingResults() public function testAssertDatabaseMissingWithArrays() { - $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->mockCountBuilder(false); - $this->assertDatabaseMissing($this->table, [ - ['title' => 'Spark', 'name' => 'Laravel'], - ['title' => 'Forge', 'name' => 'Laravel'], - ]); + $this->assertDatabaseMissing($this->table, [$this->data, $this->data]); } public function testDontSeeInDatabaseDoesNotFindResults() From 851015471e72a812b5dfe0a020fc10b9d6318c51 Mon Sep 17 00:00:00 2001 From: Jack Bayliss Date: Fri, 17 Apr 2026 15:31:15 +0100 Subject: [PATCH 4/6] be explicit fam --- .../FoundationInteractsWithDatabaseTest.php | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/Foundation/FoundationInteractsWithDatabaseTest.php b/tests/Foundation/FoundationInteractsWithDatabaseTest.php index 7bbf9c649561..41acba17810f 100644 --- a/tests/Foundation/FoundationInteractsWithDatabaseTest.php +++ b/tests/Foundation/FoundationInteractsWithDatabaseTest.php @@ -63,9 +63,17 @@ public function testAssertDatabaseHasConstrainsToModel() public function testAssertDatabaseHasWithArrays() { - $this->mockCountBuilder(true); + $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, [$this->data, $this->data]); + $this->assertDatabaseHas($this->table, [ + ['title' => 'Spark', 'name' => 'Laravel'], + ['title' => 'Forge', 'name' => 'Laravel'], + ]); } public function testSeeInDatabaseDoesNotFindResults() @@ -112,9 +120,17 @@ public function testSeeInDatabaseFindsManyNotMatchingResults() public function testAssertDatabaseMissingWithArrays() { - $this->mockCountBuilder(false); + $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, [$this->data, $this->data]); + $this->assertDatabaseMissing($this->table, [ + ['title' => 'Spark', 'name' => 'Laravel'], + ['title' => 'Forge', 'name' => 'Laravel'], + ]); } public function testDontSeeInDatabaseDoesNotFindResults() From d5be03124500ba5c38a08358ae9ce4b85c32f6f8 Mon Sep 17 00:00:00 2001 From: Jack Bayliss Date: Fri, 17 Apr 2026 15:40:02 +0100 Subject: [PATCH 5/6] drop count --- .../Foundation/Testing/Concerns/InteractsWithDatabase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php index 175b11cf81ce..115589b17936 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php @@ -33,7 +33,7 @@ protected function assertDatabaseHas($table, array $data = [], $connection = nul return $this; } - if (array_is_list($data) && count($data) > 0 && array_all($data, fn ($row) => is_array($row))) { + if (array_is_list($data) && array_all($data, fn ($row) => is_array($row))) { foreach ($data as $row) { $this->assertDatabaseHas($table, $row, $connection); } @@ -73,7 +73,7 @@ protected function assertDatabaseMissing($table, array $data = [], $connection = return $this; } - if (array_is_list($data) && count($data) > 0 && array_all($data, fn ($row) => is_array($row))) { + if (array_is_list($data) && array_all($data, fn ($row) => is_array($row))) { foreach ($data as $row) { $this->assertDatabaseMissing($table, $row, $connection); } From 0e1f863cc02567114218bd94cd8f536fa6c49f5f Mon Sep 17 00:00:00 2001 From: Jack Bayliss Date: Fri, 17 Apr 2026 15:44:02 +0100 Subject: [PATCH 6/6] suPp0rtsssss --- tests/Foundation/FoundationInteractsWithDatabaseTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Foundation/FoundationInteractsWithDatabaseTest.php b/tests/Foundation/FoundationInteractsWithDatabaseTest.php index 41acba17810f..6311839184c8 100644 --- a/tests/Foundation/FoundationInteractsWithDatabaseTest.php +++ b/tests/Foundation/FoundationInteractsWithDatabaseTest.php @@ -61,7 +61,7 @@ public function testAssertDatabaseHasConstrainsToModel() $this->assertDatabaseHas(new ProductStub(['id' => 1]), $data); } - public function testAssertDatabaseHasWithArrays() + public function testAssertDatabaseSupportsArrays() { $builder = m::mock(Builder::class); $builder->shouldReceive('where')->with(['title' => 'Spark', 'name' => 'Laravel'])->once()->andReturnSelf(); @@ -118,7 +118,7 @@ public function testSeeInDatabaseFindsManyNotMatchingResults() $this->assertDatabaseHas($this->table, $this->data); } - public function testAssertDatabaseMissingWithArrays() + public function testAssertDatabaseMissingSupportsArrays() { $builder = m::mock(Builder::class); $builder->shouldReceive('where')->with(['title' => 'Spark', 'name' => 'Laravel'])->once()->andReturnSelf();