feat: add command to purge unclaimed imported doctors and their surrogates

This commit is contained in:
hamed
2026-07-20 09:44:09 +03:30
parent 97e5acdf18
commit 46d7253ad9
5 changed files with 337 additions and 6 deletions
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace App\Tests\Doctor;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;
/**
* `app:doctors:purge` کل جدول پزشکان را پاک می‌کند و باید **فقط** در dev/test اجرا
* شود. این تست قفل می‌کند که هیچ راه فراری برای prod نماند و اجرای بی‌سوییچ فقط گزارش
* بدهد.
*/
class PurgeDoctorsCommandTest extends KernelTestCase
{
private function tester(): CommandTester
{
return new CommandTester(
(new Application(self::bootKernel()))->find('app:doctors:purge')
);
}
public function testDryRunRunsInTestEnv(): void
{
$tester = $this->tester();
$tester->execute([]);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('dry-run', $tester->getDisplay());
}
public function testRefusesOnProdWithNoEscapeHatch(): void
{
self::bootKernel();
$original = $_ENV['APP_ENV'] ?? null;
$_ENV['APP_ENV'] = 'prod';
try {
$tester = new CommandTester(
(new Application(self::$kernel))->find('app:doctors:purge')
);
$tester->execute(['--force' => true]);
$this->assertSame(Command::FAILURE, $tester->getStatusCode());
$this->assertStringContainsString('فقط در محیط dev', $tester->getDisplay());
} finally {
if ($original === null) {
unset($_ENV['APP_ENV']);
} else {
$_ENV['APP_ENV'] = $original;
}
}
}
}