diff --git a/src/Illuminate/Foundation/Testing/Constraints/HasInDatabase.php b/src/Illuminate/Foundation/Testing/Constraints/HasInDatabase.php index b88f34222872..35bf40be721b 100644 --- a/src/Illuminate/Foundation/Testing/Constraints/HasInDatabase.php +++ b/src/Illuminate/Foundation/Testing/Constraints/HasInDatabase.php @@ -75,16 +75,18 @@ public function failureDescription($table): string */ protected function getAdditionalInfo($table) { - $results = $this->database->table($table)->get(); + $query = $this->database->table($table); + + $results = $query->limit($this->show)->get(); if ($results->isEmpty()) { return 'The table is empty'; } - $description = 'Found: '.json_encode($results->take($this->show), JSON_PRETTY_PRINT); + $description = 'Found: '.json_encode($results, JSON_PRETTY_PRINT); - if ($results->count() > $this->show) { - $description .= sprintf(' and %s others', $results->count() - $this->show); + if ($query->count() > $this->show) { + $description .= sprintf(' and %s others', $query->count() - $this->show); } return $description; diff --git a/src/Illuminate/Foundation/Testing/Constraints/SoftDeletedInDatabase.php b/src/Illuminate/Foundation/Testing/Constraints/SoftDeletedInDatabase.php index 2e0d738b279c..f99b9311fb9d 100644 --- a/src/Illuminate/Foundation/Testing/Constraints/SoftDeletedInDatabase.php +++ b/src/Illuminate/Foundation/Testing/Constraints/SoftDeletedInDatabase.php @@ -88,16 +88,18 @@ public function failureDescription($table): string */ protected function getAdditionalInfo($table) { - $results = $this->database->table($table)->get(); + $query = $this->database->table($table); + + $results = $query->limit($this->show)->get(); if ($results->isEmpty()) { return 'The table is empty'; } - $description = 'Found: '.json_encode($results->take($this->show), JSON_PRETTY_PRINT); + $description = 'Found: '.json_encode($results, JSON_PRETTY_PRINT); - if ($results->count() > $this->show) { - $description .= sprintf(' and %s others', $results->count() - $this->show); + if ($query->count() > $this->show) { + $description .= sprintf(' and %s others', $query->count() - $this->show); } return $description; diff --git a/tests/Foundation/FoundationInteractsWithDatabaseTest.php b/tests/Foundation/FoundationInteractsWithDatabaseTest.php index 0947bdc665d0..5a3d7c7c0191 100644 --- a/tests/Foundation/FoundationInteractsWithDatabaseTest.php +++ b/tests/Foundation/FoundationInteractsWithDatabaseTest.php @@ -71,10 +71,11 @@ public function testSeeInDatabaseFindsManyNotMatchingResults() $this->expectExceptionMessage('Found: '.json_encode(['data', 'data', 'data'], JSON_PRETTY_PRINT).' and 2 others.'); $builder = $this->mockCountBuilder(0); + $builder->shouldReceive('count')->andReturn(0, 5); $builder->shouldReceive('take')->andReturnSelf(); $builder->shouldReceive('get')->andReturn( - collect(array_fill(0, 5, 'data')) + collect(array_fill(0, 3, 'data')) ); $this->assertDatabaseHas($this->table, $this->data); @@ -150,11 +151,13 @@ protected function mockCountBuilder($countResult, $deletedAtColumn = 'deleted_at { $builder = m::mock(Builder::class); + $builder->shouldReceive('limit')->andReturnSelf(); + $builder->shouldReceive('where')->with($this->data)->andReturnSelf(); $builder->shouldReceive('whereNotNull')->with($deletedAtColumn)->andReturnSelf(); - $builder->shouldReceive('count')->andReturn($countResult); + $builder->shouldReceive('count')->andReturn($countResult)->byDefault(); $this->connection->shouldReceive('table') ->with($this->table)