Files
piratepoet/mailpoet/tests/integration/Logging/LogRepositoryTest.php
Rodrigo Primo afe378ba22 Replace expect()->equals() with verify()->equals()
codeception/verify 2.1 removed support for expect()->equals() so we need
to replace it with verify()->equals().

[MAILPOET-5664]
2023-10-24 08:58:22 +03:00

35 lines
1.1 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Logging;
use MailPoet\Test\DataFactories\Log;
use MailPoetVendor\Carbon\Carbon;
class LogRepositoryTest extends \MailPoetTest {
/** @var LogRepository */
private $repository;
public function _before() {
$this->repository = $this->diContainer->get(LogRepository::class);
}
public function testDeletesOldLogs() {
$logFactory = new Log();
$logFactory->withCreatedAt(Carbon::now()->subDays(50))->create(); // Oldest one to delete
$log2 = $logFactory->withCreatedAt(Carbon::now()->subDays(40))->create(); // Old enough to delete but not the oldest one
$log3 = $logFactory->withCreatedAt(Carbon::now()->subDays(20))->create(); // Not old enough
$log4 = $logFactory->withCreatedAt(Carbon::now())->create(); // New
// Delete 1 log older than 30 days
$this->repository->purgeOldLogs(30, 1);
$allLogs = $this->repository->getLogs();
$logsInDB = [];
foreach ($allLogs as $log) {
$logsInDB[] = $log->getId();
}
sort($logsInDB);
verify([$log2->getId(), $log3->getId(), $log4->getId()])->equals($logsInDB);
}
}