Files
Investidor-V2/tests/Unit/IsolatedMigrationGuardTest.php
T

40 lines
2.2 KiB
PHP

<?php
namespace Tests\Unit;
use Illuminate\Foundation\Testing\TestCase;
use Illuminate\Support\Facades\DB;
use PHPUnit\Framework\Attributes\DataProvider;
use RuntimeException;
class IsolatedMigrationGuardTest extends TestCase
{
public static function rejectedTargets(): iterable
{
$migrations = ['2026_10_16_130000_add_investment_zone_editorial_draft', '2026_10_16_140000_add_investment_zone_operational_details', '2026_10_16_150000_create_investor_navigation_preferences', '2026_10_18_160000_add_portal_editorial_content'];
$cases = ['production' => ['environment' => 'production'], 'active-name' => ['database' => 'investemoz'], 'active-port' => ['port' => '5432'], 'remote-host' => ['host' => 'example.invalid'], 'database-url' => ['url' => 'postgresql://example.invalid/test'], 'other-driver' => ['driver' => 'sqlite']];
foreach ($migrations as $migration) {
foreach ($cases as $name => $patch) {
yield $migration.'/'.$name => [$migration, $patch];
}
}
}
#[DataProvider('rejectedTargets')]
public function test_new_qa_allowance_cannot_run_outside_the_isolated_target(string $migration, array $patch): void
{
$environment = $patch['environment'] ?? 'testing';
unset($patch['environment']);
app()->instance('env', $environment);
config(['database.default' => 'pgsql', 'database.connections.pgsql' => [...config('database.connections.pgsql'), 'driver' => 'pgsql', 'host' => '127.0.0.1', 'port' => '55441', 'database' => 'migration_guard_test', 'url' => null, ...$patch],
'investment-zone-profile.authenticated_installation' => false, 'investment-zone-details.authenticated_installation' => false, 'investor-context.authenticated_installation' => false, 'editorial.authenticated_installation' => false]);
if (($patch['driver'] ?? '') === 'sqlite') {
config(['database.default' => 'sqlite']);
}
DB::shouldReceive('selectOne')->never();
DB::shouldReceive('connection')->never();
$this->expectException(RuntimeException::class);
(require database_path('migrations/'.$migration.'.php'))->up();
}
}