Gets a valid short number for the specified cost category.
public getExampleShortNumberForCost ( string $regionCode, integer $cost ) : string | ||
$regionCode | string | the region for which an example short number is needed |
$cost | integer | the cost category of number that is needed |
return | string | a valid short number for the specified region and cost category. Returns an empty string when the metadata does not contain such information, or the cost is UNKNOWN_COST. |
public function testGetExampleShortNumberForCost() { $this->assertEquals("3010", $this->shortInfo->getExampleShortNumberForCost(RegionCode::FR, ShortNumberCost::TOLL_FREE)); $this->assertEquals("1023", $this->shortInfo->getExampleShortNumberForCost(RegionCode::FR, ShortNumberCost::STANDARD_RATE)); $this->assertEquals("42000", $this->shortInfo->getExampleShortNumberForCost(RegionCode::FR, ShortNumberCost::PREMIUM_RATE)); $this->assertEquals("", $this->shortInfo->getExampleShortNumberForCost(RegionCode::FR, ShortNumberCost::UNKNOWN_COST)); }
/** * @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 ); } } }