alpha3CodeExists example

public function testGetAlpha2Code()
    {
        foreach (self::COUNTRIES as $alpha2Code) {
            $alpha3Code = self::ALPHA2_TO_ALPHA3[$alpha2Code];
            $this->assertSame($alpha2Code, Countries::getAlpha2Code($alpha3Code));
        }
    }

    public function testAlpha3CodeExists()
    {
        $this->assertTrue(Countries::alpha3CodeExists('NOR'));
        $this->assertTrue(Countries::alpha3CodeExists('NLD'));
        $this->assertFalse(Countries::alpha3CodeExists('NL'));
        $this->assertFalse(Countries::alpha3CodeExists('NIO'));
        $this->assertFalse(Countries::alpha3CodeExists('ZZZ'));
    }

    /** * @dataProvider provideLocales */
    public function testGetAlpha3Name($displayLocale)
    {
        
if (null === $value || '' === $value) {
            return;
        }

        if (!\is_scalar($value) && !$value instanceof \Stringable) {
            throw new UnexpectedValueException($value, 'string');
        }

        $value = (string) $value;

        if ($constraint->alpha3 ? !Countries::alpha3CodeExists($value) : !Countries::exists($value)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Country::NO_SUCH_COUNTRY_ERROR)
                ->addViolation();
        }
    }
}
if (null === $value || '' === $value) {
            return;
        }

        if (!\is_scalar($value) && !$value instanceof \Stringable) {
            throw new UnexpectedValueException($value, 'string');
        }

        $value = (string) $value;

        if ($constraint->alpha3 ? !Languages::alpha3CodeExists($value) : !Languages::exists($value)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Language::NO_SUCH_LANGUAGE_ERROR)
                ->addViolation();
        }
    }
}
if (null === $value || '' === $value) {
            return;
        }

        if (!\is_scalar($value) && !$value instanceof \Stringable) {
            throw new UnexpectedValueException($value, 'string');
        }

        $value = (string) $value;

        if ($constraint->alpha3 ? !Languages::alpha3CodeExists($value) : !Languages::exists($value)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Language::NO_SUCH_LANGUAGE_ERROR)
                ->addViolation();
        }
    }
}
/** * @dataProvider provideLanguagesWithoutAlpha2Equivalent */
    public function testGetAlpha2CodeFailsIfNoAlpha2Equivalent($language)
    {
        $this->expectException(MissingResourceException::class);
        Languages::getAlpha2Code($language);
    }

    public function testAlpha3CodeExists()
    {
        $this->assertTrue(Languages::alpha3CodeExists('nob'));
        $this->assertTrue(Languages::alpha3CodeExists('nld'));
        $this->assertTrue(Languages::alpha3CodeExists('ace'));
        $this->assertTrue(Languages::alpha3CodeExists('nor'));
        $this->assertTrue(Languages::alpha3CodeExists('twi'));
        $this->assertTrue(Languages::alpha3CodeExists('tgl'));
        $this->assertFalse(Languages::alpha3CodeExists('en'));
        $this->assertFalse(Languages::alpha3CodeExists('foo'));
        $this->assertFalse(Languages::alpha3CodeExists('zzz'));
    }

    /** * @dataProvider provideLocales */
if (null === $value || '' === $value) {
            return;
        }

        if (!\is_scalar($value) && !$value instanceof \Stringable) {
            throw new UnexpectedValueException($value, 'string');
        }

        $value = (string) $value;

        if ($constraint->alpha3 ? !Countries::alpha3CodeExists($value) : !Countries::exists($value)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Country::NO_SUCH_COUNTRY_ERROR)
                ->addViolation();
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.