mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-11-09 21:58:28 +00:00
82 lines
2.3 KiB
PHP
82 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\MainBundle\Tests\Notification\Email;
|
|
|
|
use Chill\MainBundle\Notification\Email\DailyNotificationDigestCronjob;
|
|
use Doctrine\DBAL\Connection;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Component\Clock\ClockInterface;
|
|
use Symfony\Component\Messenger\MessageBusInterface;
|
|
|
|
/**
|
|
* @internal
|
|
*
|
|
* @coversNothing
|
|
*/
|
|
class DailyNotificationDigestCronJobTest extends TestCase
|
|
{
|
|
private ClockInterface $clock;
|
|
private Connection $connection;
|
|
private MessageBusInterface $messageBus;
|
|
private LoggerInterface $logger;
|
|
private DailyNotificationDigestCronjob $cronjob;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->clock = $this->createMock(ClockInterface::class);
|
|
$this->connection = $this->createMock(Connection::class);
|
|
$this->messageBus = $this->createMock(MessageBusInterface::class);
|
|
$this->logger = $this->createMock(LoggerInterface::class);
|
|
|
|
$this->cronjob = new DailyNotificationDigestCronjob(
|
|
$this->clock,
|
|
$this->connection,
|
|
$this->messageBus,
|
|
$this->logger
|
|
);
|
|
}
|
|
|
|
public function testGetKey(): void
|
|
{
|
|
$this->assertEquals('daily-notification-digest', $this->cronjob->getKey());
|
|
}
|
|
|
|
/**
|
|
* @dataProvider canRunTimeDataProvider
|
|
*/
|
|
public function testCanRunWithNullCronJobExecution(int $hour, bool $expected): void
|
|
{
|
|
$now = new \DateTimeImmutable("2024-01-01 {$hour}:00:00");
|
|
$this->clock->expects($this->once())
|
|
->method('now')
|
|
->willReturn($now);
|
|
|
|
$result = $this->cronjob->canRun(null);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
}
|
|
|
|
public static function canRunTimeDataProvider(): array
|
|
{
|
|
return [
|
|
'hour 5 - should not run' => [5, false],
|
|
'hour 6 - should run' => [6, true],
|
|
'hour 7 - should run' => [7, true],
|
|
'hour 8 - should run' => [8, true],
|
|
'hour 9 - should not run' => [9, false],
|
|
'hour 10 - should not run' => [10, false],
|
|
'hour 23 - should not run' => [23, false],
|
|
];
|
|
}
|
|
}
|