56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?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;
|
|
}
|
|
}
|
|
}
|
|
}
|