PhpFileLoaderTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Translation\Loader\PhpFileLoader;
  13. use Symfony\Component\Config\Resource\FileResource;
  14. class PhpFileLoaderTest extends TestCase
  15. {
  16. public function testLoad()
  17. {
  18. $loader = new PhpFileLoader();
  19. $resource = __DIR__.'/../fixtures/resources.php';
  20. $catalogue = $loader->load($resource, 'en', 'domain1');
  21. $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
  22. $this->assertEquals('en', $catalogue->getLocale());
  23. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  24. }
  25. /**
  26. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  27. */
  28. public function testLoadNonExistingResource()
  29. {
  30. $loader = new PhpFileLoader();
  31. $resource = __DIR__.'/../fixtures/non-existing.php';
  32. $loader->load($resource, 'en', 'domain1');
  33. }
  34. /**
  35. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  36. */
  37. public function testLoadThrowsAnExceptionIfFileNotLocal()
  38. {
  39. $loader = new PhpFileLoader();
  40. $resource = 'http://example.com/resources.php';
  41. $loader->load($resource, 'en', 'domain1');
  42. }
  43. }