chore: verify the ISO-2 country move and renumber its migration
This commit is contained in:
1 parent
6c0a512c05
commit
169a17e19c
2 files changed
+89
-1
No files matched your search
@@ -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',
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service\Common;
|
||||
|
||||
use App\Model\AbstractFilterDto;
|
||||
use App\Model\AssignmentFilterDto;
|
||||
use App\Service\Common\AbstractFilterHandler;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* destination.country moved from the lowercased BusProNet abbreviations to ISO-2, but a
|
||||
* session written before the deploy still holds the old value, and the filter is restored
|
||||
* from the session rather than from the form. Without the translation those users would
|
||||
* filter for a value no destination carries any more and see an empty list.
|
||||
*
|
||||
* Only a, ch, f and i can ever be in a session: those were the only four the filter forms
|
||||
* offered. All four land inside the new choice list, so no stale value can fall outside it.
|
||||
*/
|
||||
class AbstractFilterHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider legacyCountries
|
||||
*/
|
||||
public function testALegacyCountryIsTranslatedToItsIsoCode(?string $stored, ?string $expected): void
|
||||
{
|
||||
$this->assertSame($expected, $this->handler()->translate($stored));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{0: ?string, 1: ?string}>
|
||||
*/
|
||||
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
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user