get(EntityManagerInterface::class); foreach (self::$toDelete as [$className, $id]) { $object = $em->find($className, $id); $em->remove($object); } $em->flush(); self::$toDelete = []; } /** * @dataProvider generateDataMarkAsRead */ public function testMarkAsReadOrUnRead(int $notificationId) { $client = $this->getClientAuthenticated(); $client->request('POST', "/api/1.0/main/notification/{$notificationId}/mark/read"); $this->assertResponseIsSuccessful('test marking as read'); $em = self::getContainer()->get(EntityManagerInterface::class); /** @var Notification $notification */ $notification = $em->find(Notification::class, $notificationId); $user = self::getContainer()->get(UserRepository::class)->findOneBy(['username' => 'center a_social']); $this->assertTrue($notification->isReadBy($user)); $client->request('POST', "/api/1.0/main/notification/{$notificationId}/mark/unread"); $this->assertResponseIsSuccessful('test marking as unread'); $notification = $em->find(Notification::class, $notificationId); $user = $em->find(User::class, $user->getId()); $em->refresh($notification); $em->refresh($user); $this->assertFalse($notification->isReadBy($user)); } public static function generateDataMarkAsRead() { self::bootKernel(); $em = self::getContainer()->get(EntityManagerInterface::class); $userRepository = self::getContainer()->get(UserRepository::class); $userA = $userRepository->findOneBy(['username' => 'center a_social']); $userB = $userRepository->findOneBy(['username' => 'center b_social']); $notification = new Notification(); $notification ->setMessage('Test generated') ->setRelatedEntityClass(AccompanyingPeriod::class) ->setRelatedEntityId(0) ->setSender($userB) ->addAddressee($userA) ->setUpdatedAt(new \DateTimeImmutable()); $em->persist($notification); $em->refresh($notification); $em->flush(); self::$toDelete[] = [Notification::class, $notification->getId()]; self::ensureKernelShutdown(); yield [$notification->getId()]; } }