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('

Description HTML é purger.

'); $this->productRepository->method('findAll')->willReturn([$product]); // 2. Setup Formules Data $formule = new Formules(); $formule->setDescription('
Une autre
description.
'); $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()); } }