Artisan command to run middleware-like hooks during phpunit tests

dev-master 2017-08-19 01:40 UTC

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.

Build Status Coverage Status Total Downloads Latest Stable Version License

Installation

  1. composer require thecrypticace/suitey
  2. php artisan vendor:publish --tag=suitey
  3. 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