DelegatingLoaderTest.php 2.8 KB

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