Merge branch '2.1' into 2.2
* 2.1: Fixed XML syntax. Fixed parsing of leading blank lines in folded scalars. Closes #7989. Added a test case for Loader::import(). Fixed Loader import [Console] Added dedicated testcase for HelperSet class
This commit is contained in:
commit
70ea5a61c5
@ -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
|
||||
|
136
src/Symfony/Component/Console/Tests/Helper/HelperSetTest.php
Normal file
136
src/Symfony/Component/Console/Tests/Helper/HelperSetTest.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class HelperSetTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Symfony\Component\Console\Helper\HelperSet::__construct
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$mock_helper = $this->getGenericMockHelper('fake_helper');
|
||||
$helperset = new HelperSet(array('fake_helper_alias' => $mock_helper));
|
||||
|
||||
$this->assertEquals($mock_helper, $helperset->get('fake_helper_alias'), '__construct sets given helper to helpers');
|
||||
$this->assertTrue($helperset->has('fake_helper_alias'), '__construct sets helper alias for given helper');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Symfony\Component\Console\Helper\HelperSet::set
|
||||
*/
|
||||
public function testSet()
|
||||
{
|
||||
$helperset = new HelperSet();
|
||||
$helperset->set($this->getGenericMockHelper('fake_helper', $helperset));
|
||||
$this->assertTrue($helperset->has('fake_helper'), '->set() adds helper to helpers');
|
||||
|
||||
$helperset = new HelperSet();
|
||||
$helperset->set($this->getGenericMockHelper('fake_helper_01', $helperset));
|
||||
$helperset->set($this->getGenericMockHelper('fake_helper_02', $helperset));
|
||||
$this->assertTrue($helperset->has('fake_helper_01'), '->set() will set multiple helpers on consecutive calls');
|
||||
$this->assertTrue($helperset->has('fake_helper_02'), '->set() will set multiple helpers on consecutive calls');
|
||||
|
||||
$helperset = new HelperSet();
|
||||
$helperset->set($this->getGenericMockHelper('fake_helper', $helperset), 'fake_helper_alias');
|
||||
$this->assertTrue($helperset->has('fake_helper'), '->set() adds helper alias when set');
|
||||
$this->assertTrue($helperset->has('fake_helper_alias'), '->set() adds helper alias when set');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Symfony\Component\Console\Helper\HelperSet::has
|
||||
*/
|
||||
public function testHas()
|
||||
{
|
||||
$helperset = new HelperSet(array('fake_helper_alias' => $this->getGenericMockHelper('fake_helper')));
|
||||
$this->assertTrue($helperset->has('fake_helper'), '->has() finds set helper');
|
||||
$this->assertTrue($helperset->has('fake_helper_alias'), '->has() finds set helper by alias');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Symfony\Component\Console\Helper\HelperSet::get
|
||||
*/
|
||||
public function testGet()
|
||||
{
|
||||
$helper_01 = $this->getGenericMockHelper('fake_helper_01');
|
||||
$helper_02 = $this->getGenericMockHelper('fake_helper_02');
|
||||
$helperset = new HelperSet(array('fake_helper_01_alias' => $helper_01, 'fake_helper_02_alias' => $helper_02));
|
||||
$this->assertEquals($helper_01, $helperset->get('fake_helper_01'), '->get() returns correct helper by name');
|
||||
$this->assertEquals($helper_01, $helperset->get('fake_helper_01_alias'), '->get() returns correct helper by alias');
|
||||
$this->assertEquals($helper_02, $helperset->get('fake_helper_02'), '->get() returns correct helper by name');
|
||||
$this->assertEquals($helper_02, $helperset->get('fake_helper_02_alias'), '->get() returns correct helper by alias');
|
||||
|
||||
$helperset = new HelperSet();
|
||||
try {
|
||||
$helperset->get('foo');
|
||||
$this->fail('->get() throws \InvalidArgumentException when helper not found');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws \InvalidArgumentException when helper not found');
|
||||
$this->assertContains('The helper "foo" is not defined.', $e->getMessage(), '->get() throws \InvalidArgumentException when helper not found');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Symfony\Component\Console\Helper\HelperSet::setCommand
|
||||
*/
|
||||
public function testSetCommand()
|
||||
{
|
||||
$cmd_01 = new Command('foo');
|
||||
$cmd_02 = new Command('bar');
|
||||
|
||||
$helperset = new HelperSet();
|
||||
$helperset->setCommand($cmd_01);
|
||||
$this->assertEquals($cmd_01, $helperset->getCommand(), '->setCommand() stores given command');
|
||||
|
||||
$helperset = new HelperSet();
|
||||
$helperset->setCommand($cmd_01);
|
||||
$helperset->setCommand($cmd_02);
|
||||
$this->assertEquals($cmd_02, $helperset->getCommand(), '->setCommand() overwrites stored command with consecutive calls');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Symfony\Component\Console\Helper\HelperSet::getCommand
|
||||
*/
|
||||
public function testGetCommand()
|
||||
{
|
||||
$cmd = new Command('foo');
|
||||
$helperset = new HelperSet();
|
||||
$helperset->setCommand($cmd);
|
||||
$this->assertEquals($cmd, $helperset->getCommand(), '->getCommand() retrieves stored command');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a generic mock for the helper interface. Optionally check for a call to setHelperSet with a specific
|
||||
* helperset instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param HelperSet $helperset allows a mock to verify a particular helperset set is being added to the Helper
|
||||
*/
|
||||
private function getGenericMockHelper($name, HelperSet $helperset = null)
|
||||
{
|
||||
$mock_helper = $this->getMock('\Symfony\Component\Console\Helper\HelperInterface');
|
||||
$mock_helper->expects($this->any())
|
||||
->method('getName')
|
||||
->will($this->returnValue($name));
|
||||
|
||||
if ($helperset) {
|
||||
$mock_helper->expects($this->any())
|
||||
->method('setHelperSet')
|
||||
->with($this->equalTo($helperset));
|
||||
}
|
||||
|
||||
return $mock_helper;
|
||||
}
|
||||
}
|
@ -184,7 +184,7 @@
|
||||
</trans-unit>
|
||||
<trans-unit id="49">
|
||||
<source>The file was only partially uploaded.</source>
|
||||
<source>Fail ei laetud täielikult üles.</target>
|
||||
<target>Fail ei laetud täielikult üles.</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="50">
|
||||
<source>No file was uploaded.</source>
|
||||
|
@ -419,6 +419,18 @@ class Parser
|
||||
return '';
|
||||
}
|
||||
|
||||
$isCurrentLineBlank = $this->isCurrentLineBlank();
|
||||
$text = '';
|
||||
|
||||
// leading blank lines are consumed before determining indentation
|
||||
while ($notEOF && $isCurrentLineBlank) {
|
||||
// newline only if not EOF
|
||||
if ($notEOF = $this->moveToNextLine()) {
|
||||
$text .= "\n";
|
||||
$isCurrentLineBlank = $this->isCurrentLineBlank();
|
||||
}
|
||||
}
|
||||
|
||||
// determine indentation if not specified
|
||||
if (0 === $indentation) {
|
||||
if (preg_match('/^ +/', $this->currentLine, $matches)) {
|
||||
@ -426,11 +438,9 @@ class Parser
|
||||
}
|
||||
}
|
||||
|
||||
$text = '';
|
||||
if ($indentation > 0) {
|
||||
$pattern = sprintf('/^ {%d}(.*)$/', $indentation);
|
||||
|
||||
$isCurrentLineBlank = $this->isCurrentLineBlank();
|
||||
while (
|
||||
$notEOF && (
|
||||
$isCurrentLineBlank ||
|
||||
|
@ -396,6 +396,27 @@ EOF;
|
||||
$this->assertSame($expected, $this->parser->parse($yaml));
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression test for issue #7989.
|
||||
*
|
||||
* @see https://github.com/symfony/symfony/issues/7989
|
||||
*/
|
||||
public function testBlockLiteralWithLeadingNewlines()
|
||||
{
|
||||
$yaml = <<<'EOF'
|
||||
foo: |-
|
||||
|
||||
|
||||
bar
|
||||
|
||||
EOF;
|
||||
$expected = array(
|
||||
'foo' => "\n\nbar"
|
||||
);
|
||||
|
||||
$this->assertSame($expected, $this->parser->parse($yaml));
|
||||
}
|
||||
|
||||
public function testObjectSupportEnabled()
|
||||
{
|
||||
$input = <<<EOF
|
||||
|
Reference in New Issue
Block a user