feat(core) : move notification into core and expose notifier contract

This commit is contained in:
Matthieu
2026-06-19 16:25:03 +02:00
parent 0b4874e94d
commit f1a9b42930
10 changed files with 91 additions and 38 deletions
@@ -7,7 +7,7 @@ namespace App\Tests\Functional\EventListener;
use App\Entity\Project;
use App\Entity\Task;
use App\Module\Core\Domain\Entity\User;
use App\Repository\NotificationRepository;
use App\Module\Core\Infrastructure\Doctrine\DoctrineNotificationRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@@ -19,7 +19,7 @@ use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
class TaskNotificationListenerTest extends KernelTestCase
{
private EntityManagerInterface $em;
private NotificationRepository $notifications;
private DoctrineNotificationRepository $notifications;
private TokenStorageInterface $tokenStorage;
private Project $project;
private User $actor;
@@ -31,7 +31,7 @@ class TaskNotificationListenerTest extends KernelTestCase
self::bootKernel();
$c = self::getContainer();
$this->em = $c->get(EntityManagerInterface::class);
$this->notifications = $c->get(NotificationRepository::class);
$this->notifications = $c->get(DoctrineNotificationRepository::class);
$this->tokenStorage = $c->get(TokenStorageInterface::class);
$project = $this->em->getRepository(Project::class)->findOneBy([]);
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Tests\Functional\Module\Core;
use App\Module\Core\Domain\Entity\User;
use App\Shared\Domain\Contract\NotifierInterface;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
*/
final class NotifierTest extends KernelTestCase
{
public function testNotifyPersistsANotificationForTheUser(): void
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$notifier = self::getContainer()->get(NotifierInterface::class);
$user = $em->getRepository(User::class)->findOneBy(['username' => 'alice']);
self::assertNotNull($user);
$title = 'Titre-'.uniqid('', true);
$notifier->notify($user, 'task_assigned', $title, 'Message');
$count = (int) $em->createQuery(
'SELECT COUNT(n.id) FROM App\Module\Core\Domain\Entity\Notification n WHERE n.user = :u AND n.title = :t'
)->setParameter('u', $user)->setParameter('t', $title)->getSingleScalarResult();
self::assertSame(1, $count);
}
}