YamlFileLoaderTest.php 1.8 KB

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