Merge branch '2.2'
* 2.2: fixed CS Fixed XML syntax. Fixed parsing of leading blank lines in folded scalars. Closes #7989. [Form] Fixed a method name. Added a test case for Loader::import(). Fixed Loader import [Console] Added dedicated testcase for HelperSet class [Serializer] fixed CS (refs #7971) Fixed fatal error in normalize/denormalizeObject. Fixed 2 namespaces Conflicts: src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php
This commit is contained in:
commit
498bfa33fa
@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* 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\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* 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\Tests\TestCase;
|
||||||
use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
|
use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
|
||||||
|
@ -52,7 +52,7 @@ abstract class Loader implements LoaderInterface
|
|||||||
*/
|
*/
|
||||||
public function import($resource, $type = null)
|
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;
|
namespace Symfony\Component\Config\Tests\Loader;
|
||||||
|
|
||||||
use Symfony\Component\Config\Loader\LoaderResolver;
|
|
||||||
use Symfony\Component\Config\Loader\Loader;
|
use Symfony\Component\Config\Loader\Loader;
|
||||||
use Symfony\Component\Config\Exception\FileLoaderLoadException;
|
|
||||||
|
|
||||||
class LoaderTest extends \PHPUnit_Framework_TestCase
|
class LoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @covers Symfony\Component\Config\Loader\Loader::getResolver
|
|
||||||
* @covers Symfony\Component\Config\Loader\Loader::setResolver
|
|
||||||
*/
|
|
||||||
public function testGetSetResolver()
|
public function testGetSetResolver()
|
||||||
{
|
{
|
||||||
$resolver = new LoaderResolver();
|
$resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
|
||||||
|
|
||||||
$loader = new ProjectLoader1();
|
$loader = new ProjectLoader1();
|
||||||
$loader->setResolver($resolver);
|
$loader->setResolver($resolver);
|
||||||
|
|
||||||
$this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader');
|
$this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Component\Config\Loader\Loader::resolve
|
|
||||||
*/
|
|
||||||
public function testResolve()
|
public function testResolve()
|
||||||
{
|
{
|
||||||
$loader1 = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
|
$resolvedLoader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
|
||||||
$loader1->expects($this->once())->method('supports')->will($this->returnValue(true));
|
|
||||||
$resolver = new LoaderResolver(array($loader1));
|
$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 = new ProjectLoader1();
|
||||||
$loader->setResolver($resolver);
|
$loader->setResolver($resolver);
|
||||||
|
|
||||||
$this->assertSame($loader, $loader->resolve('foo.foo'), '->resolve() finds a loader');
|
$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 = new ProjectLoader1();
|
||||||
$loader->setResolver($resolver);
|
$loader->setResolver($resolver);
|
||||||
try {
|
|
||||||
$loader->resolve('FOOBAR');
|
$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');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testImport()
|
public function testImport()
|
||||||
{
|
{
|
||||||
$loader = $this->getMock('Symfony\Component\Config\Loader\Loader', array('supports', 'load'));
|
$resolvedLoader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
|
||||||
$loader->expects($this->once())->method('supports')->will($this->returnValue(true));
|
$resolvedLoader->expects($this->once())
|
||||||
$loader->expects($this->once())->method('load')->will($this->returnValue('yes'));
|
->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'));
|
$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
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -173,9 +173,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||||||
private function getNormalizer($data, $format = null)
|
private function getNormalizer($data, $format = null)
|
||||||
{
|
{
|
||||||
foreach ($this->normalizers as $normalizer) {
|
foreach ($this->normalizers as $normalizer) {
|
||||||
if ($normalizer instanceof NormalizerInterface
|
if ($normalizer instanceof NormalizerInterface && $normalizer->supportsNormalization($data, $format)) {
|
||||||
&& $normalizer->supportsNormalization($data, $format)
|
|
||||||
) {
|
|
||||||
return $normalizer;
|
return $normalizer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -189,9 +187,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||||||
private function getDenormalizer($data, $type, $format = null)
|
private function getDenormalizer($data, $type, $format = null)
|
||||||
{
|
{
|
||||||
foreach ($this->normalizers as $normalizer) {
|
foreach ($this->normalizers as $normalizer) {
|
||||||
if ($normalizer instanceof DenormalizerInterface
|
if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $type, $format)) {
|
||||||
&& $normalizer->supportsDenormalization($data, $type, $format)
|
|
||||||
) {
|
|
||||||
return $normalizer;
|
return $normalizer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,7 +235,8 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->normalizers as $normalizer) {
|
foreach ($this->normalizers as $normalizer) {
|
||||||
if ($normalizer->supportsNormalization($object, $format)) {
|
if ($normalizer instanceof NormalizerInterface
|
||||||
|
&& $normalizer->supportsNormalization($object, $format)) {
|
||||||
$this->normalizerCache[$class][$format] = $normalizer;
|
$this->normalizerCache[$class][$format] = $normalizer;
|
||||||
|
|
||||||
return $normalizer->normalize($object, $format, $context);
|
return $normalizer->normalize($object, $format, $context);
|
||||||
@ -273,7 +270,8 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->normalizers as $normalizer) {
|
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;
|
$this->denormalizerCache[$class][$format] = $normalizer;
|
||||||
|
|
||||||
return $normalizer->denormalize($data, $class, $format, $context);
|
return $normalizer->denormalize($data, $class, $format, $context);
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
<?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\Serializer\Tests\Normalizer;
|
||||||
|
|
||||||
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a test Normalizer which only implements the DenormalizerInterface.
|
||||||
|
*
|
||||||
|
* @author Lin Clark <lin@lin-clark.com>
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
<?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\Serializer\Tests\Normalizer;
|
||||||
|
|
||||||
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a test Normalizer which only implements the NormalizerInterface.
|
||||||
|
*
|
||||||
|
* @author Lin Clark <lin@lin-clark.com>
|
||||||
|
*/
|
||||||
|
class TestNormalizer implements NormalizerInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function normalize($object, $format = null, array $context = array())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function supportsNormalization($data, $format = null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,8 @@ use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
|
|||||||
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
|
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
|
||||||
use Symfony\Component\Serializer\Tests\Fixtures\TraversableDummy;
|
use Symfony\Component\Serializer\Tests\Fixtures\TraversableDummy;
|
||||||
use Symfony\Component\Serializer\Tests\Fixtures\NormalizableTraversableDummy;
|
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
|
class SerializerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -43,6 +45,15 @@ class SerializerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('{"foo":"normalizedFoo","bar":"normalizedBar"}', $result);
|
$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
|
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
|
||||||
*/
|
*/
|
||||||
@ -52,6 +63,16 @@ class SerializerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->serializer->denormalize('foo', 'stdClass');
|
$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()
|
public function testSerialize()
|
||||||
{
|
{
|
||||||
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
|
$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);
|
return array('title' => $this->title, 'numbers' => $this->numbers);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ class Translator implements TranslatorInterface
|
|||||||
|
|
||||||
$this->resources[$locale][] = array($format, $resource, $domain);
|
$this->resources[$locale][] = array($format, $resource, $domain);
|
||||||
|
|
||||||
if(in_array($locale, $this->fallbackLocales)) {
|
if (in_array($locale, $this->fallbackLocales)) {
|
||||||
$this->catalogues = array();
|
$this->catalogues = array();
|
||||||
} else {
|
} else {
|
||||||
unset($this->catalogues[$locale]);
|
unset($this->catalogues[$locale]);
|
||||||
|
@ -184,7 +184,7 @@
|
|||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="49">
|
<trans-unit id="49">
|
||||||
<source>The file was only partially uploaded.</source>
|
<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>
|
||||||
<trans-unit id="50">
|
<trans-unit id="50">
|
||||||
<source>No file was uploaded.</source>
|
<source>No file was uploaded.</source>
|
||||||
|
@ -421,6 +421,18 @@ class Parser
|
|||||||
return '';
|
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
|
// determine indentation if not specified
|
||||||
if (0 === $indentation) {
|
if (0 === $indentation) {
|
||||||
if (preg_match('/^ +/', $this->currentLine, $matches)) {
|
if (preg_match('/^ +/', $this->currentLine, $matches)) {
|
||||||
@ -428,11 +440,9 @@ class Parser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$text = '';
|
|
||||||
if ($indentation > 0) {
|
if ($indentation > 0) {
|
||||||
$pattern = sprintf('/^ {%d}(.*)$/', $indentation);
|
$pattern = sprintf('/^ {%d}(.*)$/', $indentation);
|
||||||
|
|
||||||
$isCurrentLineBlank = $this->isCurrentLineBlank();
|
|
||||||
while (
|
while (
|
||||||
$notEOF && (
|
$notEOF && (
|
||||||
$isCurrentLineBlank ||
|
$isCurrentLineBlank ||
|
||||||
|
@ -396,6 +396,27 @@ EOF;
|
|||||||
$this->assertSame($expected, $this->parser->parse($yaml));
|
$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()
|
public function testObjectSupportEnabled()
|
||||||
{
|
{
|
||||||
$input = <<<EOF
|
$input = <<<EOF
|
||||||
|
Reference in New Issue
Block a user