mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-01-15 05:41:25 +00:00
Resolve "Notification: envoi à des groupes utilisateurs"
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?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],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user