1<?php 2 3/* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Symfony\Component\Config\Tests\Loader; 13 14use PHPUnit\Framework\TestCase; 15use Symfony\Component\Config\Loader\DelegatingLoader; 16use Symfony\Component\Config\Loader\LoaderResolver; 17 18class DelegatingLoaderTest extends TestCase 19{ 20 public function testConstructor() 21 { 22 new DelegatingLoader($resolver = new LoaderResolver()); 23 $this->assertTrue(true, '__construct() takes a loader resolver as its first argument'); 24 } 25 26 public function testGetSetResolver() 27 { 28 $resolver = new LoaderResolver(); 29 $loader = new DelegatingLoader($resolver); 30 $this->assertSame($resolver, $loader->getResolver(), '->getResolver() gets the resolver loader'); 31 $loader->setResolver($resolver = new LoaderResolver()); 32 $this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader'); 33 } 34 35 public function testSupports() 36 { 37 $loader1 = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock(); 38 $loader1->expects($this->once())->method('supports')->willReturn(true); 39 $loader = new DelegatingLoader(new LoaderResolver([$loader1])); 40 $this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable'); 41 42 $loader1 = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock(); 43 $loader1->expects($this->once())->method('supports')->willReturn(false); 44 $loader = new DelegatingLoader(new LoaderResolver([$loader1])); 45 $this->assertFalse($loader->supports('foo.foo'), '->supports() returns false if the resource is not loadable'); 46 } 47 48 public function testLoad() 49 { 50 $loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock(); 51 $loader->expects($this->once())->method('supports')->willReturn(true); 52 $loader->expects($this->once())->method('load'); 53 $resolver = new LoaderResolver([$loader]); 54 $loader = new DelegatingLoader($resolver); 55 56 $loader->load('foo'); 57 } 58 59 public function testLoadThrowsAnExceptionIfTheResourceCannotBeLoaded() 60 { 61 $this->expectException('Symfony\Component\Config\Exception\FileLoaderLoadException'); 62 $loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock(); 63 $loader->expects($this->once())->method('supports')->willReturn(false); 64 $resolver = new LoaderResolver([$loader]); 65 $loader = new DelegatingLoader($resolver); 66 67 $loader->load('foo'); 68 } 69} 70