fixed seeder
This commit is contained in:
@@ -11,30 +11,31 @@ class DatabaseSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
// Seed basic system data
|
// System defaults and catalog data required in every environment
|
||||||
$this->call([
|
$this->call([
|
||||||
MediaStorageTargetSeeder::class,
|
MediaStorageTargetSeeder::class,
|
||||||
LegalPagesSeeder::class,
|
LegalPagesSeeder::class,
|
||||||
PackageSeeder::class,
|
PackageSeeder::class,
|
||||||
]);
|
|
||||||
|
|
||||||
// Seed core demo data for frontend previews
|
|
||||||
$this->call([
|
|
||||||
EventTypesSeeder::class,
|
EventTypesSeeder::class,
|
||||||
EmotionsSeeder::class,
|
EmotionsSeeder::class,
|
||||||
TasksSeeder::class,
|
|
||||||
EventTasksSeeder::class,
|
|
||||||
TaskCollectionsSeeder::class,
|
TaskCollectionsSeeder::class,
|
||||||
InviteLayoutSeeder::class,
|
InviteLayoutSeeder::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Seed demo and admin data
|
|
||||||
$this->call([
|
$this->call([
|
||||||
|
BlogPostSeeder::class,
|
||||||
SuperAdminSeeder::class,
|
SuperAdminSeeder::class,
|
||||||
DemoTenantSeeder::class,
|
|
||||||
DemoEventSeeder::class,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (! app()->environment('production')) {
|
||||||
|
$this->call([
|
||||||
|
DemoTenantSeeder::class,
|
||||||
|
DemoEventSeeder::class,
|
||||||
|
TasksSeeder::class,
|
||||||
|
EventTasksSeeder::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if (app()->environment(['local', 'development', 'demo'])) {
|
if (app()->environment(['local', 'development', 'demo'])) {
|
||||||
$this->call([
|
$this->call([
|
||||||
DemoPhotosSeeder::class,
|
DemoPhotosSeeder::class,
|
||||||
|
|||||||
46
tests/Feature/DatabaseSeederTest.php
Normal file
46
tests/Feature/DatabaseSeederTest.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Database\Seeders\DatabaseSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class DatabaseSeederTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_production_seed_skips_demo_tenant_data(): void
|
||||||
|
{
|
||||||
|
$this->seedDatabaseForEnvironment('production');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('packages', ['slug' => 'starter']);
|
||||||
|
$this->assertDatabaseHas('blog_posts', ['slug' => '10-kreative-fotoaufgaben-fuer-eure-hochzeit']);
|
||||||
|
$this->assertDatabaseMissing('tenants', ['slug' => 'demo-tenant']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_non_production_seed_includes_demo_tenant(): void
|
||||||
|
{
|
||||||
|
$this->seedDatabaseForEnvironment('local');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('tenants', ['slug' => 'demo-tenant']);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function seedDatabaseForEnvironment(string $environment): void
|
||||||
|
{
|
||||||
|
$originalEnvironment = app()->environment();
|
||||||
|
app()->detectEnvironment(fn () => $environment);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$options = ['--class' => DatabaseSeeder::class];
|
||||||
|
|
||||||
|
if ($environment === 'production') {
|
||||||
|
$options['--force'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->artisan('db:seed', $options);
|
||||||
|
} finally {
|
||||||
|
app()->detectEnvironment(fn () => $originalEnvironment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user