Suitey
Set up the world. Run code before and after PHPUnit., (*1)
, (*2)
Installation
composer require thecrypticace/suitey
php artisan vendor:publish --tag=suitey
- Update
steps list to configure and run the steps you want before your tests.
Usage
Run your tests with the test artisan command:, (*3)
php artisan test
This also accepts any parameter that PHPUnit does:, (*4)
php artisan test --filter=my_test_method_name
Want to pass arguments to artisan before PHPUnit? Use a -- to separate the two lists:, (*5)
php artisan test -vvv -- --filter=my_test_method_name
Adding steps
When you run php artisan test you'll be running one step: PHPUnit. You'll can see this because you will get
output that looks like this:, (*6)
[1/1] Run PHPUnit
… test details here …
Lets fix that., (*7)
Publishing the config
Run php artisan vendor:publish --tag=suitey to publish the config file. This file is where you can detail what steps run and how to load the test environment variables for tests., (*8)
Adding steps
In the config for Suitey you will see a steps array that looks like this:, (*9)
"steps" => [
// \TheCrypticAce\Suitey\MigrateDatabase::class,
// \TheCrypticAce\Suitey\RefreshDatabase::class,
// [
// "class" => \TheCrypticAce\Suitey\SeedDatabase::class,
// "options" => ["class" => "ExampleSeeder"],
// ]
],
Uncomment the MigrateDatabase step and your database migrations will run before your tests., (*10)
"steps" => [
\TheCrypticAce\Suitey\MigrateDatabase::class,
// \TheCrypticAce\Suitey\RefreshDatabase::class,
// [
// "class" => \TheCrypticAce\Suitey\SeedDatabase::class,
// "options" => ["class" => "ExampleSeeder"],
// ]
],
Note: You may resolve the class through the container instead of using the facade if your wish., (*11)
Your migrations will now run before your test runs. Don't forget to remove the DatabaseMigrations trait from your tests., (*12)
This step is configurable if your have an atypical setup. You may optionally specify a connection name and/or a path to your migrations., (*13)
"steps" => [
[
"class" => \TheCrypticAce\Suitey\MigrateDatabase::class,
"options" => ["database" => "connection_name", "path" => "path_to_migrations"],
],
],
And if you have more than one migration folder:, (*14)
"steps" => [
[
"class" => \TheCrypticAce\Suitey\MigrateDatabase::class,
"options" => ["database" => "foo", "path" => "database/migrations/foo"],
],
[
"class" => \TheCrypticAce\Suitey\MigrateDatabase::class,
"options" => ["database" => "bar", "path" => "database/migrations/bar"],
],
[
"class" => \TheCrypticAce\Suitey\MigrateDatabase::class,
"options" => ["database" => "baz", "path" => "database/migrations/baz"],
],
],
Available Steps
| Class |
Config Option |
Description |
MigrateDatabase |
Migrate a database via migrate and migrate:rollback before/after phpunit |
| database |
optional The default connection to use during migration |
| path |
optionalThe path to your migration files |
RefreshDatabase |
Refresh a database via migrate:refresh before starting phpunit |
| database |
optionalThe default connection to use during migration |
| path |
optionalThe path to your migration files |
SeedDatabase |
Run the given seeder before starting PHPUnit |
| name |
required The name of the seeder you would like to run |
RunCode |
Run a closure! |
| name |
required The name displayed to the user. This can be a closure that determines the name if needed. |
| code |
required The code to run |
Suitey can run its own tests:
./tests/Fixture/artisan test, (*15)