diff --git a/src/Symfony/Component/Config/Loader/Loader.php b/src/Symfony/Component/Config/Loader/Loader.php
index 9acfb7b0c0..705a6a78e9 100644
--- a/src/Symfony/Component/Config/Loader/Loader.php
+++ b/src/Symfony/Component/Config/Loader/Loader.php
@@ -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);
}
/**
diff --git a/src/Symfony/Component/Config/Tests/Loader/LoaderTest.php b/src/Symfony/Component/Config/Tests/Loader/LoaderTest.php
index 8ce5a8b68e..05ea772a7f 100644
--- a/src/Symfony/Component/Config/Tests/Loader/LoaderTest.php
+++ b/src/Symfony/Component/Config/Tests/Loader/LoaderTest.php
@@ -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
diff --git a/src/Symfony/Component/Console/Tests/Helper/HelperSetTest.php b/src/Symfony/Component/Console/Tests/Helper/HelperSetTest.php
new file mode 100644
index 0000000000..c9832736a2
--- /dev/null
+++ b/src/Symfony/Component/Console/Tests/Helper/HelperSetTest.php
@@ -0,0 +1,136 @@
+
+ *
+ * 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;
+ }
+}
diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.et.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.et.xlf
index c74a187588..309de98dc3 100644
--- a/src/Symfony/Component/Validator/Resources/translations/validators.et.xlf
+++ b/src/Symfony/Component/Validator/Resources/translations/validators.et.xlf
@@ -184,7 +184,7 @@
The file was only partially uploaded.
- Fail ei laetud täielikult üles.
+ Fail ei laetud täielikult üles.
No file was uploaded.
diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php
index 1e88f85d4a..4a82b784bc 100644
--- a/src/Symfony/Component/Yaml/Parser.php
+++ b/src/Symfony/Component/Yaml/Parser.php
@@ -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 ||
diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php
index b6bee17fe5..a8d28b9131 100644
--- a/src/Symfony/Component/Yaml/Tests/ParserTest.php
+++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php
@@ -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 = <<