Skip to content

Instantly share code, notes, and snippets.

@shov
Created February 26, 2018 08:54
Show Gist options
  • Save shov/4ecb91efc66076721ca048b75e0cc775 to your computer and use it in GitHub Desktop.
Save shov/4ecb91efc66076721ca048b75e0cc775 to your computer and use it in GitHub Desktop.
Laravel test migration and seeding helper
<?php declare(strict_types=1);
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Contracts\Console\Kernel;
/**
* Some functionality for TestCases
*
* required:
* @method fail($message)
* @method int artisan($command, $parameters = [])
* @method void beforeApplicationDestroyed(callable $callback)
* @property \Illuminate\Foundation\Application $app
*/
trait TestHelperTrait
{
use DatabaseMigrations;
public function runDatabaseMigrations()
{
$this->artisan('migrate:fresh');
$this->artisan('db:seed');
$this->app[Kernel::class]->setArtisan(null);
$this->beforeApplicationDestroyed(function () {
$this->artisan('migrate:rollback');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment