diff --git a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php index a67d48b0b..d53e845fd 100644 --- a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php +++ b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php @@ -32,8 +32,14 @@ use Symfony\Component\OptionsResolver\OptionsResolver; class CalendarType extends AbstractType { - public function __construct(private readonly PersonsToIdDataTransformer $personsToIdDataTransformer, private readonly IdToUserDataTransformer $idToUserDataTransformer, private readonly IdToUsersDataTransformer $idToUsersDataTransformer, private readonly IdToLocationDataTransformer $idToLocationDataTransformer, private readonly ThirdPartiesToIdDataTransformer $partiesToIdDataTransformer, private readonly IdToCalendarRangeDataTransformer $calendarRangeDataTransformer) - { + public function __construct( + private readonly PersonsToIdDataTransformer $personsToIdDataTransformer, + private readonly IdToUserDataTransformer $idToUserDataTransformer, + private readonly IdToUsersDataTransformer $idToUsersDataTransformer, + private readonly IdToLocationDataTransformer $idToLocationDataTransformer, + private readonly ThirdPartiesToIdDataTransformer $partiesToIdDataTransformer, + private readonly IdToCalendarRangeDataTransformer $calendarRangeDataTransformer + ) { } public function buildForm(FormBuilderInterface $builder, array $options) diff --git a/src/Bundle/ChillCalendarBundle/Tests/Form/CalendarTypeTest.php b/src/Bundle/ChillCalendarBundle/Tests/Form/CalendarTypeTest.php index 5adce17b2..85a2d72f9 100644 --- a/src/Bundle/ChillCalendarBundle/Tests/Form/CalendarTypeTest.php +++ b/src/Bundle/ChillCalendarBundle/Tests/Form/CalendarTypeTest.php @@ -24,14 +24,17 @@ use Chill\CalendarBundle\Form\CalendarType; use Chill\CalendarBundle\Form\DataTransformer\IdToCalendarRangeDataTransformer; use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Form\DataMapper\PrivateCommentDataMapper; use Chill\MainBundle\Form\DataTransformer\IdToLocationDataTransformer; use Chill\MainBundle\Form\DataTransformer\IdToUserDataTransformer; use Chill\MainBundle\Form\DataTransformer\IdToUsersDataTransformer; use Chill\MainBundle\Form\Type\CommentType; +use Chill\MainBundle\Form\Type\PrivateCommentType; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Form\DataTransformer\PersonsToIdDataTransformer; use Chill\ThirdPartyBundle\Entity\ThirdParty; use Chill\ThirdPartyBundle\Form\DataTransformer\ThirdPartiesToIdDataTransformer; +use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository; use DateTimeImmutable; use Doctrine\Common\Collections\Collection; use Prophecy\Argument; @@ -41,6 +44,7 @@ use Symfony\Component\Form\PreloadedExtension; use Symfony\Component\Form\Test\TypeTestCase; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Symfony\Component\Security\Core\Security; /** * @internal @@ -70,7 +74,7 @@ final class CalendarTypeTest extends TypeTestCase $this->idToUserDataTransformer = $this->buildSingleToIdDataTransformer(IdToUserDataTransformer::class, User::class); $this->idToUsersDataTransformer = $this->buildMultiToIdDataTransformer(IdToUsersDataTransformer::class, User::class); $this->idToLocationDataTransformer = $this->buildSingleToIdDataTransformer(IdToLocationDataTransformer::class, Location::class); - $this->partiesToIdDataTransformer = $this->buildMultiToIdDataTransformer(ThirdPartiesToIdDataTransformer::class, ThirdParty::class); + $this->partiesToIdDataTransformer = $this->buildMultiToIdDataTransformerThirdParties(); $this->calendarRangeDataTransformer = $this->buildSingleToIdDataTransformer(IdToCalendarRangeDataTransformer::class, CalendarRange::class); $tokenStorage = $this->prophesize(TokenStorageInterface::class); $token = $this->prophesize(TokenInterface::class); @@ -86,9 +90,9 @@ final class CalendarTypeTest extends TypeTestCase $formData = [ 'mainUser' => '1', 'users' => '2,3', - 'professionnals' => '4,5', - 'startDate' => '2022-05-05 14:00:00', - 'endDate' => '2022-05-05 14:30:00', + 'professionnals' => '646', + 'startDate' => '2022-05-05T14:00:00+0200', + 'endDate' => '2022-05-05T14:30:00+0200', 'persons' => '7', 'calendarRange' => '8', 'location' => '9', @@ -120,8 +124,6 @@ final class CalendarTypeTest extends TypeTestCase protected function getExtensions() { - $parents = parent::getExtensions(); - $calendarType = new CalendarType( $this->personsToIdDataTransformer, $this->idToUserDataTransformer, @@ -132,12 +134,27 @@ final class CalendarTypeTest extends TypeTestCase ); $commentType = new CommentType($this->tokenStorage); + $user = $this->prophesize(User::class); + $user->getId()->willReturn(1); + $security = $this->prophesize(Security::class); + $security->getUser()->willReturn($user->reveal()); + $privateCommentDataMapper = new PrivateCommentDataMapper($security->reveal()); + $privateCommentType = new PrivateCommentType($privateCommentDataMapper); + return array_merge( parent::getExtensions(), - [new PreloadedExtension([$calendarType, $commentType], [])] + [new PreloadedExtension([$calendarType, $commentType, $privateCommentType], [])] ); } + private function buildMultiToIdDataTransformerThirdParties(): ThirdPartiesToIdDataTransformer + { + $repository = $this->prophesize(ThirdPartyRepository::class); + $repository->findOneBy(Argument::type('array'))->willReturn(new ThirdParty()); + + return new ThirdPartiesToIdDataTransformer($repository->reveal()); + } + private function buildMultiToIdDataTransformer( string $classTransformer, string $objClass diff --git a/src/Bundle/ChillMainBundle/Form/DataTransformer/IdToEntityDataTransformer.php b/src/Bundle/ChillMainBundle/Form/DataTransformer/IdToEntityDataTransformer.php index d392fb90a..fa76a8dd9 100644 --- a/src/Bundle/ChillMainBundle/Form/DataTransformer/IdToEntityDataTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/DataTransformer/IdToEntityDataTransformer.php @@ -34,8 +34,11 @@ class IdToEntityDataTransformer implements DataTransformerInterface /** * @param Closure $getId */ - public function __construct(private readonly ObjectRepository $repository, private readonly bool $multiple = false, ?callable $getId = null) - { + public function __construct( + private readonly ObjectRepository $repository, + private readonly bool $multiple = false, + ?callable $getId = null + ) { $this->getId = $getId ?? static fn (object $o) => $o->getId(); } diff --git a/src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php b/src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php index 82b9feade..5dddb5c4d 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php @@ -24,11 +24,8 @@ use Symfony\Component\Security\Core\User\UserInterface; class PrivateCommentType extends AbstractType { - protected UserInterface $user; - - public function __construct(TokenStorageInterface $tokenStorage, protected PrivateCommentDataMapper $dataMapper) + public function __construct(protected PrivateCommentDataMapper $dataMapper) { - $this->user = $tokenStorage->getToken()->getUser(); } public function buildForm(FormBuilderInterface $builder, array $options)