From 169a17e19cb0adfba3f0768c2587cd284b913d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Sun, 27 Sep 2026 15:23:36 +0200 Subject: [PATCH] chore: verify the ISO-2 country move and renumber its migration --- ...13120000.php => Version20260927090000.php} | 2 +- .../Common/AbstractFilterHandlerTest.php | 88 +++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) rename migrations/{Version20260813120000.php => Version20260927090000.php} (96%) create mode 100644 tests/Service/Common/AbstractFilterHandlerTest.php diff --git a/migrations/Version20260813120000.php b/migrations/Version20260927090000.php similarity index 96% rename from migrations/Version20260813120000.php rename to migrations/Version20260927090000.php index b9ef624..3765035 100644 --- a/migrations/Version20260813120000.php +++ b/migrations/Version20260927090000.php @@ -16,7 +16,7 @@ use Doctrine\Migrations\AbstractMigration; * existing rows are converted to match. The flag icons and the country filters use the * same vocabulary and are switched with it. */ -final class Version20260813120000 extends AbstractMigration +final class Version20260927090000 extends AbstractMigration { private const TO_ISO = [ 'a' => 'at', diff --git a/tests/Service/Common/AbstractFilterHandlerTest.php b/tests/Service/Common/AbstractFilterHandlerTest.php new file mode 100644 index 0000000..7296b6c --- /dev/null +++ b/tests/Service/Common/AbstractFilterHandlerTest.php @@ -0,0 +1,88 @@ +assertSame($expected, $this->handler()->translate($stored)); + } + + /** + * @return iterable + */ + public static function legacyCountries(): iterable + { + // the four the filter forms offered, which is all a session can hold + yield 'Österreich' => ['a', 'at']; + yield 'Frankreich' => ['f', 'fr']; + yield 'Italien' => ['i', 'it']; + yield 'Schweiz was already ISO' => ['ch', 'ch']; + + // never offered by a filter, so unreachable from a session - translated anyway + yield 'Deutschland' => ['d', 'de']; + yield 'Niederlande was already ISO' => ['nl', 'nl']; + + yield 'no filter set' => [null, null]; + yield 'an already migrated value is left alone' => ['at', 'at']; + yield 'an unknown value is not invented away' => ['xx', 'xx']; + } + + public function testEveryTranslatedValueIsOfferedByTheFilterForm(): void + { + // what AssignmentFilterType and ApplicationFilterType offer + $offered = ['at', 'ch', 'fr', 'it']; + $handler = $this->handler(); + + foreach (['a', 'ch', 'f', 'i'] as $storable) { + $this->assertContains( + $handler->translate($storable), + $offered, + sprintf('A session holding "%s" would filter for a value the form cannot show', $storable), + ); + } + } + + private function handler(): object + { + return new class($this->createMock(RequestStack::class), $this->createMock(EntityManagerInterface::class)) extends AbstractFilterHandler { + protected string $modelClass = AssignmentFilterDto::class; + + public function translate(?string $country): ?string + { + return $this->toIsoCountry($country); + } + + public function getFilterSettings(): AbstractFilterDto + { + return new AssignmentFilterDto(); + } + + protected function saveFilterSettings(AbstractFilterDto $filterDto): void + { + } + }; + } +}