Skip to content

Commit 6f661f6

Browse files
authored
[2.x] Prevent MissingAttributeException (#1213)
* Run Fortify migrations during testing * Prevent `MissingAttributeException`
1 parent 0c4dd31 commit 6f661f6

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

Diff for: database/factories/UserFactory.php

+4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ public function definition(): array
2929
'email' => $this->faker->unique()->safeEmail(),
3030
'email_verified_at' => now(),
3131
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
32+
'two_factor_secret' => null,
33+
'two_factor_recovery_codes' => null,
3234
'remember_token' => Str::random(10),
35+
'profile_photo_path' => null,
36+
'current_team_id' => null,
3337
];
3438
}
3539

Diff for: tests/OrchestraTestCase.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ protected function getPackageProviders($app)
2727

2828
protected function defineEnvironment($app)
2929
{
30-
$app['migrator']->path(__DIR__.'/../database/migrations');
31-
3230
$app['config']->set('database.default', 'testbench');
3331

3432
$app['config']->set('database.connections.testbench', [
@@ -38,6 +36,12 @@ protected function defineEnvironment($app)
3836
]);
3937
}
4038

39+
protected function defineDatabaseMigrations()
40+
{
41+
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
42+
$this->loadMigrationsFrom(__DIR__.'/../vendor/laravel/fortify/database/migrations');
43+
}
44+
4145
protected function defineHasTeamEnvironment($app)
4246
{
4347
$features = $app->config->get('jetstream.features', []);

Diff for: tests/UserProfileControllerTest.php

-17
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Laravel\Jetstream\Tests;
44

5-
use Illuminate\Support\Facades\Schema;
65
use Laravel\Fortify\Actions\DisableTwoFactorAuthentication;
76
use Laravel\Fortify\Features;
87
use Laravel\Jetstream\Jetstream;
@@ -20,8 +19,6 @@ public function setUp(): void
2019

2120
public function test_empty_two_factor_state_is_noted()
2221
{
23-
$this->migrate();
24-
2522
$disable = $this->mock(DisableTwoFactorAuthentication::class);
2623
$disable->shouldReceive('__invoke')->once();
2724

@@ -43,8 +40,6 @@ public function test_empty_two_factor_state_is_noted()
4340

4441
public function test_two_factor_is_not_disabled_if_was_previously_empty_and_currently_confirming()
4542
{
46-
$this->migrate();
47-
4843
$disable = $this->mock(DisableTwoFactorAuthentication::class);
4944
$disable->shouldReceive('__invoke')->never();
5045

@@ -67,8 +62,6 @@ public function test_two_factor_is_not_disabled_if_was_previously_empty_and_curr
6762

6863
public function test_two_factor_is_disabled_if_was_previously_confirming_and_page_is_reloaded()
6964
{
70-
$this->migrate();
71-
7265
$disable = $this->mock(DisableTwoFactorAuthentication::class);
7366
$disable->shouldReceive('__invoke')->once();
7467

@@ -92,16 +85,6 @@ public function test_two_factor_is_disabled_if_was_previously_confirming_and_pag
9285
$response->assertStatus(200);
9386
}
9487

95-
protected function migrate()
96-
{
97-
$this->artisan('migrate', ['--database' => 'testbench'])->run();
98-
99-
Schema::table('users', function ($table) {
100-
$table->string('two_factor_secret')->nullable();
101-
$table->timestamp('two_factor_confirmed_at')->nullable();
102-
});
103-
}
104-
10588
protected function getEnvironmentSetUp($app)
10689
{
10790
parent::getEnvironmentSetUp($app);

0 commit comments

Comments
 (0)