Skip to content

Commit

Permalink
consolidate assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 7, 2016
1 parent 14e9dad commit f23ac64
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

trait InteractsWithContainer
{
/**
* Register an instance of an object in the container.
*
* @param string $abstract
* @param object $instance
* @return object
*/
protected function swap($abstract, $instance)
{
return $this->instance($abstract, $instance);
}

/**
* Register an instance of an object in the container.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait InteractsWithDatabase
* @param string $connection
* @return $this
*/
protected function seeInDatabase($table, array $data, $connection = null)
protected function assertDatabaseHas($table, array $data, $connection = null)
{
$this->assertThat(
$table, new HasInDatabase($this->getConnection($connection), $data)
Expand All @@ -32,7 +32,7 @@ protected function seeInDatabase($table, array $data, $connection = null)
* @param string $connection
* @return $this
*/
protected function missingFromDatabase($table, array $data, $connection = null)
protected function assertDatabaseMissing($table, array $data, $connection = null)
{
$constraint = new ReverseConstraint(
new HasInDatabase($this->getConnection($connection), $data)
Expand All @@ -43,32 +43,6 @@ protected function missingFromDatabase($table, array $data, $connection = null)
return $this;
}

/**
* Assert that a given where condition does not exist in the database.
*
* @param string $table
* @param array $data
* @param string $connection
* @return $this
*/
protected function dontSeeInDatabase($table, array $data, $connection = null)
{
return $this->notSeeInDatabase($table, $data, $connection);
}

/**
* Assert that a given where condition does not exist in the database.
*
* @param string $table
* @param array $data
* @param string $connection
* @return $this
*/
protected function notSeeInDatabase($table, array $data, $connection = null)
{
return $this->missingFromDatabase($table, $data, $connection);
}

/**
* Get the database connection.
*
Expand Down
12 changes: 6 additions & 6 deletions tests/Foundation/FoundationInteractsWithDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testSeeInDatabaseFindsResults()
{
$this->mockCountBuilder(1);

$this->seeInDatabase($this->table, $this->data);
$this->assertDatabaseHas($this->table, $this->data);
}

/**
Expand All @@ -42,7 +42,7 @@ public function testSeeInDatabaseDoesNotFindResults()

$builder->shouldReceive('get')->andReturn(collect());

$this->seeInDatabase($this->table, $this->data);
$this->assertDatabaseHas($this->table, $this->data);
}

/**
Expand All @@ -57,7 +57,7 @@ public function testSeeInDatabaseFindsNotMatchingResults()
$builder->shouldReceive('take')->andReturnSelf();
$builder->shouldReceive('get')->andReturn(collect([['title' => 'Forge']]));

$this->seeInDatabase($this->table, $this->data);
$this->assertDatabaseHas($this->table, $this->data);
}

/**
Expand All @@ -74,14 +74,14 @@ public function testSeeInDatabaseFindsManyNotMatchingResults()
collect(array_fill(0, 5, 'data'))
);

$this->seeInDatabase($this->table, $this->data);
$this->assertDatabaseHas($this->table, $this->data);
}

public function testDontSeeInDatabaseDoesNotFindResults()
{
$this->mockCountBuilder(0);

$this->dontSeeInDatabase($this->table, $this->data);
$this->assertDatabaseMissing($this->table, $this->data);
}

/**
Expand All @@ -95,7 +95,7 @@ public function testDontSeeInDatabaseFindsResults()
$builder->shouldReceive('take')->andReturnSelf();
$builder->shouldReceive('get')->andReturn(collect([$this->data]));

$this->dontSeeInDatabase($this->table, $this->data);
$this->assertDatabaseMissing($this->table, $this->data);
}

protected function mockCountBuilder($countResult)
Expand Down

0 comments on commit f23ac64

Please sign in to comment.