getExampleShortNumber() public method

Gets a valid short number for the specified region.
public getExampleShortNumber ( $regionCode ) : string
$regionCode String the region for which an example short number is needed
return string a valid short number for the specified region. Returns an empty string when the metadata does not contain such information.
 public function testGetExampleShortNumber()
 {
     $this->assertEquals("8711", $this->shortInfo->getExampleShortNumber(RegionCode::AM));
     $this->assertEquals("1010", $this->shortInfo->getExampleShortNumber(RegionCode::FR));
     $this->assertEquals("", $this->shortInfo->getExampleShortNumber(RegionCode::UN001));
     $this->assertEquals("", $this->shortInfo->getExampleShortNumber(null));
 }
Ejemplo n.º 2
0
    /**
     * @dataProvider shortNumberRegionList
     */
    public function testShortNumbersValidAndCorrectCost($regionCode)
    {
        $exampleShortNumber = $this->shortNumberInfo->getExampleShortNumber($regionCode);
        if (!$this->shortNumberInfo->isValidShortNumberForRegion(
            $this->phoneNumberUtil->parse($exampleShortNumber, $regionCode),
            $regionCode
        )
        ) {
            $this->fail(
                "Failed validation for string region_code: {$regionCode}, national_number: {$exampleShortNumber}"
            );
        }
        $phoneNumber = $this->phoneNumberUtil->parse($exampleShortNumber, $regionCode);
        if (!$this->shortNumberInfo->isValidShortNumber($phoneNumber)) {
            $this->fail("Failed validation for " . (string)$phoneNumber);
        }

        $costArray = array(
            ShortNumberCost::PREMIUM_RATE,
            ShortNumberCost::STANDARD_RATE,
            ShortNumberCost::TOLL_FREE,
            ShortNumberCost::UNKNOWN_COST
        );

        foreach ($costArray as $cost) {
            $exampleShortNumber = $this->shortNumberInfo->getExampleShortNumberForCost($regionCode, $cost);
            if ($exampleShortNumber != '') {
                $this->assertEquals(
                    $cost,
                    $this->shortNumberInfo->getExpectedCostForRegion($this->phoneNumberUtil->parse($exampleShortNumber, $regionCode), $regionCode),
                    "Wrong cost for " . (string)$phoneNumber
                );
            }
        }
    }