diff --git a/src/Autoload.php b/src/Autoload.php index 5ea8c98..b1a255b 100644 --- a/src/Autoload.php +++ b/src/Autoload.php @@ -3,6 +3,7 @@ (static function () { $files = [ 'InteractsWithAuthentication.php', + 'InteractsWithDatabase.php', ]; foreach ($files as $file) { diff --git a/src/InteractsWithDatabase.php b/src/InteractsWithDatabase.php new file mode 100644 index 0000000..1502545 --- /dev/null +++ b/src/InteractsWithDatabase.php @@ -0,0 +1,75 @@ + $data + * @param string|null $connection + */ + function assertDatabaseHas($table, array $data, $connection = null): TestCase + { + return test()->assertDatabaseHas($table, $data, $connection); + } +} + +if (!function_exists('assertDatabaseMissing')) { + /** + * Assert that a table in the database does not contain the given data. + * + * @param string $table + * @param array $data + * @param string|null $connection + */ + function assertDatabaseMissing($table, array $data, $connection = null): TestCase + { + return test()->assertDatabaseHas($table, $data, $connection); + } +} + +if (!function_exists('assertDatabaseCount')) { + /** + * Assert the count of table entries. + * + * @param string $table + * @param string|null $connection + */ + function assertDatabaseCount($table, int $count, $connection = null): TestCase + { + return test()->assertDatabaseCount($table, $count, $connection); + } +} + +if (!function_exists('assertDeleted')) { + /** + * Assert that the given record has been deleted. + * + * @param \Illuminate\Database\Eloquent\Model|string $table + * @param array $data + * @param string|null $connection + */ + function assertDeleted($table, array $data = [], $connection = null): TestCase + { + return test()->assertDeleted($table, $data, $connection); + } +} + +if (!function_exists('assertSoftDeleted')) { + /** + * Assert that the given record has been "soft deleted". + * + * @param \Illuminate\Database\Eloquent\Model|string $table + * @param array $data + * @param string|null $connection + * @param string|null $deletedAtColumn + */ + function assertSoftDeleted($table, array $data = [], $connection = null, $deletedAtColumn = 'deleted_at'): TestCase + { + return test()->assertSoftDeleted($table, $data, $connection, $deletedAtColumn); + } +} diff --git a/tests/InteractsWithDatabase.php b/tests/InteractsWithDatabase.php new file mode 100644 index 0000000..ba344f5 --- /dev/null +++ b/tests/InteractsWithDatabase.php @@ -0,0 +1,16 @@ +assertTrue(function_exists('assertDatabaseHas')); + +it('has assertDatabaseMissing') + ->assertTrue(function_exists('assertDatabaseMissing')); + +it('has assertDatabaseCount') + ->assertTrue(function_exists('assertDatabaseCount')); + +it('has assertDeleted') + ->assertTrue(function_exists('assertDeleted')); + +it('has assertSoftDeleted') + ->assertTrue(function_exists('assertSoftDeleted'));