assertSame(['at', 'ch', 'fr', 'it', 'de', 'nl'], DestinationDto::countryCodes()); } /** * @dataProvider isoCountryCodes */ public function testAnIsoCountryCodeIsAccepted(string $code): void { $this->assertCount(0, $this->validateCountry($code)); } /** * The four that the form offered and the constraint refused. * * @dataProvider busProNetCountryAbbreviations */ public function testABusProNetAbbreviationIsNoLongerAccepted(string $abbreviation): void { $this->assertCount(1, $this->validateCountry($abbreviation)); } /** * MyE&P drops a country it cannot map to two letters, so a destination without one is * a normal row rather than an invalid one. */ public function testNoCountryIsAccepted(): void { $this->assertCount(0, $this->validateCountry(null)); } /** * @return iterable */ public static function isoCountryCodes(): iterable { foreach (DestinationDto::countryCodes() as $code) { yield $code => [$code]; } } /** * @return iterable */ public static function busProNetCountryAbbreviations(): iterable { yield 'a' => ['a']; yield 'd' => ['d']; yield 'f' => ['f']; yield 'i' => ['i']; } private function validateCountry(?string $country): ConstraintViolationListInterface { return Validation::createValidatorBuilder() ->enableAttributeMapping() ->getValidator() ->validateProperty((new DestinationDto())->setCountry($country), 'country') ; } }