Skip to content

Commit 9f3327f

Browse files
committed
chore(unit-tests): save db operations
1 parent 349d81a commit 9f3327f

2 files changed

Lines changed: 23 additions & 15 deletions

File tree

database/seeders/ConfigSeeder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function run()
3030
try {
3131
// clear all
3232
$em = Registry::getManager(ResourceServerEntity::EntityManager);
33+
$em->clear();
3334
$connection = $em->getConnection();
3435
$connection->beginTransaction();
3536
$statements = [
@@ -53,4 +54,4 @@ public function run()
5354
Log::error($ex);
5455
}
5556
}
56-
}
57+
}

tests/BrowserKitTestCase.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ abstract class BrowserKitTestCase extends BaseTestCase {
3737
*/
3838
protected $baseUrl = "http://localhost";
3939

40+
private static $seeding_done = false;
41+
4042
protected function setUp(): void {
4143
parent::setUp(); // Don't forget this!
4244
$this->redis = Redis::connection();
@@ -53,21 +55,26 @@ protected function prepareForTests(): void {
5355
// see https://laravel.com/docs/9.x/mocking#mail-fake
5456
Mail::fake();
5557
Model::unguard();
56-
// clean up
57-
DB::setDefaultConnection("model");
58-
Artisan::call("doctrine:migrations:migrate", ["--em" => "config", "--no-interaction" => true]);
59-
Artisan::call("doctrine:migrations:migrate", ["--em" => "model", "--no-interaction" => true]);
58+
if(!self::$seeding_done) {
59+
// clean up
60+
DB::setDefaultConnection("model");
61+
Artisan::call("doctrine:migrations:migrate", ["--em" => "config", "--no-interaction" => true]);
62+
Artisan::call("doctrine:migrations:migrate", ["--em" => "model", "--no-interaction" => true]);
63+
64+
DB::setDefaultConnection("config");
65+
66+
DB::delete("DELETE FROM endpoint_api_scopes");
67+
DB::delete("DELETE FROM endpoint_api_authz_groups");
68+
DB::delete("DELETE FROM api_scopes");
69+
DB::delete("DELETE FROM api_endpoints");
70+
DB::delete("DELETE FROM apis");
6071

61-
DB::setDefaultConnection("config");
6272

63-
DB::delete("DELETE FROM endpoint_api_scopes");
64-
DB::delete("DELETE FROM endpoint_api_authz_groups");
65-
DB::delete("DELETE FROM api_scopes");
66-
DB::delete("DELETE FROM api_endpoints");
67-
DB::delete("DELETE FROM apis");
73+
$this->seed(ConfigSeeder::class);
6874

69-
$this->seed(ConfigSeeder::class);
70-
$this->seed(MainDataSeeder::class);
71-
$this->seed(SummitEmailFlowTypeSeeder::class);
75+
$this->seed(MainDataSeeder::class);
76+
$this->seed(SummitEmailFlowTypeSeeder::class);
77+
self::$seeding_done = true;
78+
}
7279
}
73-
}
80+
}

0 commit comments

Comments
 (0)