fixed seeder
This commit is contained in:
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