Skip to content

Commit

Permalink
Move group creation to seeder
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Nov 6, 2023
1 parent b0b0ce7 commit c6c2271
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
2 changes: 2 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class DatabaseSeeder extends Seeder
public function run()
{
try {
$this->call(ModelSeeders\GroupSeeder::class);

// Miscellaneous Data (e.g. counts)
$this->call(ModelSeeders\MiscSeeder::class);

Expand Down
28 changes: 28 additions & 0 deletions database/seeders/ModelSeeders/GroupSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace Database\Seeders\ModelSeeders;

use App\Models\Group;
use Illuminate\Database\Seeder;

class GroupSeeder extends Seeder
{
public function run(): void
{
Group::truncate();
foreach (Group::PRIV_IDENTIFIERS as $identifier) {
Group::create([
'group_desc' => '',
'group_name' => $identifier,
'group_type' => 2,
'identifier' => $identifier,
'short_name' => $identifier,
]);
}
}
}
12 changes: 2 additions & 10 deletions tests/SeederExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Tests;

use App\Models\Group;
use Database\Seeders\ModelSeeders\GroupSeeder;
use PHPUnit\Runner\AfterLastTestHook;
use PHPUnit\Runner\BeforeFirstTestHook;

Expand All @@ -23,16 +24,7 @@ public function executeAfterLastTest(): void
public function executeBeforeFirstTest(): void
{
TestCase::withDbAccess(function () {
Group::truncate();
foreach (Group::PRIV_IDENTIFIERS as $identifier) {
Group::create([
'group_desc' => '',
'group_name' => $identifier,
'group_type' => 2,
'identifier' => $identifier,
'short_name' => $identifier,
]);
}
(new GroupSeeder())->run();
});
}
}

0 comments on commit c6c2271

Please sign in to comment.