DelegatingLoaderTest.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\Config\Tests\Loader;
  11. use Symfony\Component\Config\Loader\LoaderResolver;
  12. use Symfony\Component\Config\Loader\DelegatingLoader;
  13. class DelegatingLoaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * @covers Symfony\Component\Config\Loader\DelegatingLoader::__construct
  17. */
  18. public function testConstructor()
  19. {
  20. $loader = new DelegatingLoader($resolver = new LoaderResolver());
  21. $this->assertTrue(true, '__construct() takes a loader resolver as its first argument');
  22. }
  23. /**
  24. * @covers Symfony\Component\Config\Loader\DelegatingLoader::getResolver
  25. * @covers Symfony\Component\Config\Loader\DelegatingLoader::setResolver
  26. */
  27. public function testGetSetResolver()
  28. {
  29. $resolver = new LoaderResolver();
  30. $loader = new DelegatingLoader($resolver);
  31. $this->assertSame($resolver, $loader->getResolver(), '->getResolver() gets the resolver loader');
  32. $loader->setResolver($resolver = new LoaderResolver());
  33. $this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader');
  34. }
  35. /**
  36. * @covers Symfony\Component\Config\Loader\DelegatingLoader::supports
  37. */
  38. public function testSupports()
  39. {
  40. $loader1 = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
  41. $loader1->expects($this->once())->method('supports')->will($this->returnValue(true));
  42. $loader = new DelegatingLoader(new LoaderResolver(array($loader1)));
  43. $this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable');
  44. $loader1 = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
  45. $loader1->expects($this->once())->method('supports')->will($this->returnValue(false));
  46. $loader = new DelegatingLoader(new LoaderResolver(array($loader1)));
  47. $this->assertFalse($loader->supports('foo.foo'), '->supports() returns false if the resource is not loadable');
  48. }
  49. /**
  50. * @covers Symfony\Component\Config\Loader\DelegatingLoader::load
  51. */
  52. public function testLoad()
  53. {
  54. $loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
  55. $loader->expects($this->once())->method('supports')->will($this->returnValue(true));
  56. $loader->expects($this->once())->method('load');
  57. $resolver = new LoaderResolver(array($loader));
  58. $loader = new DelegatingLoader($resolver);
  59. $loader->load('foo');
  60. }
  61. /**
  62. * @expectedException \Symfony\Component\Config\Exception\FileLoaderLoadException
  63. */
  64. public function testLoadThrowsAnExceptionIfTheResourceCannotBeLoaded()
  65. {
  66. $loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
  67. $loader->expects($this->once())->method('supports')->will($this->returnValue(false));
  68. $resolver = new LoaderResolver(array($loader));
  69. $loader = new DelegatingLoader($resolver);
  70. $loader->load('foo');
  71. }
  72. }