StubIntlDateFormatterTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Locale\Stub;
  11. use Symfony\Component\Locale\Locale;
  12. use Symfony\Component\Locale\Stub\StubIntlDateFormatter;
  13. class StubIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function formatProvider()
  16. {
  17. return array(
  18. array('y-M-d', 0, '1970-1-1'),
  19. /* months */
  20. array('M', 0, '1'),
  21. array('MM', 0, '01'),
  22. array('MMM', 0, 'Jan'),
  23. array('MMMM', 0, 'January'),
  24. array('MMMMM', 0, 'J'),
  25. /* this is stupid */
  26. array('MMMMMM', 0, '00001'),
  27. /* years */
  28. array('y', 0, '1970'),
  29. array('yy', 0, '70'),
  30. array('yyy', 0, '1970'),
  31. array('yyyy', 0, '1970'),
  32. array('yyyyy', 0, '01970'),
  33. array('yyyyyy', 0, '001970'),
  34. /* day */
  35. array('d', 0, '1'),
  36. array('dd', 0, '01'),
  37. array('ddd', 0, '001'),
  38. );
  39. }
  40. /**
  41. * @expectedException InvalidArgumentException
  42. */
  43. public function testConstructorWithUnsupportedLocale()
  44. {
  45. $formatter = new StubIntlDateFormatter('pt_BR', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
  46. }
  47. public function testConstructor()
  48. {
  49. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, 'UTC', StubIntlDateFormatter::GREGORIAN, 'Y-M-d');
  50. $this->assertEquals('Y-M-d', $formatter->getPattern());
  51. }
  52. /**
  53. * @dataProvider formatProvider
  54. */
  55. public function testFormat($pattern, $timestamp, $expected)
  56. {
  57. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, 'UTC', StubIntlDateFormatter::GREGORIAN, $pattern);
  58. $this->assertEquals($expected, $formatter->format($timestamp));
  59. if (extension_loaded('intl')) {
  60. $formatter = new \IntlDateFormatter('en', \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
  61. $this->assertEquals($expected, $formatter->format($timestamp));
  62. }
  63. }
  64. /**
  65. * @expectedException RuntimeException
  66. */
  67. public function testGetCalendar()
  68. {
  69. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
  70. $formatter->getCalendar();
  71. }
  72. }