expirationConfig = self::getContainer()->get(EntryDeletionExpirationConfig::class); $this->expirationConfig->setExpirationDays(2); $em = self::getContainer()->get(EntityManagerInterface::class); $this->entryDeletionRepository = $em->getRepository(EntryDeletion::class); } public function testRunPurgeEntryDeletionsCommandWithDryRun() { $application = new Application(self::$kernel); $command = $application->find('wallabag:purge-entry-deletions'); $tester = new CommandTester($command); $tester->execute([ '--dry-run' => true, ]); $this->assertStringContainsString('Dry run mode enabled', $tester->getDisplay()); $this->assertSame(0, $tester->getStatusCode()); $count = $this->entryDeletionRepository->countAllBefore($this->expirationConfig->getCutoffDate()); $this->assertSame(2, $count); } public function testRunPurgeEntryDeletionsCommand() { $application = new Application(self::$kernel); $command = $application->find('wallabag:purge-entry-deletions'); $tester = new CommandTester($command); $tester->setInputs(['yes']); // confirm deletion $tester->execute([]); $this->assertStringContainsString('Successfully deleted 2 records', $tester->getDisplay()); $this->assertSame(0, $tester->getStatusCode()); $count = $this->entryDeletionRepository->countAllBefore($this->expirationConfig->getCutoffDate()); $this->assertSame(0, $count); $countAll = $this->entryDeletionRepository->countAllBefore(new \DateTime('now')); $this->assertSame(1, $countAll); } public function testRunPurgeEntryDeletionsCommandWithNoRecords() { $this->expirationConfig->setExpirationDays(10); $application = new Application(self::$kernel); $command = $application->find('wallabag:purge-entry-deletions'); $tester = new CommandTester($command); $tester->execute([]); $this->assertStringContainsString('No entry deletion records found', $tester->getDisplay()); $this->assertSame(0, $tester->getStatusCode()); } }