feat: enhance purge commands with environment handling and testing improvements
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user