TODO: Make this method public when we have enough metadata to make it worthwhile.
public canBeInternationallyDialled ( |
||
$number | the phone-number for which we want to know whether it is diallable from outside the region | |
return | boolean |
public function testCanBeInternationallyDialled() { // We have no-international-dialling rules for the US in our test metadata that say that // toll-free numbers cannot be dialled internationally. $this->assertFalse($this->phoneUtil->canBeInternationallyDialled(self::$usTollFree)); // Normal US numbers can be internationally dialled. $this->assertTrue($this->phoneUtil->canBeInternationallyDialled(self::$usNumber)); // Invalid number. $this->assertTrue($this->phoneUtil->canBeInternationallyDialled(self::$usLocalNumber)); // We have no data for NZ - should return true. $this->assertTrue($this->phoneUtil->canBeInternationallyDialled(self::$nzNumber)); $this->assertTrue($this->phoneUtil->canBeInternationallyDialled(self::$internationalTollFree)); }
/** * @dataProvider regionList */ public function testCanBeInternationallyDialled($regionCode) { $exampleNumber = null; /** @var \libphonenumber\PhoneNumberDesc $desc */ $desc = $this->phoneNumberUtil->getMetadataForRegion($regionCode)->getNoInternationalDialling(); try { if ($desc->hasExampleNumber()) { $exampleNumber = $this->phoneNumberUtil->parse($desc->getExampleNumber(), $regionCode); } } catch (NumberParseException $e) { } if ($exampleNumber !== null && $this->phoneNumberUtil->canBeInternationallyDialled($exampleNumber)) { $this->fail("Number {$exampleNumber} should not be internationally diallable"); } }