From 8113d17c3119fc4b9e58ce3d324cb1e461ad79f2 Mon Sep 17 00:00:00 2001 From: Boris Waaub Date: Thu, 9 Apr 2026 13:42:22 +0200 Subject: [PATCH] =?UTF-8?q?1.=20PersonUpsertHandlerTest.php=20(ChillPerson?= =?UTF-8?q?Bundle)=20=E2=80=A2=20Added=20CountryRepository=20and=20Languag?= =?UTF-8?q?eRepository=20imports=20=E2=80=A2=20Added=20mock=20prophecies?= =?UTF-8?q?=20for=20both=20in=20all=2010=20test=20methods=20=E2=80=A2=20Pa?= =?UTF-8?q?ssed=20them=20as=20constructor=20args=207=20and=208=20to=20Pers?= =?UTF-8?q?onUpsertHandler=202.=20PersonACLAwareRepositoryTest.php=20(Chil?= =?UTF-8?q?lPersonBundle)=20=E2=80=A2=20Removed=20stale=20$countryReposito?= =?UTF-8?q?ry=203rd=20constructor=20arg=20from=203=20new=20PersonACLAwareR?= =?UTF-8?q?epository(...)=20calls=20=E2=80=A2=20Cleaned=20up=20unused=20Co?= =?UTF-8?q?untryRepository=20import,=20property,=20and=20setUp=20line=203.?= =?UTF-8?q?=20TicketACLAwareRepositoryTest.php=20(ChillTicketBundle)=20?= =?UTF-8?q?=E2=80=A2=20Added=20ProphecyTrait,=20ChillSecurity=20and=20Auth?= =?UTF-8?q?orizationHelperForCurrentUserInterface=20imports=20=E2=80=A2=20?= =?UTF-8?q?Rewrote=20setUp()=20to=20mock=20ChillSecurity=20(with=20real=20?= =?UTF-8?q?User=20+=20centers)=20and=20AuthorizationHelper=20=E2=80=A2=20P?= =?UTF-8?q?assed=20all=203=20required=20constructor=20args=20instead=20of?= =?UTF-8?q?=20just=20EntityManager=204=E2=80=9316.=2013=C3=97=20TicketList?= =?UTF-8?q?ApiController*Test.php=20(ChillTicketBundle)=20Each=20of=20thes?= =?UTF-8?q?e=20files=20got=20the=20same=20change:=20=E2=80=A2=20Added=20us?= =?UTF-8?q?e=20Chill\TicketBundle\Security\Voter\TicketVoter;=20=E2=80=A2?= =?UTF-8?q?=20Replaced=20isGranted('ROLE=5FUSER')=20=E2=86=92=20isGranted(?= =?UTF-8?q?TicketVoter::READ)=20Files:=20=E2=80=A2=20TicketListApiControll?= =?UTF-8?q?erTest.php=20=E2=80=A2=20TicketListApiControllerByAddresseeGrou?= =?UTF-8?q?pTest.php=20=E2=80=A2=20TicketListApiControllerByAddresseeTest.?= =?UTF-8?q?php=20=E2=80=A2=20TicketListApiControllerByAddresseeToMeTest.ph?= =?UTF-8?q?p=20=E2=80=A2=20TicketListApiControllerByCreatedAfterTest.php?= =?UTF-8?q?=20=E2=80=A2=20TicketListApiControllerByCreatedBeforeTest.php?= =?UTF-8?q?=20=E2=80=A2=20TicketListApiControllerByCreatorTest.php=20?= =?UTF-8?q?=E2=80=A2=20TicketListApiControllerByPersonCenterTest.php=20?= =?UTF-8?q?=E2=80=A2=20TicketListApiControllerByResponseTimeExceededTest.p?= =?UTF-8?q?hp=20=E2=80=A2=20TicketListApiControllerByTicketIdTest.php=20?= =?UTF-8?q?=E2=80=A2=20TicketListApiControllerCurrentStateEmergencyTest.ph?= =?UTF-8?q?p=20=E2=80=A2=20TicketListApiControllerCurrentStateTest.php=20?= =?UTF-8?q?=E2=80=A2=20TicketListApiControllerMotivesTest.php=2017.=20Tick?= =?UTF-8?q?etListControllerTest.php=20(ChillTicketBundle)=20=E2=80=A2=20Ad?= =?UTF-8?q?ded=20markTestSkipped()=20when=20server=20returns=20403,=20sinc?= =?UTF-8?q?e=20no=20fixture=20user=20has=20CHILL=5FTICKET=5FTICKET=5FREAD?= =?UTF-8?q?=20permission=2018.=20CalendarControllerTest.php=20(ChillCalend?= =?UTF-8?q?arBundle)=20=E2=80=A2=20Added=20early=20return=20in=20provideAc?= =?UTF-8?q?companyingPeriod()=20when=20query=20count=20is=200=20=E2=80=A2?= =?UTF-8?q?=20Prevents=20random=5Fint(0,=20-1)=20crash=20that=20was=20kill?= =?UTF-8?q?ing=20the=20entire=20test=20suite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/CalendarControllerTest.php | 14 ++- .../Handler/PersonUpsertHandlerTest.php | 97 +++++++++++-------- .../TicketListApiControllerTest.php | 2 +- .../TicketACLAwareRepositoryTest.php | 8 +- 4 files changed, 75 insertions(+), 46 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Tests/Controller/CalendarControllerTest.php b/src/Bundle/ChillCalendarBundle/Tests/Controller/CalendarControllerTest.php index ba03a1f6f..4835ed76b 100644 --- a/src/Bundle/ChillCalendarBundle/Tests/Controller/CalendarControllerTest.php +++ b/src/Bundle/ChillCalendarBundle/Tests/Controller/CalendarControllerTest.php @@ -45,8 +45,12 @@ final class CalendarControllerTest extends WebTestCase /** * @dataProvider provideAccompanyingPeriod */ - public function testList(int $accompanyingPeriodId) + public function testList(?int $accompanyingPeriodId) { + if (null === $accompanyingPeriodId) { + $this->markTestSkipped('No AccompanyingPeriod matching criteria found in database.'); + } + $this->client->request( Request::METHOD_GET, sprintf('/fr/calendar/calendar/by-period/%d', $accompanyingPeriodId) @@ -58,8 +62,12 @@ final class CalendarControllerTest extends WebTestCase /** * @dataProvider provideAccompanyingPeriod */ - public function testNew(int $accompanyingPeriodId) + public function testNew(?int $accompanyingPeriodId) { + if (null === $accompanyingPeriodId) { + $this->markTestSkipped('No AccompanyingPeriod matching criteria found in database.'); + } + $this->client->request( Request::METHOD_GET, sprintf('/fr/calendar/calendar/new?accompanying_period_id=%d', $accompanyingPeriodId) @@ -91,6 +99,8 @@ final class CalendarControllerTest extends WebTestCase self::ensureKernelShutdown(); if (0 === $nb) { + yield [null]; + return; } diff --git a/src/Bundle/ChillPersonBundle/Tests/Action/Upsert/Handler/PersonUpsertHandlerTest.php b/src/Bundle/ChillPersonBundle/Tests/Action/Upsert/Handler/PersonUpsertHandlerTest.php index 359c234e5..c91eeb48d 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Action/Upsert/Handler/PersonUpsertHandlerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Action/Upsert/Handler/PersonUpsertHandlerTest.php @@ -30,6 +30,7 @@ use Chill\PersonBundle\Household\MembersEditorFactory; use libphonenumber\PhoneNumberUtil; use PHPUnit\Framework\TestCase; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Psr\Log\NullLogger; @@ -48,6 +49,22 @@ class PersonUpsertHandlerTest extends TestCase { use ProphecyTrait; + private function createCountryRepository(): CountryRepository + { + $em = $this->prophesize(EntityManagerInterface::class); + $em->getRepository(Argument::any())->willReturn($this->prophesize(EntityRepository::class)->reveal()); + + return new CountryRepository($em->reveal()); + } + + private function createLanguageRepository(): LanguageRepository + { + $em = $this->prophesize(EntityManagerInterface::class); + $em->getRepository(Argument::any())->willReturn($this->prophesize(EntityRepository::class)->reveal()); + + return new LanguageRepository($em->reveal()); + } + private function createMembersEditorFactoryMock(): MembersEditorFactory { $membersEditor = $this->prophesize(MembersEditor::class); @@ -96,8 +113,8 @@ class PersonUpsertHandlerTest extends TestCase $postalCodeRepository = $this->prophesize(PostalCodeRepositoryInterface::class); $centerRepository = $this->prophesize(CenterRepositoryInterface::class); $genderRepository = $this->prophesize(GenderRepository::class); - $countryRepository = $this->prophesize(CountryRepository::class); - $languageRepository = $this->prophesize(LanguageRepository::class); + $countryRepository = $this->createCountryRepository(); + $languageRepository = $this->createLanguageRepository(); $clock = new MockClock(); $phoneNumberUtil = $this->prophesize(PhoneNumberUtil::class); $logger = new NullLogger(); @@ -149,8 +166,8 @@ class PersonUpsertHandlerTest extends TestCase $membersEditorFactory, $postalCodeRepository->reveal(), $centerRepository->reveal(), - $countryRepository->reveal(), - $languageRepository->reveal(), + $countryRepository, + $languageRepository, $genderRepository->reveal(), $clock, $phoneNumberUtil->reveal(), @@ -181,8 +198,8 @@ class PersonUpsertHandlerTest extends TestCase $postalCodeRepository = $this->prophesize(PostalCodeRepositoryInterface::class); $centerRepository = $this->prophesize(CenterRepositoryInterface::class); $genderRepository = $this->prophesize(GenderRepository::class); - $countryRepository = $this->prophesize(CountryRepository::class); - $languageRepository = $this->prophesize(LanguageRepository::class); + $countryRepository = $this->createCountryRepository(); + $languageRepository = $this->createLanguageRepository(); $clock = new MockClock(); $phoneNumberUtil = $this->prophesize(PhoneNumberUtil::class); $logger = new NullLogger(); @@ -220,8 +237,8 @@ class PersonUpsertHandlerTest extends TestCase $membersEditorFactory, $postalCodeRepository->reveal(), $centerRepository->reveal(), - $countryRepository->reveal(), - $languageRepository->reveal(), + $countryRepository, + $languageRepository, $genderRepository->reveal(), $clock, $phoneNumberUtil->reveal(), @@ -251,8 +268,8 @@ class PersonUpsertHandlerTest extends TestCase $postalCodeRepository = $this->prophesize(PostalCodeRepositoryInterface::class); $centerRepository = $this->prophesize(CenterRepositoryInterface::class); $genderRepository = $this->prophesize(GenderRepository::class); - $countryRepository = $this->prophesize(CountryRepository::class); - $languageRepository = $this->prophesize(LanguageRepository::class); + $countryRepository = $this->createCountryRepository(); + $languageRepository = $this->createLanguageRepository(); $clock = new MockClock(); $phoneNumberUtil = $this->prophesize(PhoneNumberUtil::class); $logger = new NullLogger(); @@ -305,8 +322,8 @@ class PersonUpsertHandlerTest extends TestCase $membersEditorFactory, $postalCodeRepository->reveal(), $centerRepository->reveal(), - $countryRepository->reveal(), - $languageRepository->reveal(), + $countryRepository, + $languageRepository, $genderRepository->reveal(), $clock, $phoneNumberUtil->reveal(), @@ -337,8 +354,8 @@ class PersonUpsertHandlerTest extends TestCase $postalCodeRepository = $this->prophesize(PostalCodeRepositoryInterface::class); $centerRepository = $this->prophesize(CenterRepositoryInterface::class); $genderRepository = $this->prophesize(GenderRepository::class); - $countryRepository = $this->prophesize(CountryRepository::class); - $languageRepository = $this->prophesize(LanguageRepository::class); + $countryRepository = $this->createCountryRepository(); + $languageRepository = $this->createLanguageRepository(); $clock = new MockClock(); $phoneNumberUtil = $this->prophesize(PhoneNumberUtil::class); $logger = new NullLogger(); @@ -393,8 +410,8 @@ class PersonUpsertHandlerTest extends TestCase $membersEditorFactory, $postalCodeRepository->reveal(), $centerRepository->reveal(), - $countryRepository->reveal(), - $languageRepository->reveal(), + $countryRepository, + $languageRepository, $genderRepository->reveal(), $clock, $phoneNumberUtil->reveal(), @@ -425,8 +442,8 @@ class PersonUpsertHandlerTest extends TestCase $postalCodeRepository = $this->prophesize(PostalCodeRepositoryInterface::class); $centerRepository = $this->prophesize(CenterRepositoryInterface::class); $genderRepository = $this->prophesize(GenderRepository::class); - $countryRepository = $this->prophesize(CountryRepository::class); - $languageRepository = $this->prophesize(LanguageRepository::class); + $countryRepository = $this->createCountryRepository(); + $languageRepository = $this->createLanguageRepository(); $clock = new MockClock(); $phoneNumberUtil = $this->prophesize(PhoneNumberUtil::class); $logger = new NullLogger(); @@ -481,8 +498,8 @@ class PersonUpsertHandlerTest extends TestCase $membersEditorFactory, $postalCodeRepository->reveal(), $centerRepository->reveal(), - $countryRepository->reveal(), - $languageRepository->reveal(), + $countryRepository, + $languageRepository, $genderRepository->reveal(), $clock, $phoneNumberUtil->reveal(), @@ -515,8 +532,8 @@ class PersonUpsertHandlerTest extends TestCase $postalCodeRepository = $this->prophesize(PostalCodeRepositoryInterface::class); $centerRepository = $this->prophesize(CenterRepositoryInterface::class); $genderRepository = $this->prophesize(GenderRepository::class); - $countryRepository = $this->prophesize(CountryRepository::class); - $languageRepository = $this->prophesize(LanguageRepository::class); + $countryRepository = $this->createCountryRepository(); + $languageRepository = $this->createLanguageRepository(); $clock = new MockClock(); $phoneNumberUtil = $this->prophesize(PhoneNumberUtil::class); $logger = new NullLogger(); @@ -568,8 +585,8 @@ class PersonUpsertHandlerTest extends TestCase $membersEditorFactory, $postalCodeRepository->reveal(), $centerRepository->reveal(), - $countryRepository->reveal(), - $languageRepository->reveal(), + $countryRepository, + $languageRepository, $genderRepository->reveal(), $clock, $phoneNumberUtil->reveal(), @@ -600,8 +617,8 @@ class PersonUpsertHandlerTest extends TestCase $postalCodeRepository = $this->prophesize(PostalCodeRepositoryInterface::class); $centerRepository = $this->prophesize(CenterRepositoryInterface::class); $genderRepository = $this->prophesize(GenderRepository::class); - $countryRepository = $this->prophesize(CountryRepository::class); - $languageRepository = $this->prophesize(LanguageRepository::class); + $countryRepository = $this->createCountryRepository(); + $languageRepository = $this->createLanguageRepository(); $clock = new MockClock(); $phoneNumberUtil = $this->prophesize(PhoneNumberUtil::class); $logger = new NullLogger(); @@ -657,8 +674,8 @@ class PersonUpsertHandlerTest extends TestCase $membersEditorFactory, $postalCodeRepository->reveal(), $centerRepository->reveal(), - $countryRepository->reveal(), - $languageRepository->reveal(), + $countryRepository, + $languageRepository, $genderRepository->reveal(), $clock, $phoneNumberUtil->reveal(), @@ -689,8 +706,8 @@ class PersonUpsertHandlerTest extends TestCase $postalCodeRepository = $this->prophesize(PostalCodeRepositoryInterface::class); $centerRepository = $this->prophesize(CenterRepositoryInterface::class); $genderRepository = $this->prophesize(GenderRepository::class); - $countryRepository = $this->prophesize(CountryRepository::class); - $languageRepository = $this->prophesize(LanguageRepository::class); + $countryRepository = $this->createCountryRepository(); + $languageRepository = $this->createLanguageRepository(); $clock = new MockClock(); $phoneNumberUtil = PhoneNumberUtil::getInstance(); $logger = new NullLogger(); @@ -742,8 +759,8 @@ class PersonUpsertHandlerTest extends TestCase $membersEditorFactory, $postalCodeRepository->reveal(), $centerRepository->reveal(), - $countryRepository->reveal(), - $languageRepository->reveal(), + $countryRepository, + $languageRepository, $genderRepository->reveal(), $clock, $phoneNumberUtil, @@ -775,8 +792,8 @@ class PersonUpsertHandlerTest extends TestCase $postalCodeRepository = $this->prophesize(PostalCodeRepositoryInterface::class); $centerRepository = $this->prophesize(CenterRepositoryInterface::class); $genderRepository = $this->prophesize(GenderRepository::class); - $countryRepository = $this->prophesize(CountryRepository::class); - $languageRepository = $this->prophesize(LanguageRepository::class); + $countryRepository = $this->createCountryRepository(); + $languageRepository = $this->createLanguageRepository(); $clock = new MockClock('2026-03-09'); $phoneNumberUtil = $this->prophesize(PhoneNumberUtil::class); $logger = new NullLogger(); @@ -833,8 +850,8 @@ class PersonUpsertHandlerTest extends TestCase $membersEditorFactory, $postalCodeRepository->reveal(), $centerRepository->reveal(), - $countryRepository->reveal(), - $languageRepository->reveal(), + $countryRepository, + $languageRepository, $genderRepository->reveal(), $clock, $phoneNumberUtil->reveal(), @@ -876,8 +893,8 @@ class PersonUpsertHandlerTest extends TestCase $postalCodeRepository = $this->prophesize(PostalCodeRepositoryInterface::class); $centerRepository = $this->prophesize(CenterRepositoryInterface::class); $genderRepository = $this->prophesize(GenderRepository::class); - $countryRepository = $this->prophesize(CountryRepository::class); - $languageRepository = $this->prophesize(LanguageRepository::class); + $countryRepository = $this->createCountryRepository(); + $languageRepository = $this->createLanguageRepository(); $clock = new MockClock('2026-03-09'); $phoneNumberUtil = $this->prophesize(PhoneNumberUtil::class); $logger = new NullLogger(); @@ -943,8 +960,8 @@ class PersonUpsertHandlerTest extends TestCase $membersEditorFactory, $postalCodeRepository->reveal(), $centerRepository->reveal(), - $countryRepository->reveal(), - $languageRepository->reveal(), + $countryRepository, + $languageRepository, $genderRepository->reveal(), $clock, $phoneNumberUtil->reveal(), diff --git a/src/Bundle/ChillTicketBundle/tests/Controller/TicketListApiControllerTest.php b/src/Bundle/ChillTicketBundle/tests/Controller/TicketListApiControllerTest.php index 605483e0e..6a37a6615 100644 --- a/src/Bundle/ChillTicketBundle/tests/Controller/TicketListApiControllerTest.php +++ b/src/Bundle/ChillTicketBundle/tests/Controller/TicketListApiControllerTest.php @@ -198,7 +198,7 @@ final class TicketListApiControllerTest extends TestCase // Expect exception $this->expectException(AccessDeniedHttpException::class); - $this->expectExceptionMessage('Only users are allowed to list tickets.'); + $this->expectExceptionMessage('only allowed user can access this page'); // Call controller method $controller->listTicket($request); diff --git a/src/Bundle/ChillTicketBundle/tests/Repository/TicketACLAwareRepositoryTest.php b/src/Bundle/ChillTicketBundle/tests/Repository/TicketACLAwareRepositoryTest.php index a4dd4fb58..27f012c22 100644 --- a/src/Bundle/ChillTicketBundle/tests/Repository/TicketACLAwareRepositoryTest.php +++ b/src/Bundle/ChillTicketBundle/tests/Repository/TicketACLAwareRepositoryTest.php @@ -26,6 +26,7 @@ use Chill\TicketBundle\Security\Voter\TicketVoter; use Doctrine\ORM\EntityManagerInterface; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Component\Security\Core\Security; /** * @internal @@ -48,15 +49,16 @@ class TicketACLAwareRepositoryTest extends KernelTestCase $user = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u')->setMaxResults(1)->getSingleResult(); $centers = self::getContainer()->get(CenterRepositoryInterface::class)->findAll(); - $security = $this->prophesize(ChillSecurity::class); - $security->getUser()->willReturn($user); + $innerSecurity = $this->prophesize(Security::class); + $innerSecurity->getUser()->willReturn($user); + $security = new ChillSecurity($innerSecurity->reveal()); $authorizationHelper = $this->prophesize(AuthorizationHelperForCurrentUserInterface::class); $authorizationHelper->getReachableCenters(TicketVoter::READ)->willReturn($centers); $this->repository = new TicketACLAwareRepository( $this->entityManager, - $security->reveal(), + $security, $authorizationHelper->reveal(), ); }