|
12 | 12 | use FormatPHP\Intl\Locale; |
13 | 13 | use FormatPHP\Message; |
14 | 14 | use FormatPHP\MessageCollection; |
| 15 | +use Locale as PhpLocale; |
15 | 16 |
|
16 | 17 | use function date; |
17 | 18 |
|
@@ -304,4 +305,46 @@ public function testFormatTimeUsesProvidedHourMinuteOptions(): void |
304 | 305 | $this->assertSame('2-digit', $options->hour); |
305 | 306 | $this->assertSame('2-digit', $options->minute); |
306 | 307 | } |
| 308 | + |
| 309 | + public function testConstructorWithoutConfiguration(): void |
| 310 | + { |
| 311 | + $date = 1635204852; // Mon, 25 Oct 2021 23:34:12 +0000 |
| 312 | + |
| 313 | + $systemLocale = PhpLocale::getDefault(); |
| 314 | + $locale = new Locale($systemLocale); |
| 315 | + $config = new Config($locale); |
| 316 | + $formatphpForComparison = new FormatPHP($config); |
| 317 | + |
| 318 | + $formatphpWithoutConfig = new FormatPHP(); |
| 319 | + |
| 320 | + $this->assertSame( |
| 321 | + $formatphpForComparison->formatDate($date), |
| 322 | + $formatphpWithoutConfig->formatDate($date), |
| 323 | + ); |
| 324 | + } |
| 325 | + |
| 326 | + public function testConstructorWithoutMessages(): void |
| 327 | + { |
| 328 | + $date = 1635204852; // Mon, 25 Oct 2021 23:34:12 +0000 |
| 329 | + |
| 330 | + $systemLocale = PhpLocale::getDefault(); |
| 331 | + $locale = new Locale($systemLocale); |
| 332 | + $config = new Config($locale); |
| 333 | + $formatphpForComparison = new FormatPHP($config); |
| 334 | + |
| 335 | + $expectedMessageResponse = $formatphpForComparison->formatMessage( |
| 336 | + ['defaultMessage' => 'Today is {ts, date, ::yyyyMMdd}'], |
| 337 | + ['ts' => $date], |
| 338 | + ); |
| 339 | + |
| 340 | + $formatphpWithoutMessages = new FormatPHP(); |
| 341 | + |
| 342 | + $this->assertSame( |
| 343 | + $expectedMessageResponse, |
| 344 | + $formatphpWithoutMessages->formatMessage( |
| 345 | + ['id' => 'myMessage', 'defaultMessage' => 'Today is {ts, date, ::yyyyMMdd}'], |
| 346 | + ['ts' => $date], |
| 347 | + ), |
| 348 | + ); |
| 349 | + } |
307 | 350 | } |
0 commit comments