From 52f81ef5ec61c25edb7c40989136cbd6a379b2c4 Mon Sep 17 00:00:00 2001 From: "m::r" Date: Sun, 11 Jan 2026 19:42:18 +0000 Subject: [PATCH 1/3] fix(flags-controller): fix passing extended isocodes into intl getCountry method caused exception --- app/Makefile | 2 +- app/src/Flags/Controller/FlagsController.php | 17 +++++--- app/tests/Support/Factory/UserFactory.php | 2 +- .../Unit/Service/CountriesGeneratorTest.php | 41 +++++++++++++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 app/tests/Unit/Service/CountriesGeneratorTest.php diff --git a/app/Makefile b/app/Makefile index 6acad77..6b81397 100644 --- a/app/Makefile +++ b/app/Makefile @@ -60,7 +60,7 @@ test-up: ## Start test containers (keep running) @$(TEST_COMPOSE) up -d @$(TEST_COMPOSE) exec php bin/console d:d:c -n --if-not-exists @$(TEST_COMPOSE) exec php bin/console d:m:m -n - @$(TEST_COMPOSE) exec php bin/console app:populate:users -n + @$(TEST_COMPOSE) exec php bin/console app:populate:users -n test_user_1 -f Test -l User @$(TEST_COMPOSE) exec php bin/console app:populate:capitals --purge -n @$(TEST_COMPOSE) exec php bin/console app:populate:flags --purge -n diff --git a/app/src/Flags/Controller/FlagsController.php b/app/src/Flags/Controller/FlagsController.php index 07127f3..10fd428 100644 --- a/app/src/Flags/Controller/FlagsController.php +++ b/app/src/Flags/Controller/FlagsController.php @@ -148,8 +148,8 @@ public function getStat(#[CurrentUser] $user, AnswerRepository $repository): Res $result = $repository->findAllGuesses($user->getId()); // TODO move this logic to service foreach ($result as $key => $item) { - $result[$key]['flag'] = $this->flagsGenerator->getEmojiFlag($item['flagCode']); - $result[$key]['country'] = Countries::getName(strtoupper($item['flagCode'])); + $result[$key]['flag'] = $this->flagsGenerator->getEmojiFlag($item['flagCode'], CodeSet::EXTENDED); + $result[$key]['country'] = $this->getCountryName(strtoupper($item['flagCode'])); foreach ($correctResults as $value) { if ($value['flagCode'] === $result[$key]['flagCode']) { $shown = (int) $result[$key]['times']; @@ -180,8 +180,8 @@ public function getRight(#[CurrentUser] $user, AnswerRepository $repository): Re $result = $repository->findAllGuesses($user->getId()); // TODO move this logic to service foreach ($result as $key => $item) { - $result[$key]['flag'] = $this->flagsGenerator->getEmojiFlag($item['flagCode']); - $result[$key]['country'] = Countries::getName(strtoupper($item['flagCode'])); + $result[$key]['flag'] = $this->flagsGenerator->getEmojiFlag($item['flagCode'], CodeSet::EXTENDED); + $result[$key]['country'] = $this->getCountryName(strtoupper($item['flagCode'])); foreach ($correctResults as $value) { if ($value['flagCode'] === $result[$key]['flagCode']) { $shown = (int) $result[$key]['times']; @@ -199,7 +199,14 @@ public function getRight(#[CurrentUser] $user, AnswerRepository $repository): Re } } - array_multisort($result, SORT_DESC, SORT_NUMERIC, array_column($result, 'rate'), SORT_DESC, SORT_NUMERIC); + array_multisort( + $result, + SORT_DESC, + SORT_NUMERIC, + array_column($result, 'rate'), + SORT_DESC, + SORT_NUMERIC, + ); return $this->json($result); } diff --git a/app/tests/Support/Factory/UserFactory.php b/app/tests/Support/Factory/UserFactory.php index fa45bc0..2f28914 100644 --- a/app/tests/Support/Factory/UserFactory.php +++ b/app/tests/Support/Factory/UserFactory.php @@ -7,7 +7,7 @@ use App\Flags\Entity\User; use Doctrine\ORM\EntityManagerInterface; -final class UserFactory +class UserFactory { private int $sequence = 0; diff --git a/app/tests/Unit/Service/CountriesGeneratorTest.php b/app/tests/Unit/Service/CountriesGeneratorTest.php new file mode 100644 index 0000000..4bb477c --- /dev/null +++ b/app/tests/Unit/Service/CountriesGeneratorTest.php @@ -0,0 +1,41 @@ +clientRegistry = $this->createMock(ClientRegistry::class); +// $this->router = $this->createMock(RouterInterface::class); +// $this->userRepository = $this->createMock(UserRepository::class); +// +// $this->authenticator = new HqAuthAuthenticator( +// $this->clientRegistry, +// $this->router, +// $this->userRepository +// ); +// } + + public function testCountryIsFetched(): void + { + $this->assertTrue(Countries::exists('AC')); + } +} From 6bd09cd6238054852442557a45349e7ecb8ec70f Mon Sep 17 00:00:00 2001 From: "m::r" Date: Sun, 11 Jan 2026 19:44:38 +0000 Subject: [PATCH 2/3] fix(test) --- .../Unit/Service/CountriesGeneratorTest.php | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/app/tests/Unit/Service/CountriesGeneratorTest.php b/app/tests/Unit/Service/CountriesGeneratorTest.php index 4bb477c..522ee5c 100644 --- a/app/tests/Unit/Service/CountriesGeneratorTest.php +++ b/app/tests/Unit/Service/CountriesGeneratorTest.php @@ -4,38 +4,18 @@ namespace App\Tests\Unit\Service; -use App\Flags\Entity\User; use App\Flags\Repository\UserRepository; use App\Flags\Security\HqAuthAuthenticator; use KnpU\OAuth2ClientBundle\Client\ClientRegistry; -use League\OAuth2\Client\Provider\GenericResourceOwner; use PHPUnit\Framework\TestCase; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Intl\Countries; use Symfony\Component\Routing\RouterInterface; -/** - * Unit tests for HqAuthAuthenticator - * Note: Full OAuth flow testing requires integration tests due to protected parent methods. - */ class CountriesGeneratorTest extends TestCase { -// -// protected function setUp(): void -// { -// $this->clientRegistry = $this->createMock(ClientRegistry::class); -// $this->router = $this->createMock(RouterInterface::class); -// $this->userRepository = $this->createMock(UserRepository::class); -// -// $this->authenticator = new HqAuthAuthenticator( -// $this->clientRegistry, -// $this->router, -// $this->userRepository -// ); -// } - public function testCountryIsFetched(): void { - $this->assertTrue(Countries::exists('AC')); + // TODO move getCountryName to testable unit and update the test + $this->assertFalse(Countries::exists('AC')); } } From 092328b24eccaa0125e127ff04ffed93bdf2540c Mon Sep 17 00:00:00 2001 From: "m::r" Date: Sun, 11 Jan 2026 20:05:11 +0000 Subject: [PATCH 3/3] codestyle fix --- app/tests/Unit/Service/CountriesGeneratorTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/tests/Unit/Service/CountriesGeneratorTest.php b/app/tests/Unit/Service/CountriesGeneratorTest.php index 522ee5c..42e6061 100644 --- a/app/tests/Unit/Service/CountriesGeneratorTest.php +++ b/app/tests/Unit/Service/CountriesGeneratorTest.php @@ -4,12 +4,8 @@ namespace App\Tests\Unit\Service; -use App\Flags\Repository\UserRepository; -use App\Flags\Security\HqAuthAuthenticator; -use KnpU\OAuth2ClientBundle\Client\ClientRegistry; use PHPUnit\Framework\TestCase; use Symfony\Component\Intl\Countries; -use Symfony\Component\Routing\RouterInterface; class CountriesGeneratorTest extends TestCase {