From 9cda570b139437e3b555d22c0bb345766b34ebc4 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Mon, 1 Aug 2022 17:40:25 +0200 Subject: [PATCH] Use db lazy refresh in tests & Fix some tests --- tests/Feature/Console/ResetDemoTest.php | 15 +++++++-------- tests/Feature/Console/ResetTestingTest.php | 11 ++++------- tests/FeatureTestCase.php | 16 ++++++++++------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/Feature/Console/ResetDemoTest.php b/tests/Feature/Console/ResetDemoTest.php index fcff3333..743441da 100644 --- a/tests/Feature/Console/ResetDemoTest.php +++ b/tests/Feature/Console/ResetDemoTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Console; -use App\Models\User; use Tests\FeatureTestCase; use Illuminate\Support\Facades\Config; @@ -16,7 +15,7 @@ public function test_reset_demo_without_demo_mode_succeeded() { $this->artisan('2fauth:reset-demo') ->expectsOutput('2fauth:reset-demo can only run when isDemoApp option is On') - ->assertExitCode(0); + ->assertSuccessful(); } /** @@ -29,8 +28,7 @@ public function test_reset_demo_succeeded() $this->artisan('2fauth:reset-demo') ->expectsOutput('This will reset the app in order to run a clean and fresh demo.') ->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'demo') - ->expectsOutput('Demo app refreshed') - ->assertExitCode(0); + ->assertSuccessful(); $this->assertDatabaseCount('twofaccounts', 9); @@ -147,7 +145,7 @@ public function test_reset_demo_with_invalid_confirmation_succeeded() $this->artisan('2fauth:reset-demo') ->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'null') ->expectsOutput('Bad confirmation word, nothing appened') - ->assertExitCode(0); + ->assertSuccessful(); } @@ -158,9 +156,10 @@ public function test_reset_demo_with_no_confirm_option_succeeded() { Config::set('2fauth.config.isDemoApp', true); - $this->artisan('2fauth:reset-demo --no-confirm') - ->expectsOutput('Demo app refreshed') - ->assertExitCode(0); + $this->artisan('2fauth:reset-demo', [ + '--no-confirm' => true + ]) + ->assertSuccessful(); } } \ No newline at end of file diff --git a/tests/Feature/Console/ResetTestingTest.php b/tests/Feature/Console/ResetTestingTest.php index ab668924..ac7afbbc 100644 --- a/tests/Feature/Console/ResetTestingTest.php +++ b/tests/Feature/Console/ResetTestingTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Console; -use App\Models\User; use Tests\FeatureTestCase; use Illuminate\Support\Facades\Config; @@ -16,7 +15,7 @@ public function test_reset_testing_without_testing_mode_succeeded() { $this->artisan('2fauth:reset-testing') ->expectsOutput('2fauth:reset-testing can only run when isTestingApp option is On') - ->assertExitCode(0); + ->assertSuccessful(); } /** @@ -29,8 +28,7 @@ public function test_reset_testing_succeeded() $this->artisan('2fauth:reset-testing') ->expectsOutput('This will reset the app in order to run a clean and fresh testing app.') ->expectsQuestion('To prevent any mistake please type the word "testing" to go on', 'testing') - ->expectsOutput('Testing app refreshed') - ->assertExitCode(0); + ->assertSuccessful(); $this->assertDatabaseCount('twofaccounts', 9); @@ -147,7 +145,7 @@ public function test_reset_testing_with_invalid_confirmation_succeeded() $this->artisan('2fauth:reset-testing') ->expectsQuestion('To prevent any mistake please type the word "testing" to go on', 'null') ->expectsOutput('Bad confirmation word, nothing appened') - ->assertExitCode(0); + ->assertSuccessful(); } @@ -159,8 +157,7 @@ public function test_reset_testing_with_no_confirm_option_succeeded() Config::set('2fauth.config.isTestingApp', true); $this->artisan('2fauth:reset-testing --no-confirm') - ->expectsOutput('Testing app refreshed') - ->assertExitCode(0); + ->assertSuccessful(); } } \ No newline at end of file diff --git a/tests/FeatureTestCase.php b/tests/FeatureTestCase.php index 921c8035..25aa1330 100644 --- a/tests/FeatureTestCase.php +++ b/tests/FeatureTestCase.php @@ -3,22 +3,26 @@ namespace Tests; use Illuminate\Support\Facades\Artisan; -use Illuminate\Foundation\Testing\DatabaseTransactions; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; abstract class FeatureTestCase extends BaseTestCase { use CreatesApplication; - /** + /** * Rollback and execute migrations for each test. */ - use DatabaseTransactions; + use LazilyRefreshDatabase; - protected function setUp(): void + + /** + * Perform any work that should take place once the database has finished refreshing. + * + * @return void + */ + protected function afterRefreshingDatabase() { - parent::setUp(); - Artisan::call('migrate'); Artisan::call('passport:install',['--verbose' => 2]); } }