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(), ); }