diff --git a/tests/AlwaysRunFirstTest.php b/tests/AlwaysRunFirstTest.php deleted file mode 100644 index dab787f..0000000 --- a/tests/AlwaysRunFirstTest.php +++ /dev/null @@ -1,48 +0,0 @@ -app['config']->set('database.default', 'baseline'); - $this->app['config']->set('database.connections.baseline', [ - 'driver' => 'sqlite', - "url" => null, - 'database' => __DIR__ . '/database/baseline.sqlite', - 'prefix' => '', - "foreign_key_constraints" => false, - ]); - - $this->createBaselineSqliteDatabase(); - - $this->withFactories(__DIR__ . '/database/factories'); - $this->loadMigrationsFrom(__DIR__ . '/database/migrations'); - - $this - ->artisan( - 'db:seed', - [ - '--class' => 'DatabaseSeeder', - '--database' => 'baseline', - ] - ) - ->run(); - } - - private function createBaselineSqliteDatabase() - { - shell_exec("cd " . __DIR__ . "/database && rm *.sqlite && touch baseline.sqlite"); - } - - /** @test */ - public function migrateAndInstallTheDatabase() - { - $this->assertTrue(true); - } -} diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index 4d13dcf..709f9e4 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -5,6 +5,7 @@ trait CreatesApplication { use EnvironmentSetup; + use MigrateBaselineDatabase; protected $cache; protected $testingSqlitePath; @@ -22,18 +23,16 @@ protected function cache() public function setUp() : void { + parent::setUp(); + $this->setUpBaseLineSqlLiteDatabase(); + $databasePath = __DIR__ . "/database"; $this->testingSqlitePath = "{$databasePath}/"; $baselinePath = "{$databasePath}/baseline.sqlite"; $testingPath = "{$databasePath}/testing.sqlite"; - if (file_exists($testingPath)) { - unlink($testingPath); - } - - shell_exec("cp {$baselinePath} {$testingPath}"); - - parent::setUp(); + ! file_exists($testingPath) ?: unlink($testingPath); + copy($baselinePath, $testingPath); require(__DIR__ . '/routes/web.php'); diff --git a/tests/MigrateBaselineDatabase.php b/tests/MigrateBaselineDatabase.php new file mode 100644 index 0000000..25a4d93 --- /dev/null +++ b/tests/MigrateBaselineDatabase.php @@ -0,0 +1,42 @@ +app['config']->set('database.default', 'baseline'); + $this->app['config']->set('database.connections.baseline', [ + 'driver' => 'sqlite', + "url" => null, + 'database' => $file, + 'prefix' => '', + "foreign_key_constraints" => false, + ]); + + ! file_exists($file) ?: unlink($file); + touch($file); + + $this->withFactories(__DIR__ . '/database/factories'); + $this->loadMigrationsFrom(__DIR__ . '/database/migrations'); + + Artisan::call('db:seed', [ + '--class' => 'DatabaseSeeder', + '--database' => 'baseline', + ]); + + // Reset default connection to testing + $this->app['config']->set('database.default', 'testing'); + } +} diff --git a/tests/database/.gitignore b/tests/database/.gitignore new file mode 100644 index 0000000..9b1dffd --- /dev/null +++ b/tests/database/.gitignore @@ -0,0 +1 @@ +*.sqlite diff --git a/tests/database/baseline.sqlite b/tests/database/baseline.sqlite deleted file mode 100644 index 92249b2..0000000 Binary files a/tests/database/baseline.sqlite and /dev/null differ diff --git a/tests/database/testing.sqlite b/tests/database/testing.sqlite deleted file mode 100644 index 92249b2..0000000 Binary files a/tests/database/testing.sqlite and /dev/null differ