feat: enhance purge commands with environment handling and testing improvements

This commit is contained in:
hamed
2026-07-20 11:54:02 +03:30
parent 28725792d7
commit a8d33ceeaf
5 changed files with 70 additions and 25 deletions
@@ -3,10 +3,12 @@
namespace App\Tests\Doctor;
use App\Auth\Entity\User;
use App\Doctor\Command\PurgeUnclaimedDoctorsCommand;
use App\Doctor\Entity\Doctor;
use Doctrine\DBAL\Connection;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;
/**
@@ -78,6 +80,39 @@ class PurgeUnclaimedDoctorsCommandTest extends KernelTestCase
);
}
/** برخلاف app:doctors:purge، این کامند روی prod قابل اجراست — ولی فقط با سوییچ صریح. */
private function prodTester(): CommandTester
{
self::bootKernel();
return new CommandTester(
new PurgeUnclaimedDoctorsCommand(static::getContainer()->get(Connection::class), 'prod')
);
}
public function testRefusesOnProdWithoutExplicitSwitch(): void
{
$doctor = $this->makeDoctor('irimc', 'unclaimed');
$tester = $this->prodTester();
$tester->execute(['--force' => true]);
$this->assertSame(Command::FAILURE, $tester->getStatusCode());
$this->assertStringContainsString('i-know-this-is-prod', $tester->getDisplay());
$this->assertTrue($this->doctorExists($doctor->getId()), 'گاردِ prod نباید چیزی حذف کند');
}
public function testRunsOnProdWithExplicitSwitch(): void
{
$doctor = $this->makeDoctor('irimc', 'unclaimed');
$tester = $this->prodTester();
$tester->execute(['--force' => true, '--i-know-this-is-prod' => true]);
$tester->assertCommandIsSuccessful();
$this->assertFalse($this->doctorExists($doctor->getId()), 'با سوییچ صریح باید روی prod حذف کند');
}
public function testClaimedAndOtherSourceDoctorsSurvive(): void
{
$claimed = $this->makeDoctor('irimc', 'claimed', userStatus: 1);