Files
ludikevent_crm/tests/Command/PurgeTxtCommandTest.php
Serreau Jovann 36a51c5a54 ```
 feat(ReserverController): Ajoute vérification de disponibilité produit.
🛠️ refactor(BackupCommand): Utilise DatabaseDumper et ZipArchiver.
 feat(GitSyncLogCommand): Utilise Gemini pour messages plus clairs.
 feat(GenerateVideoThumbsCommand): Utilise VideoThumbnailer service.
 feat(AppWarmupImagesCommand): Utilise StorageInterface pour warmup.
🔒️ security(nelmio_security): Renforce la sécurité avec des en-têtes.
🔧 chore(caddy): Améliore la configuration de Caddy pour la performance.
🐛 fix(makefile): Corrige les commandes de test.
🧪 chore(.env.test): Supprime la ligne vide à la fin du fichier.
🔧 chore(doctrine): Active native_lazy_objects.
🔧 chore(cache): Ajoute un cache system.
```
2026-01-30 17:58:12 +01:00

65 lines
2.2 KiB
PHP

<?php
namespace App\Tests\Command;
use App\Command\PurgeTxtCommand;
use App\Entity\Formules;
use App\Entity\Product;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
class PurgeTxtCommandTest extends TestCase
{
private MockObject&EntityManagerInterface $entityManager;
private MockObject&EntityRepository $productRepository;
private MockObject&EntityRepository $formulesRepository;
protected function setUp(): void
{
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->productRepository = $this->createMock(EntityRepository::class);
$this->formulesRepository = $this->createMock(EntityRepository::class);
$this->entityManager->method('getRepository')->willReturnMap([
[Product::class, $this->productRepository],
[Formules::class, $this->formulesRepository],
]);
}
public function testExecute()
{
// 1. Setup Product Data
$product = new Product();
$product->setDescription('<p>Description <b>HTML</b> &eacute; purger.</p>');
$this->productRepository->method('findAll')->willReturn([$product]);
// 2. Setup Formules Data
$formule = new Formules();
$formule->setDescription('<div>Une autre <br> description.</div>');
$this->formulesRepository->method('findAll')->willReturn([$formule]);
// 3. Expect Flush
$this->entityManager->expects($this->once())->method('flush');
// 4. Execute
$command = new PurgeTxtCommand($this->entityManager);
$application = new Application();
$application->add($command);
$commandTester = new CommandTester($application->find('app:txt:purge'));
$commandTester->execute([]);
// 5. Assertions
$this->assertEquals('Description HTML é purger.', $product->getDescription());
$this->assertEquals('Une autre description.', $formule->getDescription());
$this->assertStringContainsString('Purge terminée', $commandTester->getDisplay());
}
}