Yaffs site version 1.1
[yaffs-website] / vendor / symfony / config / Tests / Loader / LoaderTest.php
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
12 namespace Symfony\Component\Config\Tests\Loader;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\Loader\Loader;
16
17 class LoaderTest extends TestCase
18 {
19     public function testGetSetResolver()
20     {
21         $resolver = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderResolverInterface')->getMock();
22
23         $loader = new ProjectLoader1();
24         $loader->setResolver($resolver);
25
26         $this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader');
27     }
28
29     public function testResolve()
30     {
31         $resolvedLoader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
32
33         $resolver = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderResolverInterface')->getMock();
34         $resolver->expects($this->once())
35             ->method('resolve')
36             ->with('foo.xml')
37             ->will($this->returnValue($resolvedLoader));
38
39         $loader = new ProjectLoader1();
40         $loader->setResolver($resolver);
41
42         $this->assertSame($loader, $loader->resolve('foo.foo'), '->resolve() finds a loader');
43         $this->assertSame($resolvedLoader, $loader->resolve('foo.xml'), '->resolve() finds a loader');
44     }
45
46     /**
47      * @expectedException \Symfony\Component\Config\Exception\FileLoaderLoadException
48      */
49     public function testResolveWhenResolverCannotFindLoader()
50     {
51         $resolver = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderResolverInterface')->getMock();
52         $resolver->expects($this->once())
53             ->method('resolve')
54             ->with('FOOBAR')
55             ->will($this->returnValue(false));
56
57         $loader = new ProjectLoader1();
58         $loader->setResolver($resolver);
59
60         $loader->resolve('FOOBAR');
61     }
62
63     public function testImport()
64     {
65         $resolvedLoader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
66         $resolvedLoader->expects($this->once())
67             ->method('load')
68             ->with('foo')
69             ->will($this->returnValue('yes'));
70
71         $resolver = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderResolverInterface')->getMock();
72         $resolver->expects($this->once())
73             ->method('resolve')
74             ->with('foo')
75             ->will($this->returnValue($resolvedLoader));
76
77         $loader = new ProjectLoader1();
78         $loader->setResolver($resolver);
79
80         $this->assertEquals('yes', $loader->import('foo'));
81     }
82
83     public function testImportWithType()
84     {
85         $resolvedLoader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
86         $resolvedLoader->expects($this->once())
87             ->method('load')
88             ->with('foo', 'bar')
89             ->will($this->returnValue('yes'));
90
91         $resolver = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderResolverInterface')->getMock();
92         $resolver->expects($this->once())
93             ->method('resolve')
94             ->with('foo', 'bar')
95             ->will($this->returnValue($resolvedLoader));
96
97         $loader = new ProjectLoader1();
98         $loader->setResolver($resolver);
99
100         $this->assertEquals('yes', $loader->import('foo', 'bar'));
101     }
102 }
103
104 class ProjectLoader1 extends Loader
105 {
106     public function load($resource, $type = null)
107     {
108     }
109
110     public function supports($resource, $type = null)
111     {
112         return is_string($resource) && 'foo' === pathinfo($resource, PATHINFO_EXTENSION);
113     }
114
115     public function getType()
116     {
117     }
118 }