4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Tests\Loader
;
14 use Symfony\Component\Translation\Loader\YamlFileLoader
;
15 use Symfony\Component\Config\
Resource\FileResource
;
17 class YamlFileLoaderTest
extends \PHPUnit_Framework_TestCase
19 protected function setUp()
21 if (!class_exists('Symfony\Component\Config\Loader\Loader')) {
22 $this->markTestSkipped('The "Config" component is not available');
25 if (!class_exists('Symfony\Component\Yaml\Yaml')) {
26 $this->markTestSkipped('The "Yaml" component is not available');
30 public function testLoad()
32 $loader = new YamlFileLoader();
33 $resource = __DIR__
.'/../fixtures/resources.yml';
34 $catalogue = $loader->load($resource, 'en', 'domain1');
36 $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
37 $this->assertEquals('en', $catalogue->getLocale());
38 $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
41 public function testLoadDoesNothingIfEmpty()
43 $loader = new YamlFileLoader();
44 $resource = __DIR__
.'/../fixtures/empty.yml';
45 $catalogue = $loader->load($resource, 'en', 'domain1');
47 $this->assertEquals(array(), $catalogue->all('domain1'));
48 $this->assertEquals('en', $catalogue->getLocale());
49 $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
53 * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
55 public function testLoadNonExistingResource()
57 $loader = new YamlFileLoader();
58 $resource = __DIR__
.'/../fixtures/non-existing.yml';
59 $loader->load($resource, 'en', 'domain1');
63 * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
65 public function testLoadThrowsAnExceptionIfFileNotLocal()
67 $loader = new YamlFileLoader();
68 $resource = 'http://example.com/resources.yml';
69 $loader->load($resource, 'en', 'domain1');
73 * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
75 public function testLoadThrowsAnExceptionIfNotAnArray()
77 $loader = new YamlFileLoader();
78 $resource = __DIR__
.'/../fixtures/non-valid.yml';
79 $loader->load($resource, 'en', 'domain1');