diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php index 8cccf7e8d6..21486a7a3d 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace symfony\src\Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler; +namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; diff --git a/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/RenderTokenParserTest.php b/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/RenderTokenParserTest.php index dd347e4fbb..9823a98fca 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/RenderTokenParserTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/RenderTokenParserTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Bridge\Twig\Tests\Node; +namespace Symfony\Bundle\TwigBundle\Tests\TokenParser; use Symfony\Bundle\TwigBundle\Tests\TestCase; use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser; 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/Routing/Tests/RouteCollectionTest.php b/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php index 901317663f..3d78adf923 100644 --- a/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php @@ -97,7 +97,7 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase $collection->addCollection($collection1); $collection->add('last', $last = new Route('/last')); - $this->assertSame(array('bar' => $bar, 'foo' => $foo, 'grandchild' => $grandchild, 'last' => $last), $collection->all(), + $this->assertSame(array('bar' => $bar, 'foo' => $foo, 'grandchild' => $grandchild, 'last' => $last), $collection->all(), '->addCollection() imports routes of another collection, overrides if necessary and adds them at the end'); } diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index 6eb231c81e..73ae9fa474 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -173,9 +173,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz private function getNormalizer($data, $format = null) { foreach ($this->normalizers as $normalizer) { - if ($normalizer instanceof NormalizerInterface - && $normalizer->supportsNormalization($data, $format) - ) { + if ($normalizer instanceof NormalizerInterface && $normalizer->supportsNormalization($data, $format)) { return $normalizer; } } @@ -189,9 +187,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz private function getDenormalizer($data, $type, $format = null) { foreach ($this->normalizers as $normalizer) { - if ($normalizer instanceof DenormalizerInterface - && $normalizer->supportsDenormalization($data, $type, $format) - ) { + if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $type, $format)) { return $normalizer; } } @@ -239,7 +235,8 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz } foreach ($this->normalizers as $normalizer) { - if ($normalizer->supportsNormalization($object, $format)) { + if ($normalizer instanceof NormalizerInterface + && $normalizer->supportsNormalization($object, $format)) { $this->normalizerCache[$class][$format] = $normalizer; return $normalizer->normalize($object, $format, $context); @@ -273,7 +270,8 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz } foreach ($this->normalizers as $normalizer) { - if ($normalizer->supportsDenormalization($data, $class, $format)) { + if ($normalizer instanceof DenormalizerInterface + && $normalizer->supportsDenormalization($data, $class, $format)) { $this->denormalizerCache[$class][$format] = $normalizer; return $normalizer->denormalize($data, $class, $format, $context); diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/TestDenormalizer.php b/src/Symfony/Component/Serializer/Tests/Normalizer/TestDenormalizer.php new file mode 100644 index 0000000000..e881ad1397 --- /dev/null +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/TestDenormalizer.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Serializer\Tests\Normalizer; + +use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; + +/** + * Provides a test Normalizer which only implements the DenormalizerInterface. + * + * @author Lin Clark + */ +class TestDenormalizer implements DenormalizerInterface +{ + /** + * {@inheritdoc} + */ + public function denormalize($data, $class, $format = null, array $context = array()) + { + } + + /** + * {@inheritdoc} + */ + public function supportsDenormalization($data, $type, $format = null) + { + return true; + } +} diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/TestNormalizer.php b/src/Symfony/Component/Serializer/Tests/Normalizer/TestNormalizer.php new file mode 100644 index 0000000000..4c000b3eb4 --- /dev/null +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/TestNormalizer.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Serializer\Tests\Normalizer; + +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; + +/** + * Provides a test Normalizer which only implements the NormalizerInterface. + * + * @author Lin Clark + */ +class TestNormalizer implements NormalizerInterface +{ + /** + * {@inheritdoc} + */ + public function normalize($object, $format = null, array $context = array()) + { + } + + /** + * {@inheritdoc} + */ + public function supportsNormalization($data, $format = null) + { + return true; + } +} diff --git a/src/Symfony/Component/Serializer/Tests/SerializerTest.php b/src/Symfony/Component/Serializer/Tests/SerializerTest.php index 6470393b13..3c189461f2 100644 --- a/src/Symfony/Component/Serializer/Tests/SerializerTest.php +++ b/src/Symfony/Component/Serializer/Tests/SerializerTest.php @@ -17,6 +17,8 @@ use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; use Symfony\Component\Serializer\Normalizer\CustomNormalizer; use Symfony\Component\Serializer\Tests\Fixtures\TraversableDummy; use Symfony\Component\Serializer\Tests\Fixtures\NormalizableTraversableDummy; +use Symfony\Component\Serializer\Tests\Normalizer\TestNormalizer; +use Symfony\Component\Serializer\Tests\Normalizer\TestDenormalizer; class SerializerTest extends \PHPUnit_Framework_TestCase { @@ -43,6 +45,15 @@ class SerializerTest extends \PHPUnit_Framework_TestCase $this->assertEquals('{"foo":"normalizedFoo","bar":"normalizedBar"}', $result); } + /** + * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException + */ + public function testNormalizeOnDenormalizer() + { + $this->serializer = new Serializer(array(new TestDenormalizer()), array()); + $this->assertTrue($this->serializer->normalize(new \stdClass, 'json')); + } + /** * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException */ @@ -52,6 +63,16 @@ class SerializerTest extends \PHPUnit_Framework_TestCase $this->serializer->denormalize('foo', 'stdClass'); } + /** + * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException + */ + public function testDenormalizeOnNormalizer() + { + $this->serializer = new Serializer(array(new TestNormalizer()), array()); + $data = array('title' => 'foo', 'numbers' => array(5, 3)); + $this->assertTrue($this->serializer->denormalize(json_encode($data), 'stdClass', 'json')); + } + public function testSerialize() { $this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder())); @@ -223,5 +244,4 @@ class Model { return array('title' => $this->title, 'numbers' => $this->numbers); } - } diff --git a/src/Symfony/Component/Translation/Translator.php b/src/Symfony/Component/Translation/Translator.php index 8dc7b9db74..8e74b79f60 100644 --- a/src/Symfony/Component/Translation/Translator.php +++ b/src/Symfony/Component/Translation/Translator.php @@ -98,7 +98,7 @@ class Translator implements TranslatorInterface $this->resources[$locale][] = array($format, $resource, $domain); - if(in_array($locale, $this->fallbackLocales)) { + if (in_array($locale, $this->fallbackLocales)) { $this->catalogues = array(); } else { unset($this->catalogues[$locale]); diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.et.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.et.xlf index a1986d048d..47bee218e2 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 e368f98c5e..680b50349c 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -421,6 +421,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)) { @@ -428,11 +440,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 = <<