StubIntlDateFormatterTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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. require_once __DIR__.'/../TestCase.php';
  12. use Symfony\Component\Locale\Locale;
  13. use Symfony\Component\Locale\Stub\StubIntlDateFormatter;
  14. use Symfony\Tests\Component\Locale\TestCase as LocaleTestCase;
  15. class StubIntlDateFormatterTest extends LocaleTestCase
  16. {
  17. /**
  18. * @expectedException Symfony\Component\Locale\Exception\MethodArgumentValueNotImplementedException
  19. */
  20. public function testConstructorWithUnsupportedLocale()
  21. {
  22. $formatter = new StubIntlDateFormatter('pt_BR', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
  23. }
  24. public function testConstructor()
  25. {
  26. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, 'UTC', StubIntlDateFormatter::GREGORIAN, 'Y-M-d');
  27. $this->assertEquals('Y-M-d', $formatter->getPattern());
  28. }
  29. /**
  30. * @dataProvider formatProvider
  31. */
  32. public function testFormatStub($pattern, $timestamp, $expected)
  33. {
  34. $formatter = $this->createStubFormatter($pattern);
  35. $this->assertSame($expected, $formatter->format($timestamp));
  36. }
  37. /**
  38. * @dataProvider formatProvider
  39. */
  40. public function testFormatIntl($pattern, $timestamp, $expected)
  41. {
  42. $this->skipIfIntlExtensionIsNotLoaded();
  43. $formatter = $this->createIntlFormatter($pattern);
  44. $this->assertSame($expected, $formatter->format($timestamp));
  45. }
  46. public function formatProvider()
  47. {
  48. $formatData = array(
  49. /* general */
  50. array('y-M-d', 0, '1970-1-1'),
  51. array("yyyy.MM.dd G 'at' HH:mm:ss zzz", 0, '1970.01.01 AD at 00:00:00 GMT+00:00'),
  52. array("EEE, MMM d, ''yy", 0, "Thu, Jan 1, '70"),
  53. array('h:mm a', 0, '12:00 AM'),
  54. array('K:mm a, z', 0, '0:00 AM, GMT+00:00'),
  55. array('yyyyy.MMMM.dd GGG hh:mm aaa', 0, '01970.January.01 AD 12:00 AM'),
  56. /* escaping */
  57. array("'M'", 0, 'M'),
  58. array("'yy'", 0, 'yy'),
  59. array("'''yy'", 0, "'yy"),
  60. array("''y", 0, "'1970"),
  61. array("''yy", 0, "'70"),
  62. array("H 'o'' clock'", 0, "0 o' clock"),
  63. /* month */
  64. array('M', 0, '1'),
  65. array('MM', 0, '01'),
  66. array('MMM', 0, 'Jan'),
  67. array('MMMM', 0, 'January'),
  68. array('MMMMM', 0, 'J'),
  69. array('MMMMMM', 0, '000001'),
  70. array('L', 0, '1'),
  71. array('LL', 0, '01'),
  72. array('LLL', 0, 'Jan'),
  73. array('LLLL', 0, 'January'),
  74. array('LLLLL', 0, 'J'),
  75. array('LLLLLL', 0, '000001'),
  76. /* year */
  77. array('y', 0, '1970'),
  78. array('yy', 0, '70'),
  79. array('yyy', 0, '1970'),
  80. array('yyyy', 0, '1970'),
  81. array('yyyyy', 0, '01970'),
  82. array('yyyyyy', 0, '001970'),
  83. /* day */
  84. array('d', 0, '1'),
  85. array('dd', 0, '01'),
  86. array('ddd', 0, '001'),
  87. /* era */
  88. array('G', 0, 'AD'),
  89. /* quarter */
  90. array('Q', 0, '1'),
  91. array('QQ', 0, '01'),
  92. array('QQQ', 0, 'Q1'),
  93. array('QQQQ', 0, '1st quarter'),
  94. array('QQQQQ', 0, '1st quarter'),
  95. array('q', 0, '1'),
  96. array('qq', 0, '01'),
  97. array('qqq', 0, 'Q1'),
  98. array('qqqq', 0, '1st quarter'),
  99. array('qqqqq', 0, '1st quarter'),
  100. // 4 months
  101. array('Q', 7776000, '2'),
  102. array('QQ', 7776000, '02'),
  103. array('QQQ', 7776000, 'Q2'),
  104. array('QQQQ', 7776000, '2nd quarter'),
  105. // 7 months
  106. array('QQQQ', 15638400, '3rd quarter'),
  107. // 10 months
  108. array('QQQQ', 23587200, '4th quarter'),
  109. /* 12-hour (1-12) */
  110. array('h', 0, '12'),
  111. array('hh', 0, '12'),
  112. array('hhh', 0, '012'),
  113. array('h', 1, '12'),
  114. array('h', 3600, '1'),
  115. array('h', 43200, '12'), // 12 hours
  116. /* day of year */
  117. array('D', 0, '1'),
  118. array('D', 86400, '2'), // 1 day
  119. array('D', 31536000, '1'), // 1 year
  120. array('D', 31622400, '2'), // 1 year + 1 day
  121. /* day of week */
  122. array('E', 0, 'Thu'),
  123. array('EE', 0, 'Thu'),
  124. array('EEE', 0, 'Thu'),
  125. array('EEEE', 0, 'Thursday'),
  126. array('EEEEE', 0, 'T'),
  127. array('EEEEEE', 0, 'Thu'),
  128. array('E', 1296540000, 'Tue'), // 2011-02-01
  129. array('E', 1296950400, 'Sun'), // 2011-02-06
  130. /* am/pm marker */
  131. array('a', 0, 'AM'),
  132. array('aa', 0, 'AM'),
  133. array('aaa', 0, 'AM'),
  134. array('aaaa', 0, 'AM'),
  135. // 12 hours
  136. array('a', 43200, 'PM'),
  137. array('aa', 43200, 'PM'),
  138. array('aaa', 43200, 'PM'),
  139. array('aaaa', 43200, 'PM'),
  140. /* 24-hour (0-23) */
  141. array('H', 0, '0'),
  142. array('HH', 0, '00'),
  143. array('HHH', 0, '000'),
  144. array('H', 1, '0'),
  145. array('H', 3600, '1'),
  146. array('H', 43200, '12'),
  147. array('H', 46800, '13'),
  148. /* 24-hour (1-24) */
  149. array('k', 0, '24'),
  150. array('kk', 0, '24'),
  151. array('kkk', 0, '024'),
  152. array('k', 1, '24'),
  153. array('k', 3600, '1'),
  154. array('k', 43200, '12'),
  155. array('k', 46800, '13'),
  156. /* 12-hour (0-11) */
  157. array('K', 0, '0'),
  158. array('KK', 0, '00'),
  159. array('KKK', 0, '000'),
  160. array('K', 1, '0'),
  161. array('K', 3600, '1'),
  162. array('K', 43200, '0'), // 12 hours
  163. /* minute */
  164. array('m', 0, '0'),
  165. array('mm', 0, '00'),
  166. array('mmm', 0, '000'),
  167. array('m', 1, '0'),
  168. array('m', 60, '1'),
  169. array('m', 120, '2'),
  170. array('m', 180, '3'),
  171. array('m', 3600, '0'),
  172. array('m', 3660, '1'),
  173. array('m', 43200, '0'), // 12 hours
  174. /* second */
  175. array('s', 0, '0'),
  176. array('ss', 0, '00'),
  177. array('sss', 0, '000'),
  178. array('s', 1, '1'),
  179. array('s', 2, '2'),
  180. array('s', 5, '5'),
  181. array('s', 30, '30'),
  182. array('s', 59, '59'),
  183. array('s', 60, '0'),
  184. array('s', 120, '0'),
  185. array('s', 180, '0'),
  186. array('s', 3600, '0'),
  187. array('s', 3601, '1'),
  188. array('s', 3630, '30'),
  189. array('s', 43200, '0'), // 12 hours
  190. /* timezone */
  191. array('z', 0, 'GMT+00:00'),
  192. array('zz', 0, 'GMT+00:00'),
  193. array('zzz', 0, 'GMT+00:00'),
  194. array('zzzz', 0, 'GMT+00:00'),
  195. array('zzzzz', 0, 'GMT+00:00'),
  196. );
  197. // BC era has huge negative unix timestamp
  198. // so testing it requires 64bit
  199. if ($this->is64Bit()) {
  200. $formatData = array_merge($formatData, array(
  201. array('G', -62167222800, 'BC'),
  202. ));
  203. }
  204. return $formatData;
  205. }
  206. /**
  207. * @dataProvider formatWithTimezoneProvider
  208. */
  209. public function testFormatWithTimezoneStub($timestamp, $timezone, $expected)
  210. {
  211. $pattern = 'yyyy-MM-dd HH:mm:ss';
  212. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, $timezone, StubIntlDateFormatter::GREGORIAN, $pattern);
  213. $this->assertSame($expected, $formatter->format($timestamp));
  214. }
  215. /**
  216. * @dataProvider formatWithTimezoneProvider
  217. */
  218. public function testFormatWithTimezoneIntl($timestamp, $timezone, $expected)
  219. {
  220. $this->skipIfIntlExtensionIsNotLoaded();
  221. $pattern = 'yyyy-MM-dd HH:mm:ss';
  222. $formatter = new \IntlDateFormatter('en', \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, $timezone, \IntlDateFormatter::GREGORIAN, $pattern);
  223. $this->assertSame($expected, $formatter->format($timestamp));
  224. }
  225. public function formatWithTimezoneProvider()
  226. {
  227. return array(
  228. array(0, 'UTC', '1970-01-01 00:00:00'),
  229. array(0, 'Europe/Zurich', '1970-01-01 01:00:00'),
  230. array(0, 'Europe/Paris', '1970-01-01 01:00:00'),
  231. array(0, 'Africa/Cairo', '1970-01-01 02:00:00'),
  232. array(0, 'Africa/Casablanca', '1970-01-01 00:00:00'),
  233. array(0, 'Africa/Djibouti', '1970-01-01 03:00:00'),
  234. array(0, 'Africa/Johannesburg', '1970-01-01 02:00:00'),
  235. array(0, 'America/Antigua', '1969-12-31 20:00:00'),
  236. array(0, 'America/Toronto', '1969-12-31 19:00:00'),
  237. array(0, 'America/Vancouver', '1969-12-31 16:00:00'),
  238. array(0, 'Asia/Aqtau', '1970-01-01 05:00:00'),
  239. array(0, 'Asia/Bangkok', '1970-01-01 07:00:00'),
  240. array(0, 'Asia/Dubai', '1970-01-01 04:00:00'),
  241. array(0, 'Australia/Brisbane', '1970-01-01 10:00:00'),
  242. array(0, 'Australia/Melbourne', '1970-01-01 10:00:00'),
  243. array(0, 'Europe/Berlin', '1970-01-01 01:00:00'),
  244. array(0, 'Europe/Dublin', '1970-01-01 01:00:00'),
  245. array(0, 'Europe/Warsaw', '1970-01-01 01:00:00'),
  246. array(0, 'Pacific/Fiji', '1970-01-01 12:00:00'),
  247. array(0, 'Foo/Bar', '1970-01-01 00:00:00'),
  248. );
  249. }
  250. /**
  251. * @expectedException Symfony\Component\Locale\Exception\NotImplementedException
  252. */
  253. public function testFormatWithUnimplementedCharsStub()
  254. {
  255. $pattern = 'Y';
  256. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, 'UTC', StubIntlDateFormatter::GREGORIAN, $pattern);
  257. $formatter->format(0);
  258. }
  259. /**
  260. * @dataProvider dateAndTimeTypeProvider
  261. */
  262. public function testDateAndTimeTypeStub($timestamp, $datetype, $timetype, $expected)
  263. {
  264. $formatter = new StubIntlDateFormatter('en', $datetype, $timetype, 'UTC');
  265. $this->assertSame($expected, $formatter->format($timestamp));
  266. }
  267. /**
  268. * @dataProvider dateAndTimeTypeProvider
  269. */
  270. public function testDateAndTimeTypeIntl($timestamp, $datetype, $timetype, $expected)
  271. {
  272. $this->skipIfIntlExtensionIsNotLoaded();
  273. $formatter = new \IntlDateFormatter('en', $datetype, $timetype, 'UTC');
  274. $this->assertSame($expected, $formatter->format($timestamp));
  275. }
  276. public function dateAndTimeTypeProvider()
  277. {
  278. return array(
  279. array(0, StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE, 'Thursday, January 1, 1970'),
  280. array(0, StubIntlDateFormatter::LONG, StubIntlDateFormatter::NONE, 'January 1, 1970'),
  281. array(0, StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::NONE, 'Jan 1, 1970'),
  282. array(0, StubIntlDateFormatter::SHORT, StubIntlDateFormatter::NONE, '1/1/70'),
  283. array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::FULL, '12:00:00 AM GMT+00:00'),
  284. array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::LONG, '12:00:00 AM GMT+00:00'),
  285. array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::MEDIUM, '12:00:00 AM'),
  286. array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::SHORT, '12:00 AM'),
  287. );
  288. }
  289. public function testGetCalendar()
  290. {
  291. $formatter = $this->createStubFormatter();
  292. $this->assertEquals(StubIntlDateFormatter::GREGORIAN, $formatter->getCalendar());
  293. }
  294. public function testGetDateType()
  295. {
  296. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE);
  297. $this->assertEquals(StubIntlDateFormatter::FULL, $formatter->getDateType());
  298. }
  299. public function testGetErrorCode()
  300. {
  301. $formatter = $this->createStubFormatter();
  302. $this->assertEquals(StubIntlDateFormatter::U_ZERO_ERROR, $formatter->getErrorCode());
  303. }
  304. public function testGetErrorMessage()
  305. {
  306. $formatter = $this->createStubFormatter();
  307. $this->assertEquals(StubIntlDateFormatter::U_ZERO_ERROR_MESSAGE, $formatter->getErrorMessage());
  308. }
  309. public function testGetLocale()
  310. {
  311. $formatter = $this->createStubFormatter();
  312. $this->assertEquals('en', $formatter->getLocale());
  313. }
  314. public function testGetPattern()
  315. {
  316. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE, 'UTC', StubIntlDateFormatter::GREGORIAN, 'yyyy-MM-dd');
  317. $this->assertEquals('yyyy-MM-dd', $formatter->getPattern());
  318. }
  319. public function testGetTimeType()
  320. {
  321. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::NONE, StubIntlDateFormatter::FULL);
  322. $this->assertEquals(StubIntlDateFormatter::FULL, $formatter->getTimeType());
  323. }
  324. /**
  325. * @dataProvider timeZoneIdProvider
  326. */
  327. public function testGetTimeZoneIdStub($timeZoneId)
  328. {
  329. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE, $timeZoneId);
  330. $this->assertEquals($timeZoneId, $formatter->getTimeZoneId());
  331. }
  332. /**
  333. * @dataProvider timeZoneIdProvider
  334. */
  335. public function testGetTimeZoneIdIntl($timeZoneId)
  336. {
  337. $this->skipIfIntlExtensionIsNotLoaded();
  338. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, $timeZoneId);
  339. $this->assertEquals($timeZoneId, $formatter->getTimeZoneId());
  340. }
  341. public function timeZoneIdProvider()
  342. {
  343. return array(
  344. array('Europe/Zurich'),
  345. array('Asia/Dubai'),
  346. );
  347. }
  348. /**
  349. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  350. */
  351. public function testIsLenient()
  352. {
  353. $formatter = $this->createStubFormatter();
  354. $formatter->isLenient();
  355. }
  356. /**
  357. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  358. */
  359. public function testLocaltime()
  360. {
  361. $formatter = $this->createStubFormatter();
  362. $formatter->localtime('Wednesday, December 31, 1969 4:00:00 PM PT');
  363. }
  364. /**
  365. * @dataProvider parseProvider
  366. */
  367. public function testParseIntl($pattern, $value, $expected)
  368. {
  369. $formatter = $this->createIntlFormatter($pattern);
  370. $this->assertEquals($expected, $formatter->parse($value));
  371. }
  372. /**
  373. * @dataProvider parseProvider
  374. */
  375. public function testParseStub($pattern, $value, $expected)
  376. {
  377. $formatter = $this->createStubFormatter($pattern);
  378. $this->assertEquals($expected, $formatter->parse($value));
  379. }
  380. public function parseProvider()
  381. {
  382. return array(
  383. // years
  384. array('y-M-d', '1970-1-1', 0),
  385. // TODO: review to support or not this variant
  386. // array('yy-M-d', '70-1-1', 0),
  387. // months
  388. array('y-M-d', '1970-1-1', 0),
  389. array('y-MMM-d', '1970-Jan-1', 0),
  390. array('y-MMMM-d', '1970-January-1', 0),
  391. // 1 char month
  392. array('y-MMMMM-d', '1970-J-1', false),
  393. array('y-MMMMM-d', '1970-S-1', false),
  394. // standalone months
  395. array('y-L-d', '1970-1-1', 0),
  396. array('y-LLL-d', '1970-Jan-1', 0),
  397. array('y-LLLL-d', '1970-January-1', 0),
  398. // standalone 1 char month
  399. array('y-LLLLL-d', '1970-J-1', false),
  400. array('y-LLLLL-d', '1970-S-1', false),
  401. // days
  402. array('y-M-d', '1970-1-1', 0),
  403. array('y-M-dd', '1970-1-01', 0),
  404. array('y-M-ddd', '1970-1-001', 0),
  405. // 12 hours (1-12)
  406. array('y-M-d h', '1970-1-1 1', 3600),
  407. array('y-M-d h', '1970-1-1 10', 36000),
  408. array('y-M-d hh', '1970-1-1 11', 39600),
  409. array('y-M-d hh', '1970-1-1 12', 0),
  410. array('y-M-d hh a', '1970-1-1 12 AM', 0),
  411. array('y-M-d hh a', '1970-1-1 12 PM', 43200),
  412. array('y-M-d hh a', '1970-1-1 11 AM', 39600),
  413. array('y-M-d hh a', '1970-1-1 11 PM', 82800),
  414. // 12 hours (0-11)
  415. array('y-M-d K', '1970-1-1 1', 3600),
  416. array('y-M-d K', '1970-1-1 10', 36000),
  417. array('y-M-d KK', '1970-1-1 11', 39600),
  418. array('y-M-d KK', '1970-1-1 12', 43200),
  419. array('y-M-d KK a', '1970-1-1 12 AM', 43200),
  420. array('y-M-d KK a', '1970-1-1 12 PM', 86400),
  421. array('y-M-d KK a', '1970-1-1 10 AM', 36000),
  422. array('y-M-d KK a', '1970-1-1 10 PM', 79200),
  423. // 24 hours (0-23)
  424. array('y-M-d H', '1970-1-1 0', 0),
  425. array('y-M-d H', '1970-1-1 1', 3600),
  426. array('y-M-d H', '1970-1-1 10', 36000),
  427. array('y-M-d HH', '1970-1-1 11', 39600),
  428. array('y-M-d HH', '1970-1-1 12', 43200),
  429. array('y-M-d HH', '1970-1-1 23', 82800),
  430. array('y-M-d HH a', '1970-1-1 11 AM', 0),
  431. array('y-M-d HH a', '1970-1-1 12 AM', 0),
  432. array('y-M-d HH a', '1970-1-1 23 AM', 0),
  433. // 24 hours (1-24)
  434. array('y-M-d k', '1970-1-1 1', 3600),
  435. array('y-M-d k', '1970-1-1 10', 36000),
  436. array('y-M-d kk', '1970-1-1 11', 39600),
  437. array('y-M-d kk', '1970-1-1 12', 43200),
  438. array('y-M-d kk', '1970-1-1 23', 82800),
  439. array('y-M-d kk', '1970-1-1 24', 0),
  440. array('y-M-d kk a', '1970-1-1 11 AM', 0),
  441. array('y-M-d kk a', '1970-1-1 12 AM', 0),
  442. array('y-M-d kk a', '1970-1-1 23 AM', 0),
  443. // minutes
  444. array('y-M-d HH:m', '1970-1-1 0:1', 60),
  445. array('y-M-d HH:mm', '1970-1-1 0:10', 600),
  446. // seconds
  447. array('y-M-d HH:mm:s', '1970-1-1 00:01:1', 61),
  448. array('y-M-d HH:mm:ss', '1970-1-1 00:01:10', 70),
  449. // timezone
  450. array('y-M-d HH:mm:ss zzzz', '1970-1-1 00:00:00 GMT-03:00', 10800),
  451. array('y-M-d HH:mm:ss zzzz', '1970-1-1 00:00:00 GMT-04:00', 14400),
  452. array('y-M-d HH:mm:ss zzzz', '1970-1-1 00:00:00 GMT-00:00', 0),
  453. array('y-M-d HH:mm:ss zzzz', '1970-1-1 00:00:00 GMT+03:00', -10800),
  454. array('y-M-d HH:mm:ss zzzz', '1970-1-1 00:00:00 GMT+04:00', -14400),
  455. // a previous timezoned parsing should not change the timezone for the next parsing
  456. array('y-M-d HH:mm:ss', '1970-1-1 00:00:00', 0)
  457. );
  458. }
  459. /**
  460. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  461. */
  462. public function testSetCalendar()
  463. {
  464. $formatter = $this->createStubFormatter();
  465. $formatter->setCalendar(StubIntlDateFormatter::GREGORIAN);
  466. }
  467. /**
  468. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  469. */
  470. public function testSetLenient()
  471. {
  472. $formatter = $this->createStubFormatter();
  473. $formatter->setLenient(true);
  474. }
  475. public function testSetPattern()
  476. {
  477. $formatter = $this->createStubFormatter();
  478. $formatter->setPattern('yyyy-MM-dd');
  479. $this->assertEquals('yyyy-MM-dd', $formatter->getPattern());
  480. }
  481. public function testSetTimeZoneIdStub()
  482. {
  483. $formatter = $this->createStubFormatter();
  484. $this->assertEquals('UTC', $formatter->getTimeZoneId());
  485. $formatter->setTimeZoneId('Europe/Zurich');
  486. $this->assertEquals('Europe/Zurich', $formatter->getTimeZoneId());
  487. }
  488. public function testSetTimeZoneIdIntl()
  489. {
  490. $this->skipIfIntlExtensionIsNotLoaded();
  491. $formatter = $this->createIntlFormatter();
  492. $this->assertEquals('UTC', $formatter->getTimeZoneId());
  493. $formatter->setTimeZoneId('Europe/Zurich');
  494. $this->assertEquals('Europe/Zurich', $formatter->getTimeZoneId());
  495. }
  496. public function testStaticCreate()
  497. {
  498. $formatter = StubIntlDateFormatter::create('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
  499. $this->assertInstanceOf('Symfony\Component\Locale\Stub\StubIntlDateFormatter', $formatter);
  500. }
  501. protected function createStubFormatter($pattern = null)
  502. {
  503. return new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, 'UTC', StubIntlDateFormatter::GREGORIAN, $pattern);
  504. }
  505. protected function createIntlFormatter($pattern = null)
  506. {
  507. return new \IntlDateFormatter('en', \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
  508. }
  509. }