diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php index 42b613ebf76d..a2e60e7916f8 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php @@ -4,7 +4,7 @@ use PHPUnit_Framework_Constraint_Not as ReverseConstraint; use Illuminate\Foundation\Testing\Constraints\HasInDatabase; -use Illuminate\Foundation\Testing\Constraints\HasSoftDeletedInDatabase; +use Illuminate\Foundation\Testing\Constraints\SoftDeletedInDatabase; trait InteractsWithDatabase { @@ -45,17 +45,17 @@ protected function assertDatabaseMissing($table, array $data, $connection = null } /** - * Assert that a given where condition exists in the database. + * Assert the given record has been deleted. * * @param string $table * @param array $data * @param string $connection * @return $this */ - protected function assertDatabaseHasSoftDelete($table, array $data, $connection = null) + protected function assertSoftDeleted($table, array $data, $connection = null) { $this->assertThat( - $table, new HasSoftDeletedInDatabase($this->getConnection($connection), $data) + $table, new SoftDeletedInDatabase($this->getConnection($connection), $data) ); return $this; diff --git a/src/Illuminate/Foundation/Testing/Constraints/HasSoftDeletedInDatabase.php b/src/Illuminate/Foundation/Testing/Constraints/HasSoftDeletedInDatabase.php deleted file mode 100644 index 75854cf180d8..000000000000 --- a/src/Illuminate/Foundation/Testing/Constraints/HasSoftDeletedInDatabase.php +++ /dev/null @@ -1,102 +0,0 @@ -data = $data; - - $this->database = $database; - } - - /** - * Check if the data is found in the given table. - * - * @param string $table - * @return bool - */ - public function matches($table) - { - return $this->database->table($table)->where($this->data)->whereNotNull('deleted_at')->count() > 0; - } - - /** - * Get the description of the failure. - * - * @param string $table - * @return string - */ - public function failureDescription($table) - { - return sprintf( - "a soft deleted row in the table [%s] matches the attributes %s.\n\n%s", - $table, $this->toString(), $this->getAdditionalInfo($table) - ); - } - - /** - * Get additional info about the records found in the database table. - * - * @param string $table - * @return string - */ - protected function getAdditionalInfo($table) - { - $results = $this->database->table($table)->get(); - - if ($results->isEmpty()) { - return 'The table is empty'; - } - - $description = 'Found: '.json_encode($results->take($this->show), JSON_PRETTY_PRINT); - - if ($results->count() > $this->show) { - $description .= sprintf(' and %s others', $results->count() - $this->show); - } - - return $description; - } - - /** - * Get a string representation of the object. - * - * @return string - */ - public function toString() - { - return json_encode($this->data); - } -} diff --git a/tests/Foundation/FoundationInteractsWithDatabaseTest.php b/tests/Foundation/FoundationInteractsWithDatabaseTest.php index a4fa7d654940..fd0d7ad95ef3 100644 --- a/tests/Foundation/FoundationInteractsWithDatabaseTest.php +++ b/tests/Foundation/FoundationInteractsWithDatabaseTest.php @@ -105,7 +105,7 @@ public function testSeeSoftDeletedInDatabaseFindsResults() { $this->mockCountBuilder(1); - $this->assertDatabaseHasSoftDelete($this->table, $this->data); + $this->assertSoftDeleted($this->table, $this->data); } /** @@ -118,7 +118,7 @@ public function testSeeSoftDeletedInDatabaseDoesNotFindResults() $builder->shouldReceive('get')->andReturn(collect()); - $this->assertDatabaseHasSoftDelete($this->table, $this->data); + $this->assertSoftDeleted($this->table, $this->data); } protected function mockCountBuilder($countResult)