Skip to content

Commit

Permalink
Update FoundationInteractsWithDatabaseTest.php
Browse files Browse the repository at this point in the history
allow the builder to receive a `where` clause containing the first element of the data.
  • Loading branch information
browner12 committed Jan 6, 2020
1 parent 810dfac commit 7fcf5a6
Showing 1 changed file with 11 additions and 3 deletions.
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

0 comments on commit 7fcf5a6

Please sign in to comment.