Browse Source

Use db lazy refresh in tests & Fix some tests

Bubka 3 years ago
parent
commit
9cda570b13

+ 7 - 8
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 @@ class ResetDemoTest extends FeatureTestCase
     {
         $this->artisan('2fauth:reset-demo')
              ->expectsOutput('2fauth:reset-demo can only run when isDemoApp option is On')
-             ->assertExitCode(0);
+             ->assertSuccessful();
     }
 
     /**
@@ -29,8 +28,7 @@ class ResetDemoTest extends FeatureTestCase
         $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 @@ class ResetDemoTest extends FeatureTestCase
         $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 @@ class ResetDemoTest extends FeatureTestCase
     {
         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();
     }
 
 }

+ 4 - 7
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 @@ class ResetTestingTest extends FeatureTestCase
     {
         $this->artisan('2fauth:reset-testing')
              ->expectsOutput('2fauth:reset-testing can only run when isTestingApp option is On')
-             ->assertExitCode(0);
+             ->assertSuccessful();
     }
 
     /**
@@ -29,8 +28,7 @@ class ResetTestingTest extends FeatureTestCase
         $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 @@ class ResetTestingTest extends FeatureTestCase
         $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 @@ class ResetTestingTest extends FeatureTestCase
         Config::set('2fauth.config.isTestingApp', true);
 
         $this->artisan('2fauth:reset-testing --no-confirm')
-             ->expectsOutput('Testing app refreshed')
-             ->assertExitCode(0);
+             ->assertSuccessful();
     }
 
 }

+ 10 - 6
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]);
     }
 }