YamlFileLoaderTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace Symfony\Tests\Component\Routing\Loader;
  10. use Symfony\Component\Routing\Loader\LoaderResolver;
  11. use Symfony\Component\Routing\Loader\YamlFileLoader;
  12. use Symfony\Component\Routing\Route;
  13. use Symfony\Component\Routing\RouteCollection;
  14. use Symfony\Component\Routing\Resource\FileResource;
  15. class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * @covers Symfony\Component\Routing\Loader\YamlFileLoader::supports
  19. */
  20. public function testSupports()
  21. {
  22. $loader = new YamlFileLoader();
  23. $this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
  24. $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
  25. $this->assertTrue($loader->supports('foo.yml', 'yaml'), '->supports() checks the resource type if specified');
  26. $this->assertFalse($loader->supports('foo.yml', 'foo'), '->supports() checks the resource type if specified');
  27. }
  28. public function testLoadDoesNothingIfEmpty()
  29. {
  30. $loader = new YamlFileLoader(array(__DIR__.'/../Fixtures'));
  31. $collection = $loader->load('empty.yml');
  32. $this->assertEquals(array(), $collection->all());
  33. $this->assertEquals(array(new FileResource(realpath(__DIR__.'/../Fixtures/empty.yml'))), $collection->getResources());
  34. }
  35. /**
  36. * @expectedException \InvalidArgumentException
  37. */
  38. public function testLoadThrowsExceptionIfNotAnArray()
  39. {
  40. $loader = new YamlFileLoader(array(__DIR__.'/../Fixtures'));
  41. $loader->load('nonvalid.yml');
  42. }
  43. }