PhpFileLoaderTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\PhpFileLoader;
  12. use Symfony\Component\Config\Resource\FileResource;
  13. class PhpFileLoaderTest 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 PhpFileLoader();
  24. $resource = __DIR__.'/../fixtures/resources.php';
  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. /**
  31. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  32. */
  33. public function testLoadNonExistingResource()
  34. {
  35. $loader = new PhpFileLoader();
  36. $resource = __DIR__.'/../fixtures/non-existing.php';
  37. $loader->load($resource, 'en', 'domain1');
  38. }
  39. /**
  40. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  41. */
  42. public function testLoadThrowsAnExceptionIfFileNotLocal()
  43. {
  44. $loader = new PhpFileLoader();
  45. $resource = 'http://example.com/resources.php';
  46. $loader->load($resource, 'en', 'domain1');
  47. }
  48. }