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
Prev Previous commit
Update FoundationInteractsWithDatabaseTest.php
allow the builder to receive a `where` clause containing the first element of the data.
  • Loading branch information
browner12 committed Jan 6, 2020
commit 7fcf5a6723fe14121e0e1729a794162904571056
14 changes: 11 additions & 3 deletions tests/Foundation/FoundationInteractsWithDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class FoundationInteractsWithDatabaseTest extends TestCase

protected $table = 'products';

protected $data = ['title' => 'Spark'];
protected $data = [
'title' => 'Spark',
'name' => 'Laravel',
];

protected $connection;

Expand Down Expand Up @@ -54,7 +57,7 @@ public function testSeeInDatabaseFindsNotMatchingResults()
{
$this->expectException(ExpectationFailedException::class);

$this->expectExceptionMessage('Found: '.json_encode([['title' => 'Forge']], JSON_PRETTY_PRINT));
$this->expectExceptionMessage('Found similar results: '.json_encode([['title' => 'Forge']], JSON_PRETTY_PRINT));

$builder = $this->mockCountBuilder(0);

Expand All @@ -68,7 +71,7 @@ public function testSeeInDatabaseFindsManyNotMatchingResults()
{
$this->expectException(ExpectationFailedException::class);

$this->expectExceptionMessage('Found: '.json_encode(['data', 'data', 'data'], JSON_PRETTY_PRINT).' and 2 others.');
$this->expectExceptionMessage('Found similar results: '.json_encode(['data', 'data', 'data'], JSON_PRETTY_PRINT).' and 2 others.');

$builder = $this->mockCountBuilder(0);
$builder->shouldReceive('count')->andReturn(0, 5);
Expand Down Expand Up @@ -193,6 +196,11 @@ protected function mockCountBuilder($countResult, $deletedAtColumn = 'deleted_at
{
$builder = m::mock(Builder::class);

$key = array_key_first($this->data);
$value = $this->data[$key];

$builder->shouldReceive('where')->with($key, $value)->andReturnSelf();

$builder->shouldReceive('limit')->andReturnSelf();

$builder->shouldReceive('where')->with($this->data)->andReturnSelf();
Expand Down