LoaderTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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\Loader;
  12. class LoaderTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testGetSetResolver()
  15. {
  16. $resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
  17. $loader = new ProjectLoader1();
  18. $loader->setResolver($resolver);
  19. $this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader');
  20. }
  21. public function testResolve()
  22. {
  23. $resolvedLoader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
  24. $resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
  25. $resolver->expects($this->once())
  26. ->method('resolve')
  27. ->with('foo.xml')
  28. ->will($this->returnValue($resolvedLoader));
  29. $loader = new ProjectLoader1();
  30. $loader->setResolver($resolver);
  31. $this->assertSame($loader, $loader->resolve('foo.foo'), '->resolve() finds a loader');
  32. $this->assertSame($resolvedLoader, $loader->resolve('foo.xml'), '->resolve() finds a loader');
  33. }
  34. /**
  35. * @expectedException Symfony\Component\Config\Exception\FileLoaderLoadException
  36. */
  37. public function testResolveWhenResolverCannotFindLoader()
  38. {
  39. $resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
  40. $resolver->expects($this->once())
  41. ->method('resolve')
  42. ->with('FOOBAR')
  43. ->will($this->returnValue(false));
  44. $loader = new ProjectLoader1();
  45. $loader->setResolver($resolver);
  46. $loader->resolve('FOOBAR');
  47. }
  48. public function testImport()
  49. {
  50. $resolvedLoader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
  51. $resolvedLoader->expects($this->once())
  52. ->method('load')
  53. ->with('foo')
  54. ->will($this->returnValue('yes'));
  55. $resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
  56. $resolver->expects($this->once())
  57. ->method('resolve')
  58. ->with('foo')
  59. ->will($this->returnValue($resolvedLoader));
  60. $loader = new ProjectLoader1();
  61. $loader->setResolver($resolver);
  62. $this->assertEquals('yes', $loader->import('foo'));
  63. }
  64. public function testImportWithType()
  65. {
  66. $resolvedLoader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
  67. $resolvedLoader->expects($this->once())
  68. ->method('load')
  69. ->with('foo', 'bar')
  70. ->will($this->returnValue('yes'));
  71. $resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
  72. $resolver->expects($this->once())
  73. ->method('resolve')
  74. ->with('foo', 'bar')
  75. ->will($this->returnValue($resolvedLoader));
  76. $loader = new ProjectLoader1();
  77. $loader->setResolver($resolver);
  78. $this->assertEquals('yes', $loader->import('foo', 'bar'));
  79. }
  80. }
  81. class ProjectLoader1 extends Loader
  82. {
  83. public function load($resource, $type = null)
  84. {
  85. }
  86. public function supports($resource, $type = null)
  87. {
  88. return is_string($resource) && 'foo' === pathinfo($resource, PATHINFO_EXTENSION);
  89. }
  90. public function getType()
  91. {
  92. }
  93. }