IniFileLoaderTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\Translation\Tests\Loader;
  11. use Symfony\Component\Translation\Loader\IniFileLoader;
  12. use Symfony\Component\Config\Resource\FileResource;
  13. class IniFileLoaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected function setUp()
  16. {
  17. if (!class_exists('Symfony\Component\Config\Loader\Loader')) {
  18. $this->markTestSkipped('The "Config" component is not available');
  19. }
  20. }
  21. public function testLoad()
  22. {
  23. $loader = new IniFileLoader();
  24. $resource = __DIR__.'/../fixtures/resources.ini';
  25. $catalogue = $loader->load($resource, 'en', 'domain1');
  26. $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
  27. $this->assertEquals('en', $catalogue->getLocale());
  28. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  29. }
  30. public function testLoadDoesNothingIfEmpty()
  31. {
  32. $loader = new IniFileLoader();
  33. $resource = __DIR__.'/../fixtures/empty.ini';
  34. $catalogue = $loader->load($resource, 'en', 'domain1');
  35. $this->assertEquals(array(), $catalogue->all('domain1'));
  36. $this->assertEquals('en', $catalogue->getLocale());
  37. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  38. }
  39. /**
  40. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  41. */
  42. public function testLoadNonExistingResource()
  43. {
  44. $loader = new IniFileLoader();
  45. $resource = __DIR__.'/../fixtures/non-existing.ini';
  46. $loader->load($resource, 'en', 'domain1');
  47. }
  48. }