Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Search for similar results #31042

Merged
merged 3 commits into from
Jan 13, 2020
Merged
Changes from 1 commit
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
Next Next commit
search for similar results
first we take the first key/value pair of the expected data, and look to see if that exists in the database. If that finds results, we'll send those back to the developer since they're easier to compare.

if we don't find any of those results, we'll fallback to the old way of just returning results from the table.
  • Loading branch information
browner12 committed Dec 19, 2019
commit 92a9702ae642683189c36f8ebb77071d611fbeb0
20 changes: 16 additions & 4 deletions src/Illuminate/Foundation/Testing/Constraints/HasInDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,25 @@ protected function getAdditionalInfo($table)
{
$query = $this->database->table($table);

$results = $query->limit($this->show)->get();
$key = array_key_first($this->data);
$value = $this->data[$key];
$similarResults = $query->where($key, $value)->limit($this->show)->get();

if ($results->isEmpty()) {
return 'The table is empty';
if ($similarResults->isNotEmpty()) {
$description = 'Found similar results: '.json_encode($similarResults, JSON_PRETTY_PRINT);
}

$description = 'Found: '.json_encode($results, JSON_PRETTY_PRINT);
else {
$query = $this->database->table($table);

$results = $query->limit($this->show)->get();

if ($results->isEmpty()) {
return 'The table is empty';
}

$description = 'Found: '.json_encode($results, JSON_PRETTY_PRINT);
}

if ($query->count() > $this->show) {
$description .= sprintf(' and %s others', $query->count() - $this->show);
Expand Down