PhpBundleReaderTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\PhpBundleReader;
  13. /**
  14. * @author Bernhard Schussek <bschussek@gmail.com>
  15. */
  16. class PhpBundleReaderTest extends TestCase
  17. {
  18. /**
  19. * @var PhpBundleReader
  20. */
  21. private $reader;
  22. protected function setUp()
  23. {
  24. $this->reader = new PhpBundleReader();
  25. }
  26. public function testReadReturnsArray()
  27. {
  28. $data = $this->reader->read(__DIR__.'/Fixtures/php', '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/php', '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\ResourceBundleNotFoundException
  56. */
  57. public function testReaderDoesNotBreakOutOfGivenPath()
  58. {
  59. $this->reader->read(__DIR__.'/Fixtures/php', '../invalid_directory/en');
  60. }
  61. }