StubIntlDateFormatterTest.php 21 KB

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