From e52da07173da6c6a9f07fe7148269acd8a5e76be Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Mon, 9 Jan 2023 15:28:00 +1000 Subject: [PATCH 1/2] Run Fortify migrations during testing --- tests/OrchestraTestCase.php | 8 ++++++-- tests/UserProfileControllerTest.php | 17 ----------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/tests/OrchestraTestCase.php b/tests/OrchestraTestCase.php index 74cc49178..2cafaac4b 100644 --- a/tests/OrchestraTestCase.php +++ b/tests/OrchestraTestCase.php @@ -27,8 +27,6 @@ protected function getPackageProviders($app) protected function defineEnvironment($app) { - $app['migrator']->path(__DIR__.'/../database/migrations'); - $app['config']->set('database.default', 'testbench'); $app['config']->set('database.connections.testbench', [ @@ -38,6 +36,12 @@ protected function defineEnvironment($app) ]); } + protected function defineDatabaseMigrations() + { + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + $this->loadMigrationsFrom(__DIR__.'/../vendor/laravel/fortify/database/migrations'); + } + protected function defineHasTeamEnvironment($app) { $features = $app->config->get('jetstream.features', []); diff --git a/tests/UserProfileControllerTest.php b/tests/UserProfileControllerTest.php index 82cf77ede..6ca93d4d5 100644 --- a/tests/UserProfileControllerTest.php +++ b/tests/UserProfileControllerTest.php @@ -2,7 +2,6 @@ namespace Laravel\Jetstream\Tests; -use Illuminate\Support\Facades\Schema; use Laravel\Fortify\Actions\DisableTwoFactorAuthentication; use Laravel\Fortify\Features; use Laravel\Jetstream\Jetstream; @@ -20,8 +19,6 @@ public function setUp(): void public function test_empty_two_factor_state_is_noted() { - $this->migrate(); - $disable = $this->mock(DisableTwoFactorAuthentication::class); $disable->shouldReceive('__invoke')->once(); @@ -43,8 +40,6 @@ public function test_empty_two_factor_state_is_noted() public function test_two_factor_is_not_disabled_if_was_previously_empty_and_currently_confirming() { - $this->migrate(); - $disable = $this->mock(DisableTwoFactorAuthentication::class); $disable->shouldReceive('__invoke')->never(); @@ -67,8 +62,6 @@ public function test_two_factor_is_not_disabled_if_was_previously_empty_and_curr public function test_two_factor_is_disabled_if_was_previously_confirming_and_page_is_reloaded() { - $this->migrate(); - $disable = $this->mock(DisableTwoFactorAuthentication::class); $disable->shouldReceive('__invoke')->once(); @@ -92,16 +85,6 @@ public function test_two_factor_is_disabled_if_was_previously_confirming_and_pag $response->assertStatus(200); } - protected function migrate() - { - $this->artisan('migrate', ['--database' => 'testbench'])->run(); - - Schema::table('users', function ($table) { - $table->string('two_factor_secret')->nullable(); - $table->timestamp('two_factor_confirmed_at')->nullable(); - }); - } - protected function getEnvironmentSetUp($app) { parent::getEnvironmentSetUp($app); From 4a51644434d89df7d5f17dbcc6ae8026349e5925 Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Mon, 9 Jan 2023 15:32:16 +1000 Subject: [PATCH 2/2] Prevent `MissingAttributeException` --- database/factories/UserFactory.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index ade97a953..86b04b972 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -29,7 +29,11 @@ public function definition(): array 'email' => $this->faker->unique()->safeEmail(), 'email_verified_at' => now(), 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'two_factor_secret' => null, + 'two_factor_recovery_codes' => null, 'remember_token' => Str::random(10), + 'profile_photo_path' => null, + 'current_team_id' => null, ]; }