Created
February 26, 2018 08:54
-
-
Save shov/4ecb91efc66076721ca048b75e0cc775 to your computer and use it in GitHub Desktop.
Laravel test migration and seeding helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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