Skip to content

Commit 93db0ef

Browse files
Merge branch '3.4' into 4.3
* 3.4: Minor fixes Use namespaced Phpunit classes [Form] remove leftover int child phpdoc Support DateTimeInterface in IntlDateFormatter::format [PhpUnitBridge] fixed PHPUnit 8.3 compatibility: method handleError was renamed to __invoke Use PHPunit assertion
2 parents c678a8b + 0fdc637 commit 93db0ef

File tree

5 files changed

+18
-26
lines changed

5 files changed

+18
-26
lines changed

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

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/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)