DatabaseTestTrait
DatabaseTestTrait
Provides functionality for refreshing/seeding the database during testing.
Tags
Table of Contents
- $doneMigration : bool
- Is db migration done once or more than once?
- $doneSeed : bool
- Is seeding done once or more than once?
- dontSeeInDatabase() : void
- Asserts that records that match the conditions in $where do not exist in the database.
- grabFromDatabase() : bool
- Fetches a single column from a database row with criteria matching $where.
- hasInDatabase() : bool
- Inserts a row into to the database. This row will be removed after the test has run.
- loadBuilder() : BaseBuilder
- Loads the Builder class appropriate for the current database.
- loadDependencies() : mixed
- Load any database test dependencies.
- resetMigrationSeedCount() : mixed
- Reset $doneMigration and $doneSeed
- seed() : void
- Seeds that database with a specific seeder.
- seeInDatabase() : void
- Asserts that records that match the conditions in $where DO exist in the database.
- seeNumRecords() : void
- Asserts that the number of rows in the database that match $where is equal to $expected.
- clearInsertCache() : mixed
- Removes any rows inserted via $this->hasInDatabase()
- migrateDatabase() : mixed
- Run migrations as defined by the class
- regressDatabase() : mixed
- Regress migrations as defined by the class
- runSeeds() : mixed
- Run seeds as defined by the class
- setUpDatabase() : mixed
- Runs the trait set up methods.
- setUpMigrate() : mixed
- Migrate on setUp
- setUpSeed() : mixed
- Seed on setUp
- tearDownDatabase() : mixed
- Runs the trait set up methods.
Properties
$doneMigration
Is db migration done once or more than once?
private
static bool
$doneMigration
= false
$doneSeed
Is seeding done once or more than once?
private
static bool
$doneSeed
= false
Methods
dontSeeInDatabase()
Asserts that records that match the conditions in $where do not exist in the database.
public
dontSeeInDatabase(string $table, array<string|int, mixed> $where) : void
Parameters
- $table : string
- $where : array<string|int, mixed>
Return values
void —grabFromDatabase()
Fetches a single column from a database row with criteria matching $where.
public
grabFromDatabase(string $table, string $column, array<string|int, mixed> $where) : bool
Parameters
- $table : string
- $column : string
- $where : array<string|int, mixed>
Tags
Return values
bool —hasInDatabase()
Inserts a row into to the database. This row will be removed after the test has run.
public
hasInDatabase(string $table, array<string|int, mixed> $data) : bool
Parameters
- $table : string
- $data : array<string|int, mixed>
Return values
bool —loadBuilder()
Loads the Builder class appropriate for the current database.
public
loadBuilder(string $tableName) : BaseBuilder
Parameters
- $tableName : string
Return values
BaseBuilder —loadDependencies()
Load any database test dependencies.
public
loadDependencies() : mixed
Return values
mixed —resetMigrationSeedCount()
Reset $doneMigration and $doneSeed
public
static resetMigrationSeedCount() : mixed
Tags
Return values
mixed —seed()
Seeds that database with a specific seeder.
public
seed(string $name) : void
Parameters
- $name : string
Return values
void —seeInDatabase()
Asserts that records that match the conditions in $where DO exist in the database.
public
seeInDatabase(string $table, array<string|int, mixed> $where) : void
Parameters
- $table : string
- $where : array<string|int, mixed>
Tags
Return values
void —seeNumRecords()
Asserts that the number of rows in the database that match $where is equal to $expected.
public
seeNumRecords(int $expected, string $table, array<string|int, mixed> $where) : void
Parameters
- $expected : int
- $table : string
- $where : array<string|int, mixed>
Tags
Return values
void —clearInsertCache()
Removes any rows inserted via $this->hasInDatabase()
protected
clearInsertCache() : mixed
Return values
mixed —migrateDatabase()
Run migrations as defined by the class
protected
migrateDatabase() : mixed
Return values
mixed —regressDatabase()
Regress migrations as defined by the class
protected
regressDatabase() : mixed
Return values
mixed —runSeeds()
Run seeds as defined by the class
protected
runSeeds() : mixed
Return values
mixed —setUpDatabase()
Runs the trait set up methods.
protected
setUpDatabase() : mixed
Return values
mixed —setUpMigrate()
Migrate on setUp
protected
setUpMigrate() : mixed
Return values
mixed —setUpSeed()
Seed on setUp
protected
setUpSeed() : mixed
Return values
mixed —tearDownDatabase()
Runs the trait set up methods.
protected
tearDownDatabase() : mixed