33namespace MagicLink \Test ;
44
55use Illuminate \Database \Schema \Blueprint ;
6+ use Illuminate \Foundation \Testing \RefreshDatabase ;
67use MagicLink \MagicLinkServiceProvider ;
78use MagicLink \Test \TestSupport \User ;
89use Orchestra \Testbench \TestCase as Orchestra ;
910
1011abstract class TestCase extends Orchestra
1112{
13+ use RefreshDatabase;
14+
1215 public function setUp (): void
1316 {
1417 parent ::setUp ();
@@ -77,7 +80,7 @@ protected function defineEnvironment($app)
7780
7881 $ driver = getenv ('DB_DRIVER ' );
7982
80- if ($ driver !== 'mysql ' ) {
83+ if ($ driver !== 'pgsql ' ) {
8184 $ app ['config ' ]->set ('database.default ' , 'testbench ' );
8285 } else {
8386 $ app ['config ' ]->set ('database.default ' , $ driver );
@@ -87,31 +90,29 @@ protected function defineEnvironment($app)
8790 protected function defineDatabaseMigrations ()
8891 {
8992 $ this ->loadMigrationsFrom (__DIR__ . '/../databases/migrations ' );
90- $ this ->setUpDatabase ($ this ->app );
9193 }
9294
93- /**
94- * Set up the database.
95- *
96- * @param \Illuminate\Foundation\Application $app
97- */
98- protected function setUpDatabase ($ app )
95+ protected function refreshTestDatabase ()
9996 {
100- if ($ app ['config ' ]->get ('database.default ' ) !== 'testbench ' ) {
101- $ app ['db ' ]->connection ()->getSchemaBuilder ()->dropIfExists ('users ' );
102- $ app ['db ' ]->connection ()->getSchemaBuilder ()->dropIfExists ('migrations ' );
103- $ app ['db ' ]->connection ()->getSchemaBuilder ()->dropIfExists ('magic_links ' );
97+ if (getenv ('DB_DRIVER ' ) === 'pgsql ' ) {
98+ $ this ->app ['db ' ]->connection ()->getSchemaBuilder ()->dropIfExists ('users ' );
99+ $ this ->app ['db ' ]->connection ()->getSchemaBuilder ()->dropIfExists ('migrations ' );
100+ $ this ->app ['db ' ]->connection ()->getSchemaBuilder ()->dropIfExists ('magic_links ' );
101+ $ this ->artisan ('migrate ' , ['--database ' => getenv ('DB_DRIVER ' ) === 'pgsql ' ? 'pgsql ' : 'testbench ' ]);
104102 }
103+ }
105104
106- $ this -> artisan ( ' migrate ' );
107-
108- $ app ['db ' ]->connection ()->getSchemaBuilder ()->create ('users ' , function (Blueprint $ table ) {
105+ protected function afterRefreshingDatabase ()
106+ {
107+ $ this -> app ['db ' ]->connection ()->getSchemaBuilder ()->create ('users ' , function (Blueprint $ table ) {
109108 $ table ->increments ('id ' );
110109 $ table ->string ('email ' );
111110 $ table ->string ('remember_token ' )->nullable ();
112111 });
113112
114113 User::create (['email ' => 'test@user.com ' ]);
114+
115+ $ this ->artisan ('migrate ' , ['--database ' => getenv ('DB_DRIVER ' ) === 'pgsql ' ? 'pgsql ' : 'testbench ' ]);
115116 }
116117
117118 protected function loadRoutes ()
0 commit comments