IntlBundleReaderTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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\Component\Intl\Tests\Data\Bundle\Reader;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Intl\Data\Bundle\Reader\IntlBundleReader;
  13. /**
  14. * @author Bernhard Schussek <bschussek@gmail.com>
  15. * @requires extension intl
  16. */
  17. class IntlBundleReaderTest extends TestCase
  18. {
  19. /**
  20. * @var IntlBundleReader
  21. */
  22. private $reader;
  23. protected function setUp()
  24. {
  25. $this->reader = new IntlBundleReader();
  26. }
  27. public function testReadReturnsArrayAccess()
  28. {
  29. $data = $this->reader->read(__DIR__.'/Fixtures/res', 'ro');
  30. $this->assertInstanceOf('\ArrayAccess', $data);
  31. $this->assertSame('Bar', $data['Foo']);
  32. $this->assertFalse(isset($data['ExistsNot']));
  33. }
  34. public function testReadFollowsAlias()
  35. {
  36. // "alias" = "ro"
  37. $data = $this->reader->read(__DIR__.'/Fixtures/res', 'alias');
  38. $this->assertInstanceOf('\ArrayAccess', $data);
  39. $this->assertSame('Bar', $data['Foo']);
  40. $this->assertFalse(isset($data['ExistsNot']));
  41. }
  42. public function testReadDoesNotFollowFallback()
  43. {
  44. if (defined('HHVM_VERSION')) {
  45. $this->markTestSkipped('ResourceBundle does not support disabling fallback properly on HHVM.');
  46. }
  47. // "ro_MD" -> "ro"
  48. $data = $this->reader->read(__DIR__.'/Fixtures/res', 'ro_MD');
  49. $this->assertInstanceOf('\ArrayAccess', $data);
  50. $this->assertSame('Bam', $data['Baz']);
  51. $this->assertFalse(isset($data['Foo']));
  52. $this->assertNull($data['Foo']);
  53. $this->assertFalse(isset($data['ExistsNot']));
  54. }
  55. public function testReadDoesNotFollowFallbackAlias()
  56. {
  57. if (defined('HHVM_VERSION')) {
  58. $this->markTestSkipped('ResourceBundle does not support disabling fallback properly on HHVM.');
  59. }
  60. // "mo" = "ro_MD" -> "ro"
  61. $data = $this->reader->read(__DIR__.'/Fixtures/res', 'mo');
  62. $this->assertInstanceOf('\ArrayAccess', $data);
  63. $this->assertSame('Bam', $data['Baz'], 'data from the aliased locale can be accessed');
  64. $this->assertFalse(isset($data['Foo']));
  65. $this->assertNull($data['Foo']);
  66. $this->assertFalse(isset($data['ExistsNot']));
  67. }
  68. /**
  69. * @expectedException \Symfony\Component\Intl\Exception\ResourceBundleNotFoundException
  70. */
  71. public function testReadFailsIfNonExistingLocale()
  72. {
  73. $this->reader->read(__DIR__.'/Fixtures/res', 'foo');
  74. }
  75. /**
  76. * @expectedException \Symfony\Component\Intl\Exception\ResourceBundleNotFoundException
  77. */
  78. public function testReadFailsIfNonExistingFallbackLocale()
  79. {
  80. $this->reader->read(__DIR__.'/Fixtures/res', 'ro_AT');
  81. }
  82. /**
  83. * @expectedException \Symfony\Component\Intl\Exception\RuntimeException
  84. */
  85. public function testReadFailsIfNonExistingDirectory()
  86. {
  87. $this->reader->read(__DIR__.'/foo', 'ro');
  88. }
  89. }