merged branch jakzal/loader-fix (PR #7987)
This PR was submitted for the master branch but it was merged into the 2.1 branch instead (closes #7987). Discussion ---------- [Config] FIxed Loader::import() | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? |no | Tests pass? | yes | Fixed tickets | fixes #7965, replaces #7983 | License | MIT | Doc PR | - Commits ------- 984e56a [Config] Added a test case for Loader::import(). 2f69860 [Config] Fixed Loader import
This commit is contained in:
commit
d2a542c5bb
@ -52,7 +52,7 @@ abstract class Loader implements LoaderInterface
|
||||
*/
|
||||
public function import($resource, $type = null)
|
||||
{
|
||||
return $this->resolve($resource)->load($resource, $type);
|
||||
return $this->resolve($resource, $type)->load($resource, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,59 +11,93 @@
|
||||
|
||||
namespace Symfony\Component\Config\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Config\Loader\LoaderResolver;
|
||||
use Symfony\Component\Config\Loader\Loader;
|
||||
use Symfony\Component\Config\Exception\FileLoaderLoadException;
|
||||
|
||||
class LoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Loader\Loader::getResolver
|
||||
* @covers Symfony\Component\Config\Loader\Loader::setResolver
|
||||
*/
|
||||
public function testGetSetResolver()
|
||||
{
|
||||
$resolver = new LoaderResolver();
|
||||
$resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
|
||||
|
||||
$loader = new ProjectLoader1();
|
||||
$loader->setResolver($resolver);
|
||||
|
||||
$this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Loader\Loader::resolve
|
||||
*/
|
||||
public function testResolve()
|
||||
{
|
||||
$loader1 = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
|
||||
$loader1->expects($this->once())->method('supports')->will($this->returnValue(true));
|
||||
$resolver = new LoaderResolver(array($loader1));
|
||||
$resolvedLoader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
|
||||
|
||||
$resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
|
||||
$resolver->expects($this->once())
|
||||
->method('resolve')
|
||||
->with('foo.xml')
|
||||
->will($this->returnValue($resolvedLoader));
|
||||
|
||||
$loader = new ProjectLoader1();
|
||||
$loader->setResolver($resolver);
|
||||
|
||||
$this->assertSame($loader, $loader->resolve('foo.foo'), '->resolve() finds a loader');
|
||||
$this->assertSame($loader1, $loader->resolve('foo.xml'), '->resolve() finds a loader');
|
||||
$this->assertSame($resolvedLoader, $loader->resolve('foo.xml'), '->resolve() finds a loader');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Config\Exception\FileLoaderLoadException
|
||||
*/
|
||||
public function testResolveWhenResolverCannotFindLoader()
|
||||
{
|
||||
$resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
|
||||
$resolver->expects($this->once())
|
||||
->method('resolve')
|
||||
->with('FOOBAR')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$loader1 = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
|
||||
$loader1->expects($this->once())->method('supports')->will($this->returnValue(false));
|
||||
$resolver = new LoaderResolver(array($loader1));
|
||||
$loader = new ProjectLoader1();
|
||||
$loader->setResolver($resolver);
|
||||
try {
|
||||
$loader->resolve('FOOBAR');
|
||||
$this->fail('->resolve() throws a FileLoaderLoadException if the resource cannot be loaded');
|
||||
} catch (FileLoaderLoadException $e) {
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Exception\FileLoaderLoadException', $e, '->resolve() throws a FileLoaderLoadException if the resource cannot be loaded');
|
||||
}
|
||||
|
||||
$loader->resolve('FOOBAR');
|
||||
}
|
||||
|
||||
public function testImport()
|
||||
{
|
||||
$loader = $this->getMock('Symfony\Component\Config\Loader\Loader', array('supports', 'load'));
|
||||
$loader->expects($this->once())->method('supports')->will($this->returnValue(true));
|
||||
$loader->expects($this->once())->method('load')->will($this->returnValue('yes'));
|
||||
$resolvedLoader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
|
||||
$resolvedLoader->expects($this->once())
|
||||
->method('load')
|
||||
->with('foo')
|
||||
->will($this->returnValue('yes'));
|
||||
|
||||
$resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
|
||||
$resolver->expects($this->once())
|
||||
->method('resolve')
|
||||
->with('foo')
|
||||
->will($this->returnValue($resolvedLoader));
|
||||
|
||||
$loader = new ProjectLoader1();
|
||||
$loader->setResolver($resolver);
|
||||
|
||||
$this->assertEquals('yes', $loader->import('foo'));
|
||||
}
|
||||
|
||||
public function testImportWithType()
|
||||
{
|
||||
$resolvedLoader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
|
||||
$resolvedLoader->expects($this->once())
|
||||
->method('load')
|
||||
->with('foo', 'bar')
|
||||
->will($this->returnValue('yes'));
|
||||
|
||||
$resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
|
||||
$resolver->expects($this->once())
|
||||
->method('resolve')
|
||||
->with('foo', 'bar')
|
||||
->will($this->returnValue($resolvedLoader));
|
||||
|
||||
$loader = new ProjectLoader1();
|
||||
$loader->setResolver($resolver);
|
||||
|
||||
$this->assertEquals('yes', $loader->import('foo', 'bar'));
|
||||
}
|
||||
}
|
||||
|
||||
class ProjectLoader1 extends Loader
|
||||
|
Reference in New Issue
Block a user