當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PhoneNumberUtil::truncateTooLongNumber方法代碼示例

本文整理匯總了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);
 }
開發者ID:wasabiNorman,項目名稱:libphonenumber-for-php,代碼行數:49,代碼來源:PhoneNumberUtilTest.php


注:本文中的libphonenumber\PhoneNumberUtil::truncateTooLongNumber方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。