Skip to content

Commit c1932a2

Browse files
Merge branch '4.3' into 4.4
* 4.3: Minor fixes [HttpClient] Minor fixes Use namespaced Phpunit classes [Messenger] Fixed ConsumeMessagesCommand configuration [Form] remove leftover int child phpdoc Support DateTimeInterface in IntlDateFormatter::format [PhpUnitBridge] fixed PHPUnit 8.3 compatibility: method handleError was renamed to __invoke fixed phpdocs Use PHPunit assertion [Intl] Order alpha2 to alpha3 mapping + phpdoc fixes
2 parents 836c959 + 93db0ef commit c1932a2

File tree

10 files changed

+55
-52
lines changed

10 files changed

+55
-52
lines changed

Countries.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ final class Countries extends ResourceBundle
3131
*
3232
* This list only contains "officially assigned ISO 3166-1 alpha-2" country codes.
3333
*
34-
* @return string[] an array of canonical ISO 3166 country codes
34+
* @return string[] an array of canonical ISO 3166 alpha-2 country codes
3535
*/
3636
public static function getCountryCodes(): array
3737
{
3838
return self::readEntry(['Regions'], 'meta');
3939
}
4040

41+
/**
42+
* @param string $country Alpha2 country code
43+
*/
4144
public static function exists(string $country): bool
4245
{
4346
try {
@@ -50,6 +53,8 @@ public static function exists(string $country): bool
5053
}
5154

5255
/**
56+
* Gets the country name from alpha2 code.
57+
*
5358
* @throws MissingResourceException if the country code does not exists
5459
*/
5560
public static function getName(string $country, string $displayLocale = null): string
@@ -58,9 +63,11 @@ public static function getName(string $country, string $displayLocale = null): s
5863
}
5964

6065
/**
66+
* Gets the list of country names indexed with alpha2 codes as keys.
67+
*
6168
* @return string[]
6269
*/
63-
public static function getNames($displayLocale = null)
70+
public static function getNames($displayLocale = null): array
6471
{
6572
return self::asort(self::readEntry(['Names'], $displayLocale), $displayLocale);
6673
}

DateFormatter/IntlDateFormatter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public static function create($locale, $datetype, $timetype, $timezone = null, $
176176
/**
177177
* Format the date/time value (timestamp) as a string.
178178
*
179-
* @param int|\DateTime $timestamp The timestamp to format
179+
* @param int|\DateTimeInterface $timestamp The timestamp to format
180180
*
181181
* @return string|bool The formatted value or false if formatting failed
182182
*
@@ -195,7 +195,7 @@ public function format($timestamp)
195195

196196
// behave like the intl extension
197197
$argumentError = null;
198-
if (!\is_int($timestamp) && !$timestamp instanceof \DateTime) {
198+
if (!\is_int($timestamp) && !$timestamp instanceof \DateTimeInterface) {
199199
$argumentError = sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $timestamp);
200200
}
201201

@@ -207,7 +207,7 @@ public function format($timestamp)
207207
return false;
208208
}
209209

210-
if ($timestamp instanceof \DateTime) {
210+
if ($timestamp instanceof \DateTimeInterface) {
211211
$timestamp = $timestamp->getTimestamp();
212212
}
213213

Languages.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
final class Languages extends ResourceBundle
2323
{
2424
/**
25-
* Returns all available languages.
25+
* Returns all available languages as two-letter codes.
2626
*
2727
* Languages are returned as lowercase ISO 639-1 two-letter language codes.
2828
* For languages that don't have a two-letter code, the ISO 639-2
@@ -31,7 +31,7 @@ final class Languages extends ResourceBundle
3131
* A full table of ISO 639 language codes can be found here:
3232
* http://www-01.sil.org/iso639-3/codes.asp
3333
*
34-
* @return string[] an array of canonical ISO 639 language codes
34+
* @return string[] an array of canonical ISO 639-1 language codes
3535
*/
3636
public static function getLanguageCodes(): array
3737
{
@@ -50,6 +50,8 @@ public static function exists(string $language): bool
5050
}
5151

5252
/**
53+
* Gets the language name from alpha2 code.
54+
*
5355
* @throws MissingResourceException if the language code does not exists
5456
*/
5557
public static function getName(string $language, string $displayLocale = null): string
@@ -58,6 +60,8 @@ public static function getName(string $language, string $displayLocale = null):
5860
}
5961

6062
/**
63+
* Gets the list of language names indexed with alpha2 codes as keys.
64+
*
6165
* @return string[]
6266
*/
6367
public static function getNames(string $displayLocale = null): array
@@ -66,7 +70,7 @@ public static function getNames(string $displayLocale = null): array
6670
}
6771

6872
/**
69-
* Returns the ISO 639-2 three-letter code of a language.
73+
* Returns the ISO 639-2 three-letter code of a language, given a two-letter code.
7074
*
7175
* @throws MissingResourceException if the language has no corresponding three-letter code
7276
*/

Locales.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static function getName(string $locale, string $displayLocale = null): st
6767
/**
6868
* @return string[]
6969
*/
70-
public static function getNames($displayLocale = null)
70+
public static function getNames($displayLocale = null): array
7171
{
7272
return self::asort(self::readEntry(['Names'], $displayLocale), $displayLocale);
7373
}

Scripts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static function getName(string $script, string $displayLocale = null): st
5151
/**
5252
* @return string[]
5353
*/
54-
public static function getNames($displayLocale = null)
54+
public static function getNames($displayLocale = null): array
5555
{
5656
return self::asort(self::readEntry(['Names'], $displayLocale), $displayLocale);
5757
}

Tests/DateFormatter/AbstractIntlDateFormatterTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function testFormat($pattern, $timestamp, $expected)
7676
public function formatProvider()
7777
{
7878
$dateTime = new \DateTime('@0');
79+
$dateTimeImmutable = new \DateTimeImmutable('@0');
7980

8081
$formatData = [
8182
/* general */
@@ -250,6 +251,12 @@ public function formatProvider()
250251
$formatData[] = ['h:mm a', $dateTime, '12:00 AM'];
251252
$formatData[] = ['yyyyy.MMMM.dd hh:mm aaa', $dateTime, '01970.January.01 12:00 AM'];
252253

254+
/* general, DateTimeImmutable */
255+
$formatData[] = ['y-M-d', $dateTimeImmutable, '1970-1-1'];
256+
$formatData[] = ["EEE, MMM d, ''yy", $dateTimeImmutable, "Thu, Jan 1, '70"];
257+
$formatData[] = ['h:mm a', $dateTimeImmutable, '12:00 AM'];
258+
$formatData[] = ['yyyyy.MMMM.dd hh:mm aaa', $dateTimeImmutable, '01970.January.01 12:00 AM'];
259+
253260
if (IcuVersion::compare(Intl::getIcuVersion(), '59.1', '>=', 1)) {
254261
// Before ICU 59.1 GMT was used instead of UTC
255262
$formatData[] = ["yyyy.MM.dd 'at' HH:mm:ss zzz", 0, '1970.01.01 at 00:00:00 UTC'];
@@ -269,6 +276,8 @@ public function testFormatUtcAndGmtAreSplit()
269276

270277
$this->assertSame('1970.01.01 at 00:00:00 GMT', $gmtFormatter->format(new \DateTime('@0')));
271278
$this->assertSame('1970.01.01 at 00:00:00 UTC', $utcFormatter->format(new \DateTime('@0')));
279+
$this->assertSame('1970.01.01 at 00:00:00 GMT', $gmtFormatter->format(new \DateTimeImmutable('@0')));
280+
$this->assertSame('1970.01.01 at 00:00:00 UTC', $utcFormatter->format(new \DateTimeImmutable('@0')));
272281
}
273282

274283
/**

Tests/IntlTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testGetIcuStubVersionReadsTheVersionOfBundledStubs()
7373

7474
public function testGetDataDirectoryReturnsThePathToIcuData()
7575
{
76-
$this->assertTrue(is_dir(Intl::getDataDirectory()));
76+
$this->assertDirectoryExists(Intl::getDataDirectory());
7777
}
7878

7979
/**

Tests/LanguagesTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -644,32 +644,27 @@ class LanguagesTest extends ResourceBundleTestCase
644644
'ab' => 'abk',
645645
'af' => 'afr',
646646
'ak' => 'aka',
647-
'sq' => 'sqi',
648647
'am' => 'amh',
649648
'ar' => 'ara',
650649
'an' => 'arg',
651-
'hy' => 'hye',
652650
'as' => 'asm',
653651
'av' => 'ava',
654652
'ae' => 'ave',
655653
'ay' => 'aym',
656654
'az' => 'aze',
657655
'ba' => 'bak',
658656
'bm' => 'bam',
659-
'eu' => 'eus',
660657
'be' => 'bel',
661658
'bn' => 'ben',
662659
'bi' => 'bis',
663660
'bo' => 'bod',
664661
'bs' => 'bos',
665662
'br' => 'bre',
666663
'bg' => 'bul',
667-
'my' => 'mya',
668664
'ca' => 'cat',
669665
'cs' => 'ces',
670666
'ch' => 'cha',
671667
'ce' => 'che',
672-
'zh' => 'zho',
673668
'cu' => 'chu',
674669
'cv' => 'chv',
675670
'kw' => 'cor',
@@ -679,13 +674,12 @@ class LanguagesTest extends ResourceBundleTestCase
679674
'da' => 'dan',
680675
'de' => 'deu',
681676
'dv' => 'div',
682-
'nl' => 'nld',
683677
'dz' => 'dzo',
684-
'et' => 'est',
685678
'el' => 'ell',
686679
'en' => 'eng',
687680
'eo' => 'epo',
688-
'ik' => 'ipk',
681+
'et' => 'est',
682+
'eu' => 'eus',
689683
'ee' => 'ewe',
690684
'fo' => 'fao',
691685
'fa' => 'fas',
@@ -694,8 +688,6 @@ class LanguagesTest extends ResourceBundleTestCase
694688
'fr' => 'fra',
695689
'fy' => 'fry',
696690
'ff' => 'ful',
697-
'om' => 'orm',
698-
'ka' => 'kat',
699691
'gd' => 'gla',
700692
'ga' => 'gle',
701693
'gl' => 'glg',
@@ -710,32 +702,34 @@ class LanguagesTest extends ResourceBundleTestCase
710702
'ho' => 'hmo',
711703
'hr' => 'hrv',
712704
'hu' => 'hun',
705+
'hy' => 'hye',
713706
'ig' => 'ibo',
714-
'is' => 'isl',
715707
'io' => 'ido',
716708
'ii' => 'iii',
717709
'iu' => 'iku',
718710
'ie' => 'ile',
719711
'ia' => 'ina',
720712
'id' => 'ind',
713+
'ik' => 'ipk',
714+
'is' => 'isl',
721715
'it' => 'ita',
722716
'jv' => 'jav',
723717
'ja' => 'jpn',
724718
'kl' => 'kal',
725719
'kn' => 'kan',
726720
'ks' => 'kas',
721+
'ka' => 'kat',
727722
'kr' => 'kau',
728723
'kk' => 'kaz',
729-
'mn' => 'mon',
730724
'km' => 'khm',
731725
'ki' => 'kik',
732726
'rw' => 'kin',
733727
'ky' => 'kir',
734-
'ku' => 'kur',
735-
'kg' => 'kon',
736728
'kv' => 'kom',
729+
'kg' => 'kon',
737730
'ko' => 'kor',
738731
'kj' => 'kua',
732+
'ku' => 'kur',
739733
'lo' => 'lao',
740734
'la' => 'lat',
741735
'lv' => 'lav',
@@ -745,40 +739,43 @@ class LanguagesTest extends ResourceBundleTestCase
745739
'lb' => 'ltz',
746740
'lu' => 'lub',
747741
'lg' => 'lug',
748-
'mk' => 'mkd',
749742
'mh' => 'mah',
750743
'ml' => 'mal',
751-
'mi' => 'mri',
752744
'mr' => 'mar',
753-
'ms' => 'msa',
745+
'mk' => 'mkd',
754746
'mg' => 'mlg',
755747
'mt' => 'mlt',
748+
'mn' => 'mon',
749+
'mi' => 'mri',
750+
'ms' => 'msa',
751+
'my' => 'mya',
756752
'na' => 'nau',
757753
'nv' => 'nav',
758754
'nr' => 'nbl',
759755
'nd' => 'nde',
760756
'ng' => 'ndo',
761757
'ne' => 'nep',
758+
'nl' => 'nld',
762759
'nn' => 'nno',
763760
'nb' => 'nob',
764761
'ny' => 'nya',
765762
'oc' => 'oci',
766763
'oj' => 'oji',
767764
'or' => 'ori',
765+
'om' => 'orm',
768766
'os' => 'oss',
769767
'pa' => 'pan',
770-
'ps' => 'pus',
771768
'pi' => 'pli',
772769
'pl' => 'pol',
773770
'pt' => 'por',
771+
'ps' => 'pus',
774772
'qu' => 'que',
775773
'rm' => 'roh',
776774
'ro' => 'ron',
777775
'rn' => 'run',
778776
'ru' => 'rus',
779777
'sg' => 'sag',
780778
'sa' => 'san',
781-
'sr' => 'srp',
782779
'si' => 'sin',
783780
'sk' => 'slk',
784781
'sl' => 'slv',
@@ -789,7 +786,9 @@ class LanguagesTest extends ResourceBundleTestCase
789786
'so' => 'som',
790787
'st' => 'sot',
791788
'es' => 'spa',
789+
'sq' => 'sqi',
792790
'sc' => 'srd',
791+
'sr' => 'srp',
793792
'ss' => 'ssw',
794793
'su' => 'sun',
795794
'sw' => 'swa',
@@ -819,6 +818,7 @@ class LanguagesTest extends ResourceBundleTestCase
819818
'yi' => 'yid',
820819
'yo' => 'yor',
821820
'za' => 'zha',
821+
'zh' => 'zho',
822822
'zu' => 'zul',
823823
];
824824

Tests/NumberFormatter/AbstractNumberFormatterTest.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Intl\Tests\NumberFormatter;
1313

14+
use PHPUnit\Framework\Error\Warning;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\Intl\Globals\IntlGlobals;
1617
use Symfony\Component\Intl\NumberFormatter\NumberFormatter;
@@ -323,13 +324,7 @@ public function formatTypeDoubleWithCurrencyStyleProvider()
323324
*/
324325
public function testFormatTypeCurrency($formatter, $value)
325326
{
326-
$exceptionCode = 'PHPUnit\Framework\Error\Warning';
327-
328-
if (class_exists('PHPUnit_Framework_Error_Warning')) {
329-
$exceptionCode = 'PHPUnit_Framework_Error_Warning';
330-
}
331-
332-
$this->expectException($exceptionCode);
327+
$this->expectException(Warning::class);
333328

334329
$formatter->format($value, NumberFormatter::TYPE_CURRENCY);
335330
}
@@ -706,13 +701,7 @@ public function parseProvider()
706701

707702
public function testParseTypeDefault()
708703
{
709-
$exceptionCode = 'PHPUnit\Framework\Error\Warning';
710-
711-
if (class_exists('PHPUnit_Framework_Error_Warning')) {
712-
$exceptionCode = 'PHPUnit_Framework_Error_Warning';
713-
}
714-
715-
$this->expectException($exceptionCode);
704+
$this->expectException(Warning::class);
716705

717706
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
718707
$formatter->parse('1', NumberFormatter::TYPE_DEFAULT);
@@ -832,13 +821,7 @@ public function parseTypeDoubleProvider()
832821

833822
public function testParseTypeCurrency()
834823
{
835-
$exceptionCode = 'PHPUnit\Framework\Error\Warning';
836-
837-
if (class_exists('PHPUnit_Framework_Error_Warning')) {
838-
$exceptionCode = 'PHPUnit_Framework_Error_Warning';
839-
}
840-
841-
$this->expectException($exceptionCode);
824+
$this->expectException(Warning::class);
842825

843826
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
844827
$formatter->parse('1', NumberFormatter::TYPE_CURRENCY);

Tests/Util/GitRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testItClonesTheRepository()
5151
$git = GitRepository::download(self::REPO_URL, $this->targetDir);
5252

5353
$this->assertInstanceOf(GitRepository::class, $git);
54-
$this->assertTrue(is_dir($this->targetDir.'/.git'));
54+
$this->assertDirectoryExists($this->targetDir.'/.git');
5555
$this->assertSame($this->targetDir, $git->getPath());
5656
$this->assertSame(self::REPO_URL, $git->getUrl());
5757
$this->assertRegExp('#^[0-9a-z]{40}$#', $git->getLastCommitHash());

0 commit comments

Comments
 (0)