JsonBundleReaderTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\JsonBundleReader;
  13. /**
  14. * @author Bernhard Schussek <bschussek@gmail.com>
  15. */
  16. class JsonBundleReaderTest extends TestCase
  17. {
  18. /**
  19. * @var JsonBundleReader
  20. */
  21. private $reader;
  22. protected function setUp()
  23. {
  24. $this->reader = new JsonBundleReader();
  25. }
  26. public function testReadReturnsArray()
  27. {
  28. $data = $this->reader->read(__DIR__.'/Fixtures/json', 'en');
  29. $this->assertInternalType('array', $data);
  30. $this->assertSame('Bar', $data['Foo']);
  31. $this->assertFalse(isset($data['ExistsNot']));
  32. }
  33. /**
  34. * @expectedException \Symfony\Component\Intl\Exception\ResourceBundleNotFoundException
  35. */
  36. public function testReadFailsIfNonExistingLocale()
  37. {
  38. $this->reader->read(__DIR__.'/Fixtures/json', 'foo');
  39. }
  40. /**
  41. * @expectedException \Symfony\Component\Intl\Exception\RuntimeException
  42. */
  43. public function testReadFailsIfNonExistingDirectory()
  44. {
  45. $this->reader->read(__DIR__.'/foo', 'en');
  46. }
  47. /**
  48. * @expectedException \Symfony\Component\Intl\Exception\RuntimeException
  49. */
  50. public function testReadFailsIfNotAFile()
  51. {
  52. $this->reader->read(__DIR__.'/Fixtures/NotAFile', 'en');
  53. }
  54. /**
  55. * @expectedException \Symfony\Component\Intl\Exception\RuntimeException
  56. */
  57. public function testReadFailsIfInvalidJson()
  58. {
  59. $this->reader->read(__DIR__.'/Fixtures/json', 'en_Invalid');
  60. }
  61. /**
  62. * @expectedException \Symfony\Component\Intl\Exception\ResourceBundleNotFoundException
  63. */
  64. public function testReaderDoesNotBreakOutOfGivenPath()
  65. {
  66. $this->reader->read(__DIR__.'/Fixtures/json', '../invalid_directory/en');
  67. }
  68. }