trait InteractsWithDatabase (View source)

Methods

$this
assertDatabaseHas(Model|string $table, array $data, string|null $connection = null)

Assert that a given where condition exists in the database.

$this
assertDatabaseMissing(Model|string $table, array $data, string|null $connection = null)

Assert that a given where condition does not exist in the database.

$this
assertDatabaseCount(Model|string $table, int $count, string|null $connection = null)

Assert the count of table entries.

$this
assertDatabaseEmpty(Model|string $table, string|null $connection = null)

Assert that the given table has no entries.

$this
assertSoftDeleted(Model|string $table, array $data = [], string|null $connection = null, string|null $deletedAtColumn = 'deleted_at')

Assert the given record has been "soft deleted".

$this
assertNotSoftDeleted(Model|string $table, array $data = [], string|null $connection = null, string|null $deletedAtColumn = 'deleted_at')

Assert the given record has not been "soft deleted".

$this
assertModelExists(Model $model)

Assert the given model exists in the database.

$this
assertModelMissing(Model $model)

Assert the given model does not exist in the database.

$this
expectsDatabaseQueryCount(int $expected, string|null $connection = null)

Specify the number of database queries that should occur throughout the test.

bool
isSoftDeletableModel(mixed $model)

Determine if the argument is a soft deletable model.

castAsJson(array|object|string $value)

Cast a JSON string to a database compatible type.

getConnection(string|null $connection = null, string|null $table = null)

Get the database connection.

string
getTable(Model|string $table)

Get the table name from the given model or string.

string|null
getTableConnection(Model|string $table)

Get the table connection specified in the given model.

string
getDeletedAtColumn(string $table, string $defaultColumnName = 'deleted_at')

Get the table column name used for soft deletes.

Model|null
newModelFor(Model|string $table)

Get the model entity from the given model or string.

$this
seed(array|string $class = 'Database\\Seeders\\DatabaseSeeder')

Seed a given database connection.

Details

protected $this assertDatabaseHas(Model|string $table, array $data, string|null $connection = null)

Assert that a given where condition exists in the database.

Parameters

Model|string $table
array $data
string|null $connection

Return Value

$this

protected $this assertDatabaseMissing(Model|string $table, array $data, string|null $connection = null)

Assert that a given where condition does not exist in the database.

Parameters

Model|string $table
array $data
string|null $connection

Return Value

$this

protected $this assertDatabaseCount(Model|string $table, int $count, string|null $connection = null)

Assert the count of table entries.

Parameters

Model|string $table
int $count
string|null $connection

Return Value

$this

protected $this assertDatabaseEmpty(Model|string $table, string|null $connection = null)

Assert that the given table has no entries.

Parameters

Model|string $table
string|null $connection

Return Value

$this

protected $this assertSoftDeleted(Model|string $table, array $data = [], string|null $connection = null, string|null $deletedAtColumn = 'deleted_at')

Assert the given record has been "soft deleted".

Parameters

Model|string $table
array $data
string|null $connection
string|null $deletedAtColumn

Return Value

$this

protected $this assertNotSoftDeleted(Model|string $table, array $data = [], string|null $connection = null, string|null $deletedAtColumn = 'deleted_at')

Assert the given record has not been "soft deleted".

Parameters

Model|string $table
array $data
string|null $connection
string|null $deletedAtColumn

Return Value

$this

protected $this assertModelExists(Model $model)

Assert the given model exists in the database.

Parameters

Model $model

Return Value

$this

protected $this assertModelMissing(Model $model)

Assert the given model does not exist in the database.

Parameters

Model $model

Return Value

$this

$this expectsDatabaseQueryCount(int $expected, string|null $connection = null)

Specify the number of database queries that should occur throughout the test.

Parameters

int $expected
string|null $connection

Return Value

$this

protected bool isSoftDeletableModel(mixed $model)

Determine if the argument is a soft deletable model.

Parameters

mixed $model

Return Value

bool

Expression castAsJson(array|object|string $value)

Cast a JSON string to a database compatible type.

Parameters

array|object|string $value

Return Value

Expression

protected Connection getConnection(string|null $connection = null, string|null $table = null)

Get the database connection.

Parameters

string|null $connection
string|null $table

Return Value

Connection

protected string getTable(Model|string $table)

Get the table name from the given model or string.

Parameters

Model|string $table

Return Value

string

protected string|null getTableConnection(Model|string $table)

Get the table connection specified in the given model.

Parameters

Model|string $table

Return Value

string|null

protected string getDeletedAtColumn(string $table, string $defaultColumnName = 'deleted_at')

Get the table column name used for soft deletes.

Parameters

string $table
string $defaultColumnName

Return Value

string

protected Model|null newModelFor(Model|string $table)

Get the model entity from the given model or string.

Parameters

Model|string $table

Return Value

Model|null

$this seed(array|string $class = 'Database\\Seeders\\DatabaseSeeder')

Seed a given database connection.

Parameters

array|string $class

Return Value

$this