本文整理匯總了PHP中libphonenumber\PhoneNumberUtil::truncateTooLongNumber方法的典型用法代碼示例。如果您正苦於以下問題:PHP PhoneNumberUtil::truncateTooLongNumber方法的具體用法?PHP PhoneNumberUtil::truncateTooLongNumber怎麽用?PHP PhoneNumberUtil::truncateTooLongNumber使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類libphonenumber\PhoneNumberUtil
的用法示例。
在下文中一共展示了PhoneNumberUtil::truncateTooLongNumber方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testTruncateTooLongNumber
public function testTruncateTooLongNumber()
{
// GB number 080 1234 5678, but entered with 4 extra digits at the end.
$tooLongNumber = new PhoneNumber();
$tooLongNumber->setCountryCode(44)->setNationalNumber(80123456780123);
$validNumber = new PhoneNumber();
$validNumber->setCountryCode(44)->setNationalNumber(8012345678);
$this->assertTrue($this->phoneUtil->truncateTooLongNumber($tooLongNumber));
$this->assertEquals($validNumber, $tooLongNumber);
// IT number 022 3456 7890, but entered with 3 extra digits at the end.
$tooLongNumber->clear();
$tooLongNumber->setCountryCode(39)->setNationalNumber(2234567890123)->setItalianLeadingZero(true);
$validNumber->clear();
$validNumber->setCountryCode(39)->setNationalNumber(2234567890)->setItalianLeadingZero(true);
$this->assertTrue($this->phoneUtil->truncateTooLongNumber($tooLongNumber));
$this->assertEquals($validNumber, $tooLongNumber);
// US number 650-253-0000, but entered with one additional digit at the end.
$tooLongNumber->clear();
$tooLongNumber->mergeFrom(self::$usLongNumber);
$this->assertTrue($this->phoneUtil->truncateTooLongNumber($tooLongNumber));
$this->assertEquals(self::$usNumber, $tooLongNumber);
$tooLongNumber->clear();
$tooLongNumber->mergeFrom(self::$internationalTollFreeTooLong);
$this->assertTrue($this->phoneUtil->truncateTooLongNumber($tooLongNumber));
$this->assertEquals(self::$internationalTollFree, $tooLongNumber);
// Tests what happens when a valid number is passed in.
$validNumberCopy = new PhoneNumber();
$validNumberCopy->mergeFrom($validNumber);
$this->assertTrue($this->phoneUtil->truncateTooLongNumber($validNumber));
// Tests the number is not modified.
$this->assertEquals($validNumberCopy, $validNumber);
// Tests what happens when a number with invalid prefix is passed in.
$numberWithInvalidPrefix = new PhoneNumber();
// The test metadata says US numbers cannot have prefix 240.
$numberWithInvalidPrefix->setCountryCode(1)->setNationalNumber(2401234567);
$invalidNumberCopy = new PhoneNumber();
$invalidNumberCopy->mergeFrom($numberWithInvalidPrefix);
$this->assertFalse($this->phoneUtil->truncateTooLongNumber($numberWithInvalidPrefix));
// Tests the number is not modified.
$this->assertEquals($invalidNumberCopy, $numberWithInvalidPrefix);
// Tests what happens when a too short number is passed in.
$tooShortNumber = new PhoneNumber();
$tooShortNumber->setCountryCode(1)->setNationalNumber(1234);
$tooShortNumberCopy = new PhoneNumber();
$tooShortNumberCopy->mergeFrom($tooShortNumber);
$this->assertFalse($this->phoneUtil->truncateTooLongNumber($tooShortNumber));
// Tests the number is not modified.
$this->assertEquals($tooShortNumberCopy, $tooShortNumber);
}