thecrypticace / suitey
Artisan command to run middleware-like hooks during phpunit tests
Requires
- php: >=7.0.0
- illuminate/console: ^5.4
- illuminate/container: ^5.4
- illuminate/pipeline: ^5.4
- illuminate/support: ^5.4
- symfony/process: ^3.3
Requires (Dev)
- orchestra/testbench: ^3.4
- phpunit/phpunit: ^6.0
- symfony/var-dumper: ^3.2
This package is not auto-updated.
Last update: 2024-11-10 02:57:47 UTC
README
Set up the world. Run code before and after PHPUnit.
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:
php artisan test
This also accepts any parameter that PHPUnit does:
php artisan test --filter=my_test_method_name
Want to pass arguments to artisan
before PHPUnit? Use a --
to separate the two lists:
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:
[1/1] Run PHPUnit
… test details here …
Lets fix that.
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.
Adding steps
In the config for Suitey you will see a steps
array that looks like this:
"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.
"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.
Your migrations will now run before your test runs. Don't forget to remove the DatabaseMigrations
trait from your tests.
This step is configurable if your have an atypical setup. You may optionally specify a connection name and/or a path to your migrations.
"steps" => [ [ "class" => \TheCrypticAce\Suitey\MigrateDatabase::class, "options" => ["database" => "connection_name", "path" => "path_to_migrations"], ], ],
And if you have more than one migration folder:
"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
Want to see something meta?
Suitey can run its own tests:
./tests/Fixture/artisan test