getExampleNumber() public method

Gets a valid number for the specified region.
public getExampleNumber ( $regionCode ) : PhoneNumber
return PhoneNumber a valid fixed-line number for the specified region. Returns null when the metadata does not contain such information, or the region 001 is passed in. For 001 (representing non-geographical numbers), call {@link #getExampleNumberForNonGeoEntity} instead.
Esempio n. 1
0
 /**
  * @param string $country
  * @param string $format
  *
  * @return string|NULL
  *
  * @throws Exceptions\NoValidCountryException
  */
 protected function getExampleNumber($country, $format)
 {
     // Check if country is valid
     $country = $this->validateCountry($country);
     // Create example number
     $number = $this->phoneNumberUtil->getExampleNumber($country);
     return $number !== NULL ? $this->phoneNumberUtil->format($number, $format) : NULL;
 }
 /**
  * @dataProvider regionList
  * @param string $regionCode
  */
 public function testEveryRegionHasExampleNumber($regionCode)
 {
     $exampleNumber = $this->phoneNumberUtil->getExampleNumber($regionCode);
     $this->assertNotNull($exampleNumber, "None found for region " . $regionCode);
     /*
      * Check the number is valid
      */
     $e164 = $this->phoneNumberUtil->format($exampleNumber, PhoneNumberFormat::E164);
     $phoneObject = $this->phoneNumberUtil->parse($e164, 'ZZ');
     $this->assertEquals($phoneObject, $exampleNumber);
     $this->assertTrue($this->phoneNumberUtil->isValidNumber($phoneObject));
     $this->assertTrue($this->phoneNumberUtil->isValidNumberForRegion($phoneObject, $regionCode));
 }
 public function testGetExampleNumber()
 {
     $this->assertEquals(self::$deNumber, $this->phoneUtil->getExampleNumber(RegionCode::DE));
     $this->assertEquals(self::$deNumber, $this->phoneUtil->getExampleNumberForType(RegionCode::DE, PhoneNumberType::FIXED_LINE));
     $this->assertEquals(null, $this->phoneUtil->getExampleNumberForType(RegionCode::DE, PhoneNumberType::MOBILE));
     // For the US, the example number is placed under general description, and hence should be used
     // for both fixed line and mobile, so neither of these should return null.
     $this->assertNotNull($this->phoneUtil->getExampleNumberForType(RegionCode::US, PhoneNumberType::FIXED_LINE));
     $this->assertNotNull($this->phoneUtil->getExampleNumberForType(RegionCode::US, PhoneNumberType::MOBILE));
     // CS is an invalid region, so we have no data for it.
     $this->assertNull($this->phoneUtil->getExampleNumberForType(RegionCode::CS, PhoneNumberType::MOBILE));
     // RegionCode 001 is reserved for supporting non-geographical country calling code. We don't
     // support getting an example number for it with this method.
     $this->assertEquals(null, $this->phoneUtil->getExampleNumber(RegionCode::UN001));
 }
 /**
  * @dataProvider regionList
  */
 public function getEveryRegionHasExampleNumber($regionCode)
 {
     $exampleNumber = $this->phoneNumberUtil->getExampleNumber($regionCode);
     $this->assertNotNull($exampleNumber, "None found for region " . $regionCode);
 }