Files
clinicpro/tests/Doctor/PurgeDoctorsCommandTest.php
T

51 lines
1.8 KiB
PHP

<?php
namespace App\Tests\Doctor;
use App\Doctor\Command\PurgeDoctorsCommand;
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;
/**
* `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());
}
/**
* محیط از kernel تزریق می‌شود، پس گارد با ساختِ مستقیم کامند در محیط prod تست
* می‌شود — نه با دست‌کاری $_ENV که دیگر خوانده نمی‌شود.
*/
public function testRefusesOnProdWithNoEscapeHatch(): void
{
self::bootKernel();
$command = new PurgeDoctorsCommand(static::getContainer()->get(Connection::class), 'prod');
$tester = new CommandTester($command);
$tester->execute(['--force' => true]);
$this->assertSame(Command::FAILURE, $tester->getStatusCode());
$this->assertStringContainsString('فقط در محیط dev', $tester->getDisplay());
}
}