mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-04-14 00:43:49 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
eb2dfc8591
|
|||
| b5a22508ff | |||
| f12bc2f35f | |||
|
9ba8ec8f41
|
|||
| 6a66f05451 | |||
| 1524ed8ce9 | |||
| 0aa0824831 | |||
| dd429ca02a | |||
| 81193376a4 | |||
| a921009eff |
5
.changes/v4.14.1.md
Normal file
5
.changes/v4.14.1.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
## v4.14.1 - 2026-03-16
|
||||||
|
### Security
|
||||||
|
* ([#506](https://gitlab.com/Chill-Projet/chill-bundles/-/issues/506)) ([!972](https://gitlab.com/Chill-Projet/chill-bundles/-/merge_requests/972)) Fix permission in list of activities in person context
|
||||||
|
### DX
|
||||||
|
* ([#504](https://gitlab.com/Chill-Projet/chill-bundles/-/issues/504)) ([!970](https://gitlab.com/Chill-Projet/chill-bundles/-/merge_requests/970)) Add seeds in DataFixtures and in some tests to avoid random test failures
|
||||||
3
.changes/v4.14.2.md
Normal file
3
.changes/v4.14.2.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
## v4.14.2 - 2026-03-18
|
||||||
|
### Fixed
|
||||||
|
* Fix link inside notification email
|
||||||
10
CHANGELOG.md
10
CHANGELOG.md
@@ -6,6 +6,16 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
|
|||||||
and is generated by [Changie](https://github.com/miniscruff/changie).
|
and is generated by [Changie](https://github.com/miniscruff/changie).
|
||||||
|
|
||||||
|
|
||||||
|
## v4.14.2 - 2026-03-18
|
||||||
|
### Fixed
|
||||||
|
* Fix link inside notification email
|
||||||
|
|
||||||
|
## v4.14.1 - 2026-03-16
|
||||||
|
### Security
|
||||||
|
* ([#506](https://gitlab.com/Chill-Projet/chill-bundles/-/issues/506)) ([!972](https://gitlab.com/Chill-Projet/chill-bundles/-/merge_requests/972)) Fix permission in list of activities in person context
|
||||||
|
### DX
|
||||||
|
* ([#504](https://gitlab.com/Chill-Projet/chill-bundles/-/issues/504)) ([!970](https://gitlab.com/Chill-Projet/chill-bundles/-/merge_requests/970)) Add seeds in DataFixtures and in some tests to avoid random test failures
|
||||||
|
|
||||||
## v4.14.0 - 2026-03-09
|
## v4.14.0 - 2026-03-09
|
||||||
### Feature
|
### Feature
|
||||||
* ([#486](https://gitlab.com/Chill-Projet/chill-bundles/-/issues/486)) ([!<no value>](https://gitlab.com/Chill-Projet/chill-bundles/-/merge_requests/<no value>)) Add filter and aggregator based on referrer's main center for exports of accompanying period
|
* ([#486](https://gitlab.com/Chill-Projet/chill-bundles/-/issues/486)) ([!<no value>](https://gitlab.com/Chill-Projet/chill-bundles/-/merge_requests/<no value>)) Add filter and aggregator based on referrer's main center for exports of accompanying period
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ when@dev: &dev
|
|||||||
- 'file'
|
- 'file'
|
||||||
- 'md5'
|
- 'md5'
|
||||||
- 'sha1'
|
- 'sha1'
|
||||||
|
seed: 1234567890
|
||||||
|
|
||||||
when@test: *dev
|
when@test: *dev
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
|
|
||||||
public function __construct(private readonly EntityManagerInterface $em)
|
public function __construct(private readonly EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
|
mt_srand(123456789);
|
||||||
$this->faker = FakerFactory::create('fr_FR');
|
$this->faker = FakerFactory::create('fr_FR');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
->findAll();
|
->findAll();
|
||||||
|
|
||||||
foreach ($persons as $person) {
|
foreach ($persons as $person) {
|
||||||
$activityNbr = random_int(0, 3);
|
$activityNbr = mt_rand(0, 3);
|
||||||
|
|
||||||
for ($i = 0; $i < $activityNbr; ++$i) {
|
for ($i = 0; $i < $activityNbr; ++$i) {
|
||||||
$activity = $this->newRandomActivity($person);
|
$activity = $this->newRandomActivity($person);
|
||||||
@@ -73,7 +74,7 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
|
|
||||||
// ->setAttendee($this->faker->boolean())
|
// ->setAttendee($this->faker->boolean())
|
||||||
|
|
||||||
for ($i = 0; random_int(0, 4) > $i; ++$i) {
|
for ($i = 0; mt_rand(0, 4) > $i; ++$i) {
|
||||||
$reason = $this->getRandomActivityReason();
|
$reason = $this->getRandomActivityReason();
|
||||||
|
|
||||||
if (null !== $reason) {
|
if (null !== $reason) {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInt
|
|||||||
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||||
use Doctrine\DBAL\Types\Types;
|
use Doctrine\DBAL\Types\Types;
|
||||||
use Doctrine\ORM\AbstractQuery;
|
use Doctrine\ORM\AbstractQuery;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
@@ -340,7 +341,7 @@ final readonly class ActivityACLAwareRepository implements ActivityACLAwareRepos
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($person->getAccompanyingPeriodParticipations() as $participation) {
|
foreach ($person->getAccompanyingPeriodParticipations() as $participation) {
|
||||||
if (!$this->security->isGranted(ActivityVoter::SEE, $participation->getAccompanyingPeriod())) {
|
if (!$this->security->isGranted(AccompanyingPeriodVoter::SEE, $participation->getAccompanyingPeriod())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ use Doctrine\Persistence\ObjectManager;
|
|||||||
|
|
||||||
class LoadAsideActivity extends Fixture implements DependentFixtureInterface
|
class LoadAsideActivity extends Fixture implements DependentFixtureInterface
|
||||||
{
|
{
|
||||||
public function __construct(private readonly UserRepository $userRepository) {}
|
public function __construct(private readonly UserRepository $userRepository)
|
||||||
|
{
|
||||||
|
mt_srand(123456789);
|
||||||
|
}
|
||||||
|
|
||||||
public function getDependencies(): array
|
public function getDependencies(): array
|
||||||
{
|
{
|
||||||
@@ -47,7 +50,7 @@ class LoadAsideActivity extends Fixture implements DependentFixtureInterface
|
|||||||
$this->getReference('aside_activity_category_0', AsideActivityCategory::class)
|
$this->getReference('aside_activity_category_0', AsideActivityCategory::class)
|
||||||
)
|
)
|
||||||
->setDate((new \DateTimeImmutable('today'))
|
->setDate((new \DateTimeImmutable('today'))
|
||||||
->sub(new \DateInterval('P'.\random_int(1, 100).'D')));
|
->sub(new \DateInterval('P'.\mt_rand(1, 100).'D')));
|
||||||
|
|
||||||
$manager->persist($activity);
|
$manager->persist($activity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
mt_srand(123456789);
|
||||||
$this->fakerFr = \Faker\Factory::create('fr_FR');
|
$this->fakerFr = \Faker\Factory::create('fr_FR');
|
||||||
$this->fakerEn = \Faker\Factory::create('en_EN');
|
$this->fakerEn = \Faker\Factory::create('en_EN');
|
||||||
$this->fakerNl = \Faker\Factory::create('nl_NL');
|
$this->fakerNl = \Faker\Factory::create('nl_NL');
|
||||||
@@ -104,7 +105,7 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
$manager->persist($parent);
|
$manager->persist($parent);
|
||||||
|
|
||||||
// Load children
|
// Load children
|
||||||
$expected_nb_children = random_int(10, 50);
|
$expected_nb_children = mt_rand(10, 50);
|
||||||
|
|
||||||
for ($i = 0; $i < $expected_nb_children; ++$i) {
|
for ($i = 0; $i < $expected_nb_children; ++$i) {
|
||||||
$companyName = $this->fakerFr->company;
|
$companyName = $this->fakerFr->company;
|
||||||
@@ -144,7 +145,7 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
$manager->persist($parent);
|
$manager->persist($parent);
|
||||||
|
|
||||||
// Load children
|
// Load children
|
||||||
$expected_nb_children = random_int(10, 50);
|
$expected_nb_children = mt_rand(10, 50);
|
||||||
|
|
||||||
for ($i = 0; $i < $expected_nb_children; ++$i) {
|
for ($i = 0; $i < $expected_nb_children; ++$i) {
|
||||||
$manager->persist($this->createChildOption($parent, [
|
$manager->persist($this->createChildOption($parent, [
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class LoadParticipation extends AbstractFixture implements OrderedFixtureInterfa
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
mt_srand(123456789);
|
||||||
$this->faker = \Faker\Factory::create('fr_FR');
|
$this->faker = \Faker\Factory::create('fr_FR');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ class LoadParticipation extends AbstractFixture implements OrderedFixtureInterfa
|
|||||||
for ($i = 0; $i < $expectedNumber; ++$i) {
|
for ($i = 0; $i < $expectedNumber; ++$i) {
|
||||||
$event = (new Event())
|
$event = (new Event())
|
||||||
->setDate($this->faker->dateTimeBetween('-2 years', '+6 months'))
|
->setDate($this->faker->dateTimeBetween('-2 years', '+6 months'))
|
||||||
->setName($this->faker->words(random_int(2, 4), true))
|
->setName($this->faker->words(mt_rand(2, 4), true))
|
||||||
->setType($this->getReference(LoadEventTypes::$refs[array_rand(LoadEventTypes::$refs)], EventType::class))
|
->setType($this->getReference(LoadEventTypes::$refs[array_rand(LoadEventTypes::$refs)], EventType::class))
|
||||||
->setCenter($center)
|
->setCenter($center)
|
||||||
->setCircle(
|
->setCircle(
|
||||||
@@ -78,7 +79,7 @@ class LoadParticipation extends AbstractFixture implements OrderedFixtureInterfa
|
|||||||
|
|
||||||
/** @var Person $person */
|
/** @var Person $person */
|
||||||
foreach ($people as $person) {
|
foreach ($people as $person) {
|
||||||
$nb = random_int(0, 3);
|
$nb = mt_rand(0, 3);
|
||||||
|
|
||||||
for ($i = 0; $i < $nb; ++$i) {
|
for ($i = 0; $i < $nb; ++$i) {
|
||||||
$event = $events[array_rand($events)];
|
$event = $events[array_rand($events)];
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class LoadAddressReferences extends AbstractFixture implements ContainerAwareInt
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
mt_srand(123456789);
|
||||||
$this->faker = \Faker\Factory::create('fr_FR');
|
$this->faker = \Faker\Factory::create('fr_FR');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +68,7 @@ class LoadAddressReferences extends AbstractFixture implements ContainerAwareInt
|
|||||||
|
|
||||||
$ar->setRefId($this->faker->numerify('ref-id-######'));
|
$ar->setRefId($this->faker->numerify('ref-id-######'));
|
||||||
$ar->setStreet($this->faker->streetName);
|
$ar->setStreet($this->faker->streetName);
|
||||||
$ar->setStreetNumber((string) random_int(0, 199));
|
$ar->setStreetNumber((string) mt_rand(0, 199));
|
||||||
$ar->setPoint($this->getRandomPoint());
|
$ar->setPoint($this->getRandomPoint());
|
||||||
$ar->setPostcode($this->getReference(
|
$ar->setPostcode($this->getReference(
|
||||||
LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)],
|
LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)],
|
||||||
@@ -88,8 +89,8 @@ class LoadAddressReferences extends AbstractFixture implements ContainerAwareInt
|
|||||||
{
|
{
|
||||||
$lonBrussels = 4.35243;
|
$lonBrussels = 4.35243;
|
||||||
$latBrussels = 50.84676;
|
$latBrussels = 50.84676;
|
||||||
$lon = $lonBrussels + 0.01 * random_int(-5, 5);
|
$lon = $lonBrussels + 0.01 * mt_rand(-5, 5);
|
||||||
$lat = $latBrussels + 0.01 * random_int(-5, 5);
|
$lat = $latBrussels + 0.01 * mt_rand(-5, 5);
|
||||||
|
|
||||||
return Point::fromLonLat($lon, $lat);
|
return Point::fromLonLat($lon, $lat);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,17 +215,21 @@ class Notification implements TrackUpdateInterface
|
|||||||
return $this->addressees;
|
return $this->addressees;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<User|UserGroup>
|
||||||
|
*/
|
||||||
public function getAllAddressees(): array
|
public function getAllAddressees(): array
|
||||||
{
|
{
|
||||||
$allUsers = [];
|
$allUsers = [];
|
||||||
|
|
||||||
foreach ($this->getAddressees() as $user) {
|
foreach ($this->getAddressees() as $user) {
|
||||||
$allUsers[$user->getId()] = $user;
|
$allUsers['u_'.$user->getId()] = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->getAddresseeUserGroups() as $userGroup) {
|
foreach ($this->getAddresseeUserGroups() as $userGroup) {
|
||||||
|
$allUsers['ug_'.$userGroup->getId()] = $userGroup;
|
||||||
foreach ($userGroup->getUsers() as $user) {
|
foreach ($userGroup->getUsers() as $user) {
|
||||||
$allUsers[$user->getId()] = $user;
|
$allUsers['u_'.$user->getId()] = $user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -658,6 +658,11 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isUserGroup(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private function getNotificationFlagData(string $flag): array
|
private function getNotificationFlagData(string $flag): array
|
||||||
{
|
{
|
||||||
return $this->notificationFlags[$flag] ?? [self::NOTIF_FLAG_IMMEDIATE_EMAIL];
|
return $this->notificationFlags[$flag] ?? [self::NOTIF_FLAG_IMMEDIATE_EMAIL];
|
||||||
|
|||||||
@@ -256,6 +256,21 @@ class UserGroup
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isUser(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a locale for the userGroup.
|
||||||
|
*
|
||||||
|
* Currently hardcoded, should be replaced by a property.
|
||||||
|
*/
|
||||||
|
public function getLocale(): string
|
||||||
|
{
|
||||||
|
return 'fr';
|
||||||
|
}
|
||||||
|
|
||||||
public function contains(User $user): bool
|
public function contains(User $user): bool
|
||||||
{
|
{
|
||||||
return $this->users->contains($user);
|
return $this->users->contains($user);
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ namespace Chill\MainBundle\Notification\Email\NotificationEmailHandlers;
|
|||||||
use Chill\MainBundle\Notification\Email\NotificationEmailMessages\SendImmediateNotificationEmailMessage;
|
use Chill\MainBundle\Notification\Email\NotificationEmailMessages\SendImmediateNotificationEmailMessage;
|
||||||
use Chill\MainBundle\Notification\Email\NotificationMailer;
|
use Chill\MainBundle\Notification\Email\NotificationMailer;
|
||||||
use Chill\MainBundle\Repository\NotificationRepository;
|
use Chill\MainBundle\Repository\NotificationRepository;
|
||||||
use Chill\MainBundle\Repository\UserRepository;
|
use Chill\MainBundle\Repository\UserGroupRepository;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||||
@@ -24,7 +25,8 @@ readonly class SendImmediateNotificationEmailHandler
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private NotificationRepository $notificationRepository,
|
private NotificationRepository $notificationRepository,
|
||||||
private UserRepository $userRepository,
|
private UserRepositoryInterface $userRepository,
|
||||||
|
private UserGroupRepository $userGroupRepository,
|
||||||
private NotificationMailer $notificationMailer,
|
private NotificationMailer $notificationMailer,
|
||||||
private LoggerInterface $logger,
|
private LoggerInterface $logger,
|
||||||
) {}
|
) {}
|
||||||
@@ -36,7 +38,13 @@ readonly class SendImmediateNotificationEmailHandler
|
|||||||
public function __invoke(SendImmediateNotificationEmailMessage $message): void
|
public function __invoke(SendImmediateNotificationEmailMessage $message): void
|
||||||
{
|
{
|
||||||
$notification = $this->notificationRepository->find($message->getNotificationId());
|
$notification = $this->notificationRepository->find($message->getNotificationId());
|
||||||
$addressee = $this->userRepository->find($message->getAddresseeId());
|
if (null !== $message->getUserId()) {
|
||||||
|
$addressee = $this->userRepository->find($message->getUserId());
|
||||||
|
} elseif (null !== $message->getUserGroupId()) {
|
||||||
|
$addressee = $this->userGroupRepository->find($message->getUserGroupId());
|
||||||
|
} else {
|
||||||
|
throw new \InvalidArgumentException('Addressee not found: nor an user nor a user group');
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $notification) {
|
if (null === $notification) {
|
||||||
$this->logger->error('[SendImmediateNotificationEmailHandler] Notification not found', [
|
$this->logger->error('[SendImmediateNotificationEmailHandler] Notification not found', [
|
||||||
@@ -48,10 +56,11 @@ readonly class SendImmediateNotificationEmailHandler
|
|||||||
|
|
||||||
if (null === $addressee) {
|
if (null === $addressee) {
|
||||||
$this->logger->error('[SendImmediateNotificationEmailHandler] Addressee not found', [
|
$this->logger->error('[SendImmediateNotificationEmailHandler] Addressee not found', [
|
||||||
'addressee_id' => $message->getAddresseeId(),
|
'user_id' => $message->getUserId(),
|
||||||
|
'user_group_id' => $message->getUserGroupId(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
throw new \InvalidArgumentException(sprintf('User with ID %s not found', $message->getAddresseeId()));
|
throw new \InvalidArgumentException(sprintf('User with ID %s or user group with id %s not found', $message->getUserId(), $message->getUserGroupId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -59,7 +68,8 @@ readonly class SendImmediateNotificationEmailHandler
|
|||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->error('[SendImmediateNotificationEmailHandler] Failed to send email', [
|
$this->logger->error('[SendImmediateNotificationEmailHandler] Failed to send email', [
|
||||||
'notification_id' => $message->getNotificationId(),
|
'notification_id' => $message->getNotificationId(),
|
||||||
'addressee_id' => $message->getAddresseeId(),
|
'user_id' => $message->getUserId(),
|
||||||
|
'user_group_id' => $message->getUserGroupId(),
|
||||||
'stacktrace' => $e->getTraceAsString(),
|
'stacktrace' => $e->getTraceAsString(),
|
||||||
]);
|
]);
|
||||||
throw $e;
|
throw $e;
|
||||||
|
|||||||
@@ -11,20 +11,45 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Notification\Email\NotificationEmailMessages;
|
namespace Chill\MainBundle\Notification\Email\NotificationEmailMessages;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Notification;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Entity\UserGroup;
|
||||||
|
|
||||||
readonly class SendImmediateNotificationEmailMessage
|
readonly class SendImmediateNotificationEmailMessage
|
||||||
{
|
{
|
||||||
|
private int $notificationId;
|
||||||
|
|
||||||
|
private ?int $userId;
|
||||||
|
|
||||||
|
private ?int $userGroupId;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private int $notificationId,
|
Notification $notification,
|
||||||
private int $addresseeId,
|
UserGroup|User $addressee,
|
||||||
) {}
|
) {
|
||||||
|
$this->notificationId = $notification->getId();
|
||||||
|
|
||||||
|
if ($addressee instanceof User) {
|
||||||
|
$this->userId = $addressee->getId();
|
||||||
|
$this->userGroupId = null;
|
||||||
|
} else {
|
||||||
|
$this->userGroupId = $addressee->getId();
|
||||||
|
$this->userId = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getNotificationId(): int
|
public function getNotificationId(): int
|
||||||
{
|
{
|
||||||
return $this->notificationId;
|
return $this->notificationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAddresseeId(): int
|
public function getUserId(): ?int
|
||||||
{
|
{
|
||||||
return $this->addresseeId;
|
return $this->userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserGroupId(): ?int
|
||||||
|
{
|
||||||
|
return $this->userGroupId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Chill\MainBundle\Notification\Email;
|
|||||||
use Chill\MainBundle\Entity\Notification;
|
use Chill\MainBundle\Entity\Notification;
|
||||||
use Chill\MainBundle\Entity\NotificationComment;
|
use Chill\MainBundle\Entity\NotificationComment;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Entity\UserGroup;
|
||||||
use Chill\MainBundle\Notification\Email\NotificationEmailMessages\SendImmediateNotificationEmailMessage;
|
use Chill\MainBundle\Notification\Email\NotificationEmailMessages\SendImmediateNotificationEmailMessage;
|
||||||
use Doctrine\ORM\Event\PostPersistEventArgs;
|
use Doctrine\ORM\Event\PostPersistEventArgs;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@@ -26,13 +27,13 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||||||
|
|
||||||
// use Symfony\Component\Translation\LocaleSwitcher;
|
// use Symfony\Component\Translation\LocaleSwitcher;
|
||||||
|
|
||||||
readonly class NotificationMailer
|
class NotificationMailer
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private MailerInterface $mailer,
|
private readonly MailerInterface $mailer,
|
||||||
private LoggerInterface $logger,
|
private readonly LoggerInterface $logger,
|
||||||
private MessageBusInterface $messageBus,
|
private readonly MessageBusInterface $messageBus,
|
||||||
private TranslatorInterface $translator,
|
private readonly TranslatorInterface $translator,
|
||||||
// private LocaleSwitcher $localeSwitcher,
|
// private LocaleSwitcher $localeSwitcher,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -100,25 +101,27 @@ readonly class NotificationMailer
|
|||||||
if (null === $addressee->getEmail()) {
|
if (null === $addressee->getEmail()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ($notification->getSender() === $addressee) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$this->processNotificationForAddressee($notification, $addressee);
|
$this->processNotificationForAddressee($notification, $addressee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processNotificationForAddressee(Notification $notification, User $addressee): void
|
private function processNotificationForAddressee(Notification $notification, User|UserGroup $addressee): void
|
||||||
{
|
{
|
||||||
$notificationType = $notification->getType();
|
$notificationType = $notification->getType();
|
||||||
|
|
||||||
if ($addressee->isNotificationSendImmediately($notificationType)) {
|
if ($addressee instanceof UserGroup || $addressee->isNotificationSendImmediately($notificationType)) {
|
||||||
$this->scheduleImmediateEmail($notification, $addressee);
|
$this->scheduleImmediateEmail($notification, $addressee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function scheduleImmediateEmail(Notification $notification, User $addressee): void
|
private function scheduleImmediateEmail(Notification $notification, User|UserGroup $addressee): void
|
||||||
{
|
{
|
||||||
$message = new SendImmediateNotificationEmailMessage(
|
$message = new SendImmediateNotificationEmailMessage(
|
||||||
$notification->getId(),
|
$notification,
|
||||||
$addressee->getId()
|
$addressee,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->messageBus->dispatch($message);
|
$this->messageBus->dispatch($message);
|
||||||
@@ -130,13 +133,17 @@ readonly class NotificationMailer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sends the email but is now called by the immediate notification email message handler.
|
* Send an email about a Notification.
|
||||||
|
*
|
||||||
|
* It is called by immediate notification email message handler:
|
||||||
|
*
|
||||||
|
* @see{\Chill\MainBundle\Notification\Email\NotificationEmailHandlers\SendImmediateNotificationEmailHandler}
|
||||||
*
|
*
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function sendEmailToAddressee(Notification $notification, User $addressee): void
|
public function sendEmailToAddressee(Notification $notification, User|UserGroup $addressee): void
|
||||||
{
|
{
|
||||||
if (null === $addressee->getEmail()) {
|
if (null === $addressee->getEmail() || '' === $addressee->getEmail()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use Doctrine\ORM\Query;
|
|||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Doctrine\Persistence\ObjectRepository;
|
use Doctrine\Persistence\ObjectRepository;
|
||||||
|
|
||||||
final class NotificationRepository implements ObjectRepository
|
class NotificationRepository implements ObjectRepository
|
||||||
{
|
{
|
||||||
private ?Statement $notificationByRelatedEntityAndUserAssociatedStatement = null;
|
private ?Statement $notificationByRelatedEntityAndUserAssociatedStatement = null;
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Symfony\Contracts\Translation\LocaleAwareInterface;
|
use Symfony\Contracts\Translation\LocaleAwareInterface;
|
||||||
|
|
||||||
final class UserGroupRepository implements UserGroupRepositoryInterface, LocaleAwareInterface
|
class UserGroupRepository implements UserGroupRepositoryInterface, LocaleAwareInterface
|
||||||
{
|
{
|
||||||
private readonly EntityRepository $repository;
|
private readonly EntityRepository $repository;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
{% apply markdown_to_html %}
|
{% apply markdown_to_html %}
|
||||||
|
{% if dest.isUser %}
|
||||||
{{ dest.label }},
|
{{ dest.label }},
|
||||||
|
{% else %}
|
||||||
|
{{ dest.label|localize_translatable_string }},
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{{ notification.sender.label }} a créé une notification pour vous:
|
{{ notification.sender.label }} a créé une notification pour vous:
|
||||||
|
|
||||||
@@ -9,7 +13,12 @@
|
|||||||
> {{ line }}
|
> {{ line }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if dest.isUser %}
|
||||||
[Vous pouvez visualiser la notification et y répondre ici.]({{ absolute_url(path('chill_main_notification_show', {'_locale': dest.locale, 'id': notification.id }, false)) }})
|
[Vous pouvez visualiser la notification et y répondre ici.]({{ absolute_url(path('chill_main_notification_show', {'_locale': dest.locale, 'id': notification.id }, false)) }})
|
||||||
|
{% else %}
|
||||||
|
[Vous pouvez visualiser la notification et y répondre ici.]({{ absolute_url(path('chill_main_notification_grant_access_by_access_key', {'_locale': dest.locale, 'id': notification.id, 'accessKey': notification.accessKey }, false)) }})
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
|
{% if dest.isUser %}
|
||||||
{{ dest.label }},
|
{{ dest.label }},
|
||||||
|
{% else %}
|
||||||
|
{{ dest.label|localize_translatable_string }},
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{{ notification.sender.label }} a créé une notification pour vous:
|
{{ notification.sender.label }} a créé une notification pour vous:
|
||||||
|
|
||||||
@@ -8,7 +12,11 @@ Titre de la notification: {{ notification.title }}
|
|||||||
> {{ line|raw }}
|
> {{ line|raw }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
Vous pouvez visualiser la notification et y répondre ici: {{ absolute_url(path('chill_main_notification_show', {'_locale': dest.locale, 'id': notification.id }, false)) }}.
|
{% if dest.isUser %}
|
||||||
|
[Vous pouvez visualiser la notification et y répondre ici.]({{ absolute_url(path('chill_main_notification_show', {'_locale': dest.locale, 'id': notification.id }, false)) }})
|
||||||
|
{% else %}
|
||||||
|
[Vous pouvez visualiser la notification et y répondre ici.]({{ absolute_url(path('chill_main_notification_grant_access_by_access_key', {'_locale': dest.locale, 'id': notification.id, 'accessKey': notification.accessKey }, false)) }})
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
--
|
--
|
||||||
Le logiciel Chill
|
Le logiciel Chill
|
||||||
|
|||||||
@@ -0,0 +1,187 @@
|
|||||||
|
<?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\NotificationEmailHandler;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Notification;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Entity\UserGroup;
|
||||||
|
use Chill\MainBundle\Notification\Email\NotificationEmailHandlers\SendImmediateNotificationEmailHandler;
|
||||||
|
use Chill\MainBundle\Notification\Email\NotificationEmailMessages\SendImmediateNotificationEmailMessage;
|
||||||
|
use Chill\MainBundle\Notification\Email\NotificationMailer;
|
||||||
|
use Chill\MainBundle\Repository\NotificationRepository;
|
||||||
|
use Chill\MainBundle\Repository\UserGroupRepository;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
class SendImmediateNotificationEmailHandlerTest extends TestCase
|
||||||
|
{
|
||||||
|
use ProphecyTrait;
|
||||||
|
|
||||||
|
private $notificationRepository;
|
||||||
|
private $userRepository;
|
||||||
|
private $userGroupRepository;
|
||||||
|
private $notificationMailer;
|
||||||
|
private SendImmediateNotificationEmailHandler $handler;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$this->notificationRepository = $this->prophesize(NotificationRepository::class);
|
||||||
|
$this->userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
$this->userGroupRepository = $this->prophesize(UserGroupRepository::class);
|
||||||
|
$this->notificationMailer = $this->prophesize(NotificationMailer::class);
|
||||||
|
|
||||||
|
$this->handler = new SendImmediateNotificationEmailHandler(
|
||||||
|
$this->notificationRepository->reveal(),
|
||||||
|
$this->userRepository->reveal(),
|
||||||
|
$this->userGroupRepository->reveal(),
|
||||||
|
$this->notificationMailer->reveal(),
|
||||||
|
new NullLogger()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvokeWithUserAddressee(): void
|
||||||
|
{
|
||||||
|
$notificationId = 123;
|
||||||
|
$userId = 456;
|
||||||
|
|
||||||
|
$notification = $this->prophesize(Notification::class);
|
||||||
|
$notification->getId()->willReturn($notificationId);
|
||||||
|
$user = $this->prophesize(User::class);
|
||||||
|
$user->getId()->willReturn($userId);
|
||||||
|
|
||||||
|
$message = new SendImmediateNotificationEmailMessage($notification->reveal(), $user->reveal());
|
||||||
|
|
||||||
|
$this->notificationRepository->find($notificationId)->willReturn($notification->reveal());
|
||||||
|
$this->userRepository->find($userId)->willReturn($user->reveal());
|
||||||
|
|
||||||
|
$this->notificationMailer->sendEmailToAddressee($notification->reveal(), $user->reveal())
|
||||||
|
->shouldBeCalledOnce();
|
||||||
|
|
||||||
|
($this->handler)($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvokeWithUserGroupAddressee(): void
|
||||||
|
{
|
||||||
|
$notificationId = 123;
|
||||||
|
$userGroupId = 789;
|
||||||
|
|
||||||
|
$notification = $this->prophesize(Notification::class);
|
||||||
|
$notification->getId()->willReturn($notificationId);
|
||||||
|
$userGroup = $this->prophesize(UserGroup::class);
|
||||||
|
$userGroup->getId()->willReturn($userGroupId);
|
||||||
|
|
||||||
|
$message = new SendImmediateNotificationEmailMessage($notification->reveal(), $userGroup->reveal());
|
||||||
|
|
||||||
|
$this->notificationRepository->find($notificationId)->willReturn($notification->reveal());
|
||||||
|
$this->userGroupRepository->find($userGroupId)->willReturn($userGroup->reveal());
|
||||||
|
|
||||||
|
$this->notificationMailer->sendEmailToAddressee($notification->reveal(), $userGroup->reveal())
|
||||||
|
->shouldBeCalledOnce();
|
||||||
|
|
||||||
|
($this->handler)($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvokeThrowsExceptionWhenNotificationNotFound(): void
|
||||||
|
{
|
||||||
|
$notificationId = 123;
|
||||||
|
$userId = 456;
|
||||||
|
|
||||||
|
$notification = $this->prophesize(Notification::class);
|
||||||
|
$notification->getId()->willReturn($notificationId);
|
||||||
|
$user = $this->prophesize(User::class);
|
||||||
|
$user->getId()->willReturn($userId);
|
||||||
|
|
||||||
|
$message = new SendImmediateNotificationEmailMessage($notification->reveal(), $user->reveal());
|
||||||
|
|
||||||
|
$this->notificationRepository->find($notificationId)->willReturn(null);
|
||||||
|
$this->userRepository->find($userId)->willReturn($user->reveal());
|
||||||
|
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage(sprintf('Notification with ID %s not found', $notificationId));
|
||||||
|
|
||||||
|
($this->handler)($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvokeThrowsExceptionWhenUserNotFound(): void
|
||||||
|
{
|
||||||
|
$notificationId = 123;
|
||||||
|
$userId = 456;
|
||||||
|
|
||||||
|
$notification = $this->prophesize(Notification::class);
|
||||||
|
$notification->getId()->willReturn($notificationId);
|
||||||
|
$user = $this->prophesize(User::class);
|
||||||
|
$user->getId()->willReturn($userId);
|
||||||
|
|
||||||
|
$message = new SendImmediateNotificationEmailMessage($notification->reveal(), $user->reveal());
|
||||||
|
|
||||||
|
$this->notificationRepository->find($notificationId)->willReturn($notification->reveal());
|
||||||
|
$this->userRepository->find($userId)->willReturn(null);
|
||||||
|
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage(sprintf('User with ID %s or user group with id %s not found', $userId, ''));
|
||||||
|
|
||||||
|
($this->handler)($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvokeThrowsExceptionWhenUserGroupNotFound(): void
|
||||||
|
{
|
||||||
|
$notificationId = 123;
|
||||||
|
$userGroupId = 789;
|
||||||
|
|
||||||
|
$notification = $this->prophesize(Notification::class);
|
||||||
|
$notification->getId()->willReturn($notificationId);
|
||||||
|
$userGroup = $this->prophesize(UserGroup::class);
|
||||||
|
$userGroup->getId()->willReturn($userGroupId);
|
||||||
|
|
||||||
|
$message = new SendImmediateNotificationEmailMessage($notification->reveal(), $userGroup->reveal());
|
||||||
|
|
||||||
|
$this->notificationRepository->find($notificationId)->willReturn($notification->reveal());
|
||||||
|
$this->userGroupRepository->find($userGroupId)->willReturn(null);
|
||||||
|
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage(sprintf('User with ID %s or user group with id %s not found', '', $userGroupId));
|
||||||
|
|
||||||
|
($this->handler)($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvokeRethrowsExceptionWhenMailerFails(): void
|
||||||
|
{
|
||||||
|
$notificationId = 123;
|
||||||
|
$userId = 456;
|
||||||
|
|
||||||
|
$notification = $this->prophesize(Notification::class);
|
||||||
|
$notification->getId()->willReturn($notificationId);
|
||||||
|
$user = $this->prophesize(User::class);
|
||||||
|
$user->getId()->willReturn($userId);
|
||||||
|
|
||||||
|
$message = new SendImmediateNotificationEmailMessage($notification->reveal(), $user->reveal());
|
||||||
|
|
||||||
|
$this->notificationRepository->find($notificationId)->willReturn($notification->reveal());
|
||||||
|
$this->userRepository->find($userId)->willReturn($user->reveal());
|
||||||
|
|
||||||
|
$exception = new \Exception('Mailer error');
|
||||||
|
$this->notificationMailer->sendEmailToAddressee($notification->reveal(), $user->reveal())
|
||||||
|
->willThrow($exception);
|
||||||
|
|
||||||
|
$this->expectException(\Exception::class);
|
||||||
|
$this->expectExceptionMessage('Mailer error');
|
||||||
|
|
||||||
|
($this->handler)($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?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\Entity\Notification;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Entity\UserGroup;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
class NotificationMailTwigContentTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
private Environment $twig;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
$this->twig = $this->getContainer()->get('twig');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideContent
|
||||||
|
*/
|
||||||
|
public function testContent(string $template, array $args): void
|
||||||
|
{
|
||||||
|
$actual = $this->twig->render($template, $args);
|
||||||
|
|
||||||
|
self::assertIsString($actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function provideContent(): iterable
|
||||||
|
{
|
||||||
|
$notification = new Notification();
|
||||||
|
$notification->setMessage('test message');
|
||||||
|
$notification->setSender(new User());
|
||||||
|
|
||||||
|
$class = new \ReflectionClass($notification);
|
||||||
|
$method = $class->getProperty('id');
|
||||||
|
$method->setValue($notification, 1);
|
||||||
|
|
||||||
|
$txt = '@ChillMain/Notification/email_non_system_notification_content.txt.twig';
|
||||||
|
$md = '@ChillMain/Notification/email_non_system_notification_content.md.twig';
|
||||||
|
|
||||||
|
$user = new User();
|
||||||
|
$user->setLocale('fr');
|
||||||
|
$user->setLabel('test');
|
||||||
|
|
||||||
|
$userGroup = new UserGroup();
|
||||||
|
$userGroup->setLabel(['fr' => 'test user group']);
|
||||||
|
|
||||||
|
foreach ([$md, $txt] as $template) {
|
||||||
|
yield 'test with a user for '.$template => [$template, ['notification' => $notification, 'dest' => $user]];
|
||||||
|
yield 'test with a group for '.$template => [$template, ['notification' => $notification, 'dest' => $userGroup]];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,11 +9,12 @@ declare(strict_types=1);
|
|||||||
* the LICENSE file that was distributed with this source code.
|
* the LICENSE file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Notification\Email;
|
namespace Chill\MainBundle\Tests\Notification\Email;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Notification;
|
use Chill\MainBundle\Entity\Notification;
|
||||||
use Chill\MainBundle\Entity\NotificationComment;
|
use Chill\MainBundle\Entity\NotificationComment;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Entity\UserGroup;
|
||||||
use Chill\MainBundle\Notification\Email\NotificationMailer;
|
use Chill\MainBundle\Notification\Email\NotificationMailer;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Event\PostPersistEventArgs;
|
use Doctrine\ORM\Event\PostPersistEventArgs;
|
||||||
@@ -64,13 +65,22 @@ class NotificationMailerTest extends TestCase
|
|||||||
// a mail only to user1 and user3 should have been sent
|
// a mail only to user1 and user3 should have been sent
|
||||||
$mailer->send(Argument::that(function (Email $email) {
|
$mailer->send(Argument::that(function (Email $email) {
|
||||||
foreach ($email->getTo() as $address) {
|
foreach ($email->getTo() as $address) {
|
||||||
if ('user1@foo.com' === $address->getAddress() || 'user3@foo.com' === $address->getAddress()) {
|
if ('user1@foo.com' === $address->getAddress()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}))->shouldBeCalledTimes(2);
|
}))->shouldBeCalledTimes(1);
|
||||||
|
$mailer->send(Argument::that(function (Email $email) {
|
||||||
|
foreach ($email->getTo() as $address) {
|
||||||
|
if ('user3@foo.com' === $address->getAddress()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}))->shouldBeCalledTimes(1);
|
||||||
|
|
||||||
$objectManager = $this->prophesize(EntityManagerInterface::class);
|
$objectManager = $this->prophesize(EntityManagerInterface::class);
|
||||||
|
|
||||||
@@ -121,7 +131,83 @@ class NotificationMailerTest extends TestCase
|
|||||||
* @throws \ReflectionException
|
* @throws \ReflectionException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testProcessNotificationForAddresseeWithImmediateEmailPreference(): void
|
public function testPostPersistNotificationToGroup(): void
|
||||||
|
{
|
||||||
|
// Create a real notification entity
|
||||||
|
$notification = new Notification();
|
||||||
|
$notification->setType('test_notification_type');
|
||||||
|
|
||||||
|
// Use reflection to set the ID since it's normally generated by the database
|
||||||
|
$reflectionNotification = new \ReflectionClass(Notification::class);
|
||||||
|
$idProperty = $reflectionNotification->getProperty('id');
|
||||||
|
$idProperty->setValue($notification, 123);
|
||||||
|
|
||||||
|
// Create a real user entity
|
||||||
|
$user = new User();
|
||||||
|
$user->setEmail('user@example.com');
|
||||||
|
$userGroup = new UserGroup();
|
||||||
|
$userGroup->addUser($user);
|
||||||
|
$notification->addAddressee($userGroup);
|
||||||
|
|
||||||
|
// Use reflection to set the ID since it's normally generated by the database
|
||||||
|
$reflectionUser = new \ReflectionClass($user);
|
||||||
|
$idProperty = $reflectionUser->getProperty('id');
|
||||||
|
$idProperty->setValue($user, 456);
|
||||||
|
|
||||||
|
$reflectionUser = new \ReflectionClass($userGroup);
|
||||||
|
$idProperty = $reflectionUser->getProperty('id');
|
||||||
|
$idProperty->setValue($userGroup, 789);
|
||||||
|
|
||||||
|
// Set notification flags for the user
|
||||||
|
$user->setNotificationImmediately('test_notification_type', true);
|
||||||
|
|
||||||
|
$messageBus = $this->prophesize(MessageBusInterface::class);
|
||||||
|
$messageBus->dispatch(Argument::that(fn (SendImmediateNotificationEmailMessage $message) => 123 === $message->getNotificationId() && 456 === $message->getUserId() && null === $message->getUserGroupId()))->willReturn(new Envelope(new \stdClass()))->shouldBeCalled();
|
||||||
|
|
||||||
|
$messageBus->dispatch(Argument::that(fn (SendImmediateNotificationEmailMessage $message) => 123 === $message->getNotificationId() && null === $message->getUserId() && 789 === $message->getUserGroupId()))->willReturn(new Envelope(new \stdClass()))->shouldBeCalled();
|
||||||
|
|
||||||
|
$notificationMailer = $this->buildNotificationMailer(null, $messageBus->reveal());
|
||||||
|
|
||||||
|
$notificationMailer->postPersistNotification($notification, new PostPersistEventArgs($notification, $this->prophesize(EntityManagerInterface::class)->reveal()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \ReflectionException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testPostPersistNotificationWithImmediateEmailPreference(): void
|
||||||
|
{
|
||||||
|
// Create a real notification entity
|
||||||
|
$notification = new Notification();
|
||||||
|
$notification->setType('test_notification_type');
|
||||||
|
|
||||||
|
// Use reflection to set the ID since it's normally generated by the database
|
||||||
|
$reflectionNotification = new \ReflectionClass(Notification::class);
|
||||||
|
$idProperty = $reflectionNotification->getProperty('id');
|
||||||
|
$idProperty->setValue($notification, 123);
|
||||||
|
|
||||||
|
// Create a real user entity
|
||||||
|
$user = new User();
|
||||||
|
$user->setEmail('user@example.com');
|
||||||
|
$notification->addAddressee($user);
|
||||||
|
|
||||||
|
// Use reflection to set the ID since it's normally generated by the database
|
||||||
|
$reflectionUser = new \ReflectionClass(User::class);
|
||||||
|
$idProperty = $reflectionUser->getProperty('id');
|
||||||
|
$idProperty->setValue($user, 456);
|
||||||
|
|
||||||
|
// Set notification flags for the user
|
||||||
|
$user->setNotificationImmediately('test_notification_type', true);
|
||||||
|
|
||||||
|
$messageBus = $this->prophesize(MessageBusInterface::class);
|
||||||
|
$messageBus->dispatch(Argument::that(fn (SendImmediateNotificationEmailMessage $message) => 123 === $message->getNotificationId() && 456 === $message->getUserId() && null === $message->getUserGroupId()))->willReturn(new Envelope(new \stdClass()))->shouldBeCalled();
|
||||||
|
|
||||||
|
$notificationMailer = $this->buildNotificationMailer(null, $messageBus->reveal());
|
||||||
|
|
||||||
|
$notificationMailer->postPersistNotification($notification, new PostPersistEventArgs($notification, $this->prophesize(EntityManagerInterface::class)->reveal()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostPersistNotificationWithDailyDigestPreference(): void
|
||||||
{
|
{
|
||||||
// Create a real notification entity
|
// Create a real notification entity
|
||||||
$notification = new Notification();
|
$notification = new Notification();
|
||||||
@@ -136,6 +222,11 @@ class NotificationMailerTest extends TestCase
|
|||||||
// Create a real user entity
|
// Create a real user entity
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$user->setEmail('user@example.com');
|
$user->setEmail('user@example.com');
|
||||||
|
// Set notification flags for the user
|
||||||
|
$user->setNotificationImmediately('test_notification_type', false);
|
||||||
|
$user->setNotificationDailyDigest('test_notification_type', true);
|
||||||
|
|
||||||
|
$notification->addAddressee($user);
|
||||||
|
|
||||||
// Use reflection to set the ID since it's normally generated by the database
|
// Use reflection to set the ID since it's normally generated by the database
|
||||||
$reflectionUser = new \ReflectionClass(User::class);
|
$reflectionUser = new \ReflectionClass(User::class);
|
||||||
@@ -143,23 +234,15 @@ class NotificationMailerTest extends TestCase
|
|||||||
$idProperty->setAccessible(true);
|
$idProperty->setAccessible(true);
|
||||||
$idProperty->setValue($user, 456);
|
$idProperty->setValue($user, 456);
|
||||||
|
|
||||||
// Set notification flags for the user
|
$messageBus = $this->prophesize(MessageBusInterface::class);
|
||||||
$user->setNotificationImmediately('test_notification_type', true);
|
$messageBus->dispatch(Argument::that(fn (SendImmediateNotificationEmailMessage $message) => 123 === $message->getNotificationId() && 456 === $message->getUserId() && null === $message->getUserGroupId()))->willReturn(new Envelope(new \stdClass()))->shouldNotBeCalled();
|
||||||
|
|
||||||
$messageBus = $this->createMock(MessageBusInterface::class);
|
$notificationMailer = $this->buildNotificationMailer(
|
||||||
$messageBus->expects($this->once())
|
null,
|
||||||
->method('dispatch')
|
$messageBus->reveal()
|
||||||
->with($this->callback(fn (SendImmediateNotificationEmailMessage $message) => 123 === $message->getNotificationId()
|
);
|
||||||
&& 456 === $message->getAddresseeId()))
|
|
||||||
->willReturn(new Envelope(new \stdClass()));
|
|
||||||
|
|
||||||
$mailer = $this->buildNotificationMailer(null, $messageBus);
|
$notificationMailer->postPersistNotification($notification, new PostPersistEventArgs($notification, $this->prophesize(EntityManagerInterface::class)->reveal()));
|
||||||
|
|
||||||
// Call the method that processes notifications
|
|
||||||
$reflection = new \ReflectionClass(NotificationMailer::class);
|
|
||||||
$method = $reflection->getMethod('processNotificationForAddressee');
|
|
||||||
$method->setAccessible(true);
|
|
||||||
$method->invoke($mailer, $notification, $user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendDailyDigest(): void
|
public function testSendDailyDigest(): void
|
||||||
@@ -250,6 +333,108 @@ class NotificationMailerTest extends TestCase
|
|||||||
$notificationMailer->sendDailyDigest($user, $notifications);
|
$notificationMailer->sendDailyDigest($user, $notifications);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSendEmailToAddresseeUser(): void
|
||||||
|
{
|
||||||
|
$user = new User();
|
||||||
|
$user->setEmail('user@example.com');
|
||||||
|
$notification = new Notification();
|
||||||
|
$notification->setSender(new User());
|
||||||
|
$notification->setTitle('Notification 1');
|
||||||
|
$notification->setType('test_notification_type');
|
||||||
|
$notification->addAddressee($user);
|
||||||
|
|
||||||
|
$mailer = $this->prophesize(MailerInterface::class);
|
||||||
|
$mailer->send(Argument::that(function ($arg) {
|
||||||
|
if (!$arg instanceof Email) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('Notification 1' !== $arg->getSubject()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($arg->getTo() as $address) {
|
||||||
|
if ('user@example.com' === $address->getAddress()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}))->shouldBeCalledOnce();
|
||||||
|
|
||||||
|
$notificationMailer = $this->buildNotificationMailer($mailer->reveal());
|
||||||
|
|
||||||
|
$notificationMailer->sendEmailToAddressee($notification, $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendEmailToAddresseeGroup(): void
|
||||||
|
{
|
||||||
|
$userGroup = new UserGroup();
|
||||||
|
$userGroup->setEmail('user@example.com');
|
||||||
|
$notification = new Notification();
|
||||||
|
$notification->setSender(new User());
|
||||||
|
$notification->setTitle('Notification 1');
|
||||||
|
$notification->setType('test_notification_type');
|
||||||
|
$notification->addAddressee($userGroup);
|
||||||
|
|
||||||
|
$mailer = $this->prophesize(MailerInterface::class);
|
||||||
|
$mailer->send(Argument::that(function ($arg) {
|
||||||
|
if (!$arg instanceof Email) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('Notification 1' !== $arg->getSubject()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($arg->getTo() as $address) {
|
||||||
|
if ('user@example.com' === $address->getAddress()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}))->shouldBeCalledOnce();
|
||||||
|
|
||||||
|
$notificationMailer = $this->buildNotificationMailer($mailer->reveal());
|
||||||
|
|
||||||
|
$notificationMailer->sendEmailToAddressee($notification, $userGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendEmailToAddresseeGroupWithNoAddress(): void
|
||||||
|
{
|
||||||
|
$userGroup = new UserGroup();
|
||||||
|
$notification = new Notification();
|
||||||
|
$notification->setSender(new User());
|
||||||
|
$notification->setTitle('Notification 1');
|
||||||
|
$notification->setType('test_notification_type');
|
||||||
|
$notification->addAddressee($userGroup);
|
||||||
|
|
||||||
|
$mailer = $this->prophesize(MailerInterface::class);
|
||||||
|
$mailer->send(Argument::any())->shouldNotBeCalled();
|
||||||
|
|
||||||
|
$notificationMailer = $this->buildNotificationMailer($mailer->reveal());
|
||||||
|
|
||||||
|
$notificationMailer->sendEmailToAddressee($notification, $userGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendEmailToAddresseeUserWithNoAddress(): void
|
||||||
|
{
|
||||||
|
$user = new User();
|
||||||
|
$notification = new Notification();
|
||||||
|
$notification->setSender(new User());
|
||||||
|
$notification->setTitle('Notification 1');
|
||||||
|
$notification->setType('test_notification_type');
|
||||||
|
$notification->addAddressee($user);
|
||||||
|
|
||||||
|
$mailer = $this->prophesize(MailerInterface::class);
|
||||||
|
$mailer->send(Argument::any())->shouldNotBeCalled();
|
||||||
|
|
||||||
|
$notificationMailer = $this->buildNotificationMailer($mailer->reveal());
|
||||||
|
|
||||||
|
$notificationMailer->sendEmailToAddressee($notification, $user);
|
||||||
|
}
|
||||||
|
|
||||||
private function buildNotificationMailer(
|
private function buildNotificationMailer(
|
||||||
?MailerInterface $mailer = null,
|
?MailerInterface $mailer = null,
|
||||||
?MessageBusInterface $messageBus = null,
|
?MessageBusInterface $messageBus = null,
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ trait RandomPersonHelperTrait
|
|||||||
return $qb
|
return $qb
|
||||||
->select('p')
|
->select('p')
|
||||||
->setMaxResults(1)
|
->setMaxResults(1)
|
||||||
->setFirstResult(\random_int(0, $this->nbOfPersons))
|
->setFirstResult(\mt_rand(0, $this->nbOfPersons))
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getSingleResult();
|
->getSingleResult();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ class LoadCustomFields extends AbstractFixture implements OrderedFixtureInterfac
|
|||||||
private readonly EntityManagerInterface $entityManager,
|
private readonly EntityManagerInterface $entityManager,
|
||||||
private readonly CustomFieldChoice $customFieldChoice,
|
private readonly CustomFieldChoice $customFieldChoice,
|
||||||
private readonly CustomFieldText $customFieldText,
|
private readonly CustomFieldText $customFieldText,
|
||||||
) {}
|
) {
|
||||||
|
mt_srand(123456789);
|
||||||
|
}
|
||||||
|
|
||||||
// put your code here
|
// put your code here
|
||||||
public function getOrder(): int
|
public function getOrder(): int
|
||||||
@@ -78,12 +80,12 @@ class LoadCustomFields extends AbstractFixture implements OrderedFixtureInterfac
|
|||||||
// select a set of people and add data
|
// select a set of people and add data
|
||||||
foreach ($personIds as $id) {
|
foreach ($personIds as $id) {
|
||||||
// add info on 1 person on 2
|
// add info on 1 person on 2
|
||||||
if (1 === random_int(0, 1)) {
|
if (1 === mt_rand(0, 1)) {
|
||||||
/** @var Person $person */
|
/** @var Person $person */
|
||||||
$person = $manager->getRepository(Person::class)->find($id);
|
$person = $manager->getRepository(Person::class)->find($id);
|
||||||
$person->setCFData([
|
$person->setCFData([
|
||||||
'remarques' => $this->createCustomFieldText()
|
'remarques' => $this->createCustomFieldText()
|
||||||
->serialize($faker->text(random_int(150, 250)), $this->cfText),
|
->serialize($faker->text(mt_rand(150, 250)), $this->cfText),
|
||||||
'document-d-identite' => $this->createCustomFieldChoice()
|
'document-d-identite' => $this->createCustomFieldChoice()
|
||||||
->serialize([$choices[array_rand($choices)]], $this->cfChoice),
|
->serialize([$choices[array_rand($choices)]], $this->cfChoice),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
|
|
||||||
public function __construct(private readonly MembersEditorFactory $editorFactory, private readonly EntityManagerInterface $em)
|
public function __construct(private readonly MembersEditorFactory $editorFactory, private readonly EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
|
mt_srand(123456789);
|
||||||
$this->loader = new NativeLoader();
|
$this->loader = new NativeLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,12 +73,12 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
|
|
||||||
private function addAddressToHousehold(Household $household, \DateTimeImmutable $date, ObjectManager $manager)
|
private function addAddressToHousehold(Household $household, \DateTimeImmutable $date, ObjectManager $manager)
|
||||||
{
|
{
|
||||||
if (\random_int(0, 10) > 8) {
|
if (\mt_rand(0, 10) > 8) {
|
||||||
// 20% of household without address
|
// 20% of household without address
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$nb = \random_int(1, 6);
|
$nb = \mt_rand(1, 6);
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
@@ -85,15 +86,15 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
$address = $this->createAddress();
|
$address = $this->createAddress();
|
||||||
$address->setValidFrom(\DateTime::createFromImmutable($date));
|
$address->setValidFrom(\DateTime::createFromImmutable($date));
|
||||||
|
|
||||||
if (\random_int(0, 20) < 1) {
|
if (\mt_rand(0, 20) < 1) {
|
||||||
$date = $date->add(new \DateInterval('P'.\random_int(8, 52).'W'));
|
$date = $date->add(new \DateInterval('P'.\mt_rand(8, 52).'W'));
|
||||||
$address->setValidTo(\DateTime::createFromImmutable($date));
|
$address->setValidTo(\DateTime::createFromImmutable($date));
|
||||||
}
|
}
|
||||||
|
|
||||||
$household->addAddress($address);
|
$household->addAddress($address);
|
||||||
$manager->persist($address);
|
$manager->persist($address);
|
||||||
|
|
||||||
$date = $date->add(new \DateInterval('P'.\random_int(8, 52).'W'));
|
$date = $date->add(new \DateInterval('P'.\mt_rand(8, 52).'W'));
|
||||||
++$i;
|
++$i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,7 +128,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
$k = 0;
|
$k = 0;
|
||||||
|
|
||||||
foreach ($this->getRandomPersons(1, 3) as $person) {
|
foreach ($this->getRandomPersons(1, 3) as $person) {
|
||||||
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
$date = $startDate->add(new \DateInterval('P'.\mt_rand(1, 200).'W'));
|
||||||
$position = $this->getReference(LoadHouseholdPosition::ADULT, Position::class);
|
$position = $this->getReference(LoadHouseholdPosition::ADULT, Position::class);
|
||||||
|
|
||||||
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
|
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
|
||||||
@@ -136,7 +137,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
|
|
||||||
// load children
|
// load children
|
||||||
foreach ($this->getRandomPersons(0, 3) as $person) {
|
foreach ($this->getRandomPersons(0, 3) as $person) {
|
||||||
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
$date = $startDate->add(new \DateInterval('P'.\mt_rand(1, 200).'W'));
|
||||||
$position = $this->getReference(LoadHouseholdPosition::CHILD, Position::class);
|
$position = $this->getReference(LoadHouseholdPosition::CHILD, Position::class);
|
||||||
|
|
||||||
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
|
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
|
||||||
@@ -145,7 +146,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
|
|
||||||
// load children out
|
// load children out
|
||||||
foreach ($this->getRandomPersons(0, 2) as $person) {
|
foreach ($this->getRandomPersons(0, 2) as $person) {
|
||||||
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
$date = $startDate->add(new \DateInterval('P'.\mt_rand(1, 200).'W'));
|
||||||
$position = $this->getReference(LoadHouseholdPosition::CHILD_OUT, Position::class);
|
$position = $this->getReference(LoadHouseholdPosition::CHILD_OUT, Position::class);
|
||||||
|
|
||||||
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
|
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
|
||||||
@@ -169,7 +170,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
{
|
{
|
||||||
$persons = [];
|
$persons = [];
|
||||||
|
|
||||||
$nb = \random_int($min, $max);
|
$nb = \mt_rand($min, $max);
|
||||||
|
|
||||||
for ($i = 0; $i < $nb; ++$i) {
|
for ($i = 0; $i < $nb; ++$i) {
|
||||||
$personId = \array_pop($this->personIds)['id'];
|
$personId = \array_pop($this->personIds)['id'];
|
||||||
|
|||||||
@@ -240,6 +240,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
|
|||||||
protected UserRepository $userRepository,
|
protected UserRepository $userRepository,
|
||||||
protected GenderRepository $genderRepository,
|
protected GenderRepository $genderRepository,
|
||||||
) {
|
) {
|
||||||
|
mt_srand(123456789);
|
||||||
$this->faker = Factory::create('fr_FR');
|
$this->faker = Factory::create('fr_FR');
|
||||||
$this->faker->addProvider($this);
|
$this->faker->addProvider($this);
|
||||||
$this->loader = new NativeLoader($this->faker);
|
$this->loader = new NativeLoader($this->faker);
|
||||||
@@ -273,7 +274,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
|
|||||||
$this->cacheCountries = $this->countryRepository->findAll();
|
$this->cacheCountries = $this->countryRepository->findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\random_int(0, 100) > $nullPercentage) {
|
if (\mt_rand(0, 100) > $nullPercentage) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +290,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
|
|||||||
$this->cacheGenders = $this->genderRepository->findByActiveOrdered();
|
$this->cacheGenders = $this->genderRepository->findByActiveOrdered();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\random_int(0, 100) > $nullPercentage) {
|
if (\mt_rand(0, 100) > $nullPercentage) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +308,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
|
|||||||
$this->cacheMaritalStatuses = $this->maritalStatusRepository->findAll();
|
$this->cacheMaritalStatuses = $this->maritalStatusRepository->findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\random_int(0, 100) > $nullPercentage) {
|
if (\mt_rand(0, 100) > $nullPercentage) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,7 +353,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
|
|||||||
$accompanyingPeriod = new AccompanyingPeriod(
|
$accompanyingPeriod = new AccompanyingPeriod(
|
||||||
(new \DateTime())
|
(new \DateTime())
|
||||||
->sub(
|
->sub(
|
||||||
new \DateInterval('P'.\random_int(0, 180).'D')
|
new \DateInterval('P'.\mt_rand(0, 180).'D')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$accompanyingPeriod->setCreatedBy($this->getRandomUser())
|
$accompanyingPeriod->setCreatedBy($this->getRandomUser())
|
||||||
@@ -360,7 +361,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
|
|||||||
$person->addAccompanyingPeriod($accompanyingPeriod);
|
$person->addAccompanyingPeriod($accompanyingPeriod);
|
||||||
$accompanyingPeriod->addSocialIssue($this->getRandomSocialIssue());
|
$accompanyingPeriod->addSocialIssue($this->getRandomSocialIssue());
|
||||||
|
|
||||||
if (\random_int(0, 10) > 3) {
|
if (\mt_rand(0, 10) > 3) {
|
||||||
// always add social scope:
|
// always add social scope:
|
||||||
$accompanyingPeriod->addScope($this->getReference('scope_social', Scope::class));
|
$accompanyingPeriod->addScope($this->getReference('scope_social', Scope::class));
|
||||||
$origin = $this->getReference(LoadAccompanyingPeriodOrigin::ACCOMPANYING_PERIOD_ORIGIN, AccompanyingPeriod\Origin::class);
|
$origin = $this->getReference(LoadAccompanyingPeriodOrigin::ACCOMPANYING_PERIOD_ORIGIN, AccompanyingPeriod\Origin::class);
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ class LoadRelationships extends Fixture implements DependentFixtureInterface
|
|||||||
{
|
{
|
||||||
use PersonRandomHelper;
|
use PersonRandomHelper;
|
||||||
|
|
||||||
public function __construct(private readonly EntityManagerInterface $em) {}
|
public function __construct(private readonly EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
mt_srand(123456789);
|
||||||
|
}
|
||||||
|
|
||||||
public function getDependencies(): array
|
public function getDependencies(): array
|
||||||
{
|
{
|
||||||
@@ -47,8 +50,8 @@ class LoadRelationships extends Fixture implements DependentFixtureInterface
|
|||||||
->setFromPerson($this->getRandomPerson($this->em))
|
->setFromPerson($this->getRandomPerson($this->em))
|
||||||
->setToPerson($this->getRandomPerson($this->em))
|
->setToPerson($this->getRandomPerson($this->em))
|
||||||
->setRelation($this->getReference(LoadRelations::RELATION_KEY.
|
->setRelation($this->getReference(LoadRelations::RELATION_KEY.
|
||||||
random_int(0, \count(LoadRelations::RELATIONS) - 1), Relation::class))
|
mt_rand(0, \count(LoadRelations::RELATIONS) - 1), Relation::class))
|
||||||
->setReverse((bool) random_int(0, 1))
|
->setReverse((bool) mt_rand(0, 1))
|
||||||
->setCreatedBy($user)
|
->setCreatedBy($user)
|
||||||
->setUpdatedBy($user)
|
->setUpdatedBy($user)
|
||||||
->setCreatedAt($date)
|
->setCreatedAt($date)
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ final class RelationshipApiControllerTest extends WebTestCase
|
|||||||
|
|
||||||
public static function personProvider(): array
|
public static function personProvider(): array
|
||||||
{
|
{
|
||||||
|
// fix a seed to avoid random errors
|
||||||
|
mt_srand(1234588755);
|
||||||
|
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||||
$personIdHavingRelation = $em->createQueryBuilder()
|
$personIdHavingRelation = $em->createQueryBuilder()
|
||||||
@@ -116,6 +119,9 @@ final class RelationshipApiControllerTest extends WebTestCase
|
|||||||
|
|
||||||
public static function relationProvider(): array
|
public static function relationProvider(): array
|
||||||
{
|
{
|
||||||
|
// fix a seed to avoid random errors
|
||||||
|
mt_srand(1234588755);
|
||||||
|
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||||
$personIdWithoutRelations = $em->createQueryBuilder()
|
$personIdWithoutRelations = $em->createQueryBuilder()
|
||||||
@@ -144,6 +150,8 @@ final class RelationshipApiControllerTest extends WebTestCase
|
|||||||
->findAll();
|
->findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$relations[\array_rand(self::$relations)];
|
$keys = array_keys(self::$relations);
|
||||||
|
|
||||||
|
return self::$relations[mt_rand(0, \count($keys) - 1)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ use Doctrine\Persistence\ObjectManager;
|
|||||||
*/
|
*/
|
||||||
class LoadCustomField extends AbstractFixture implements OrderedFixtureInterface
|
class LoadCustomField extends AbstractFixture implements OrderedFixtureInterface
|
||||||
{
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
mt_srand(123456789);
|
||||||
|
}
|
||||||
|
|
||||||
public function getOrder(): int
|
public function getOrder(): int
|
||||||
{
|
{
|
||||||
return 15001;
|
return 15001;
|
||||||
@@ -67,15 +72,15 @@ class LoadCustomField extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
];
|
];
|
||||||
|
|
||||||
for ($i = 0; 25 >= $i; ++$i) {
|
for ($i = 0; 25 >= $i; ++$i) {
|
||||||
$cFType = $cFTypes[random_int(0, \count($cFTypes) - 1)];
|
$cFType = $cFTypes[mt_rand(0, \count($cFTypes) - 1)];
|
||||||
|
|
||||||
$customField = (new CustomField())
|
$customField = (new CustomField())
|
||||||
->setSlug("cf_report_{$i}")
|
->setSlug("cf_report_{$i}")
|
||||||
->setType($cFType['type'])
|
->setType($cFType['type'])
|
||||||
->setOptions($cFType['options'])
|
->setOptions($cFType['options'])
|
||||||
->setName(['fr' => "CustomField {$i}"])
|
->setName(['fr' => "CustomField {$i}"])
|
||||||
->setOrdering(random_int(0, 1000) / 1000)
|
->setOrdering(mt_rand(0, 1000) / 1000)
|
||||||
->setCustomFieldsGroup($this->getReference('cf_group_report_'.random_int(0, 3), CustomFieldsGroup::class));
|
->setCustomFieldsGroup($this->getReference('cf_group_report_'.mt_rand(0, 3), CustomFieldsGroup::class));
|
||||||
|
|
||||||
$manager->persist($customField);
|
$manager->persist($customField);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly EntityManagerInterface $entityManager,
|
private readonly EntityManagerInterface $entityManager,
|
||||||
) {
|
) {
|
||||||
|
mt_srand(123456789);
|
||||||
$this->faker = FakerFactory::create('fr_FR');
|
$this->faker = FakerFactory::create('fr_FR');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
|
|||||||
$report = (new Report())
|
$report = (new Report())
|
||||||
->setPerson($person)
|
->setPerson($person)
|
||||||
->setCFGroup(
|
->setCFGroup(
|
||||||
random_int(0, 10) > 5 ?
|
mt_rand(0, 10) > 5 ?
|
||||||
$this->getReference('cf_group_report_logement', CustomFieldsGroup::class) :
|
$this->getReference('cf_group_report_logement', CustomFieldsGroup::class) :
|
||||||
$this->getReference('cf_group_report_education', CustomFieldsGroup::class)
|
$this->getReference('cf_group_report_education', CustomFieldsGroup::class)
|
||||||
)
|
)
|
||||||
@@ -106,7 +107,7 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
|
|||||||
// set date. 30% of the dates are 2015-05-01
|
// set date. 30% of the dates are 2015-05-01
|
||||||
$expectedDate = new \DateTime('2015-01-05');
|
$expectedDate = new \DateTime('2015-01-05');
|
||||||
|
|
||||||
if (random_int(0, 100) < 30) {
|
if (mt_rand(0, 100) < 30) {
|
||||||
$report->setDate($expectedDate);
|
$report->setDate($expectedDate);
|
||||||
} else {
|
} else {
|
||||||
$report->setDate($this->faker->dateTimeBetween('-1 year', 'now')
|
$report->setDate($this->faker->dateTimeBetween('-1 year', 'now')
|
||||||
@@ -150,7 +151,7 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
|
|||||||
$selectedPeople = [];
|
$selectedPeople = [];
|
||||||
|
|
||||||
foreach ($people as $person) {
|
foreach ($people as $person) {
|
||||||
if (random_int(0, 100) < $percentage) {
|
if (mt_rand(0, 100) < $percentage) {
|
||||||
$selectedPeople[] = $person;
|
$selectedPeople[] = $person;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,7 +179,7 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
|
|||||||
$picked = [];
|
$picked = [];
|
||||||
|
|
||||||
if ($multiple) {
|
if ($multiple) {
|
||||||
$numberSelected = random_int(1, \count($choices) - 1);
|
$numberSelected = mt_rand(1, \count($choices) - 1);
|
||||||
|
|
||||||
for ($i = 0; $i < $numberSelected; ++$i) {
|
for ($i = 0; $i < $numberSelected; ++$i) {
|
||||||
$picked[] = $this->pickChoice($choices);
|
$picked[] = $this->pickChoice($choices);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class LoadThirdParty extends Fixture implements DependentFixtureInterface
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
mt_srand(123456789);
|
||||||
$this->phoneNumberUtil = PhoneNumberUtil::getInstance();
|
$this->phoneNumberUtil = PhoneNumberUtil::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ class LoadThirdParty extends Fixture implements DependentFixtureInterface
|
|||||||
static fn ($a) => $a['ref'],
|
static fn ($a) => $a['ref'],
|
||||||
LoadCenters::$centers
|
LoadCenters::$centers
|
||||||
);
|
);
|
||||||
$number = random_int(1, \count($references));
|
$number = mt_rand(1, \count($references));
|
||||||
|
|
||||||
if (1 === $number) {
|
if (1 === $number) {
|
||||||
yield $this->getReference($references[array_rand($references)], Center::class);
|
yield $this->getReference($references[array_rand($references)], Center::class);
|
||||||
|
|||||||
Reference in New Issue
Block a user