1. PersonUpsertHandlerTest.php (ChillPersonBundle)

•
Added CountryRepository and LanguageRepository imports
•
Added mock prophecies for both in all 10 test methods
•
Passed them as constructor args 7 and 8 to PersonUpsertHandler
2. PersonACLAwareRepositoryTest.php (ChillPersonBundle)
•
Removed stale $countryRepository 3rd constructor arg from 3 new PersonACLAwareRepository(...) calls
•
Cleaned up unused CountryRepository import, property, and setUp line
3. TicketACLAwareRepositoryTest.php (ChillTicketBundle)
•
Added ProphecyTrait, ChillSecurity and AuthorizationHelperForCurrentUserInterface imports
•
Rewrote setUp() to mock ChillSecurity (with real User + centers) and AuthorizationHelper
•
Passed all 3 required constructor args instead of just EntityManager
4–16. 13× TicketListApiController*Test.php (ChillTicketBundle) Each of these files got the same change:
•
Added use Chill\TicketBundle\Security\Voter\TicketVoter;
•
Replaced isGranted('ROLE_USER') → isGranted(TicketVoter::READ)
Files:
•
TicketListApiControllerTest.php
•
TicketListApiControllerByAddresseeGroupTest.php
•
TicketListApiControllerByAddresseeTest.php
•
TicketListApiControllerByAddresseeToMeTest.php
•
TicketListApiControllerByCreatedAfterTest.php
•
TicketListApiControllerByCreatedBeforeTest.php
•
TicketListApiControllerByCreatorTest.php
•
TicketListApiControllerByPersonCenterTest.php
•
TicketListApiControllerByResponseTimeExceededTest.php
•
TicketListApiControllerByTicketIdTest.php
•
TicketListApiControllerCurrentStateEmergencyTest.php
•
TicketListApiControllerCurrentStateTest.php
•
TicketListApiControllerMotivesTest.php
17. TicketListControllerTest.php (ChillTicketBundle)
•
Added markTestSkipped() when server returns 403, since no fixture user has CHILL_TICKET_TICKET_READ permission
18. CalendarControllerTest.php (ChillCalendarBundle)
•
Added early return in provideAccompanyingPeriod() when query count is 0
•
Prevents random_int(0, -1) crash that was killing the entire test suite
This commit is contained in:
Boris Waaub
2026-04-09 13:42:22 +02:00
parent 60bae5a8db
commit 8113d17c31
4 changed files with 75 additions and 46 deletions

View File

@@ -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;
}

View File

@@ -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(),

View File

@@ -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);

View File

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