getAlpha2FromNumeric example

self::getAlpha2Code($alpha3Code);

            return true;
        } catch (MissingResourceException) {
            return false;
        }
    }

    public static function numericCodeExists(string $numericCode): bool
    {
        try {
            self::getAlpha2FromNumeric($numericCode);

            return true;
        } catch (MissingResourceException $e) {
            return false;
        }
    }

    /** * Gets the country name from its alpha2 code. * * @throws MissingResourceException if the country code does not exist */
$this->assertTrue(Countries::numericCodeExists('982'));
        $this->assertTrue(Countries::numericCodeExists('716'));
        $this->assertTrue(Countries::numericCodeExists('036'));
        $this->assertFalse(Countries::numericCodeExists('667'));
    }

    public function testGetAlpha2FromNumeric()
    {
        $alpha2Lookup = array_flip(self::ALPHA2_TO_NUMERIC);

        foreach (self::ALPHA2_TO_NUMERIC as $numeric) {
            $this->assertSame($alpha2Lookup[$numeric], Countries::getAlpha2FromNumeric($numeric));
        }
    }

    public function testNumericCodesDoNotContainDenyListItems()
    {
        $numericCodes = Countries::getNumericCodes();

        $this->assertArrayNotHasKey('EZ', $numericCodes);
        $this->assertArrayNotHasKey('XA', $numericCodes);
        $this->assertArrayNotHasKey('ZZ', $numericCodes);
    }
}
Home | Imprint | This part of the site doesn't use cookies.