Skip to content

Commit 12688e7

Browse files
Merge branch '2.8' into 3.0
* 2.8: [Process] Enhance compatiblity with --enable-sigchild [Validator] removes unused variable in LengthValidator class. [FrameworkBundle] [Bug] Fixes new InputStyle bug #16920 fix short array syntax for php 5.3 [Serializer] Fixed on array of objects in . [Process] Always call proc_close [Form] Add missing tests for StringUtil::fqcnToBlockPrefix() [Security] Fix a Polyfill import statement in StringUtils [Validator] Updated Luxembourgish translations for 2.8 Improved the code of the commands that use the new SymfonyStyle class disable server commands without Process component list all server command names in suggestion Suggested Process dependency disable server:run cmd without Process component Suggested Process dependency [FrameworkBundle] prevent cache:clear creating too long paths [FrameworkBundle] [Translation] Fixed translations not written when no translations directory in update command Conflicts: .travis.yml src/Symfony/Bridge/Twig/Command/LintCommand.php src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php src/Symfony/Bundle/TwigBundle/Command/DebugCommand.php src/Symfony/Component/Security/Core/Util/StringUtils.php
2 parents 1396fdf + 1695783 commit 12688e7

File tree

4 files changed

+155
-2
lines changed

4 files changed

+155
-2
lines changed

Mapping/ClassMetadataInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
/**
1515
* Stores metadata needed for serializing and deserializing objects of specific class.
1616
*
17-
* Primarily, the metadata stores the list of attributes to serialize or deserialize.
17+
* Primarily, the metadata stores the set of attributes to serialize or deserialize.
18+
*
19+
* There may only exist one metadata for each attribute according to its name.
1820
*
1921
* @author Kévin Dunglas <dunglas@gmail.com>
2022
*/

Normalizer/AbstractNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ protected function getAllowedAttributes($classOrObject, array $context, $attribu
204204
}
205205
}
206206

207-
return array_unique($allowedAttributes);
207+
return $allowedAttributes;
208208
}
209209

210210
/**
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
15+
16+
/**
17+
* Provides a dummy Normalizer which extends the AbstractNormalizer.
18+
*
19+
* @author Konstantin S. M. Möllers <ksm.moellers@gmail.com>
20+
*/
21+
class AbstractNormalizerDummy extends AbstractNormalizer
22+
{
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false)
27+
{
28+
return parent::getAllowedAttributes($classOrObject, $context, $attributesAsString);
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function normalize($object, $format = null, array $context = array())
35+
{
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
public function supportsNormalization($data, $format = null)
42+
{
43+
return true;
44+
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function denormalize($data, $class, $format = null, array $context = array())
50+
{
51+
}
52+
53+
/**
54+
* {@inheritdoc}
55+
*/
56+
public function supportsDenormalization($data, $type, $format = null)
57+
{
58+
return true;
59+
}
60+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace Symfony\Component\Serializer\Tests\Normalizer;
4+
5+
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
6+
use Symfony\Component\Serializer\Mapping\ClassMetadata;
7+
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
8+
use Symfony\Component\Serializer\Tests\Fixtures\AbstractNormalizerDummy;
9+
10+
/**
11+
* Provides a dummy Normalizer which extends the AbstractNormalizer.
12+
*
13+
* @author Konstantin S. M. Möllers <ksm.moellers@gmail.com>
14+
*/
15+
class AbstractNormalizerTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var AbstractNormalizerDummy
19+
*/
20+
private $normalizer;
21+
22+
/**
23+
* @var ClassMetadataFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $classMetadata;
26+
27+
protected function setUp()
28+
{
29+
$loader = $this->getMock('Symfony\Component\Serializer\Mapping\Loader\LoaderChain', array(), array(array()));
30+
$this->classMetadata = $this->getMock('Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory', array(), array($loader));
31+
$this->normalizer = new AbstractNormalizerDummy($this->classMetadata);
32+
}
33+
34+
public function testGetAllowedAttributesAsString()
35+
{
36+
$classMetadata = new ClassMetadata('c');
37+
38+
$a1 = new AttributeMetadata('a1');
39+
$classMetadata->addAttributeMetadata($a1);
40+
41+
$a2 = new AttributeMetadata('a2');
42+
$a2->addGroup('test');
43+
$classMetadata->addAttributeMetadata($a2);
44+
45+
$a3 = new AttributeMetadata('a3');
46+
$a3->addGroup('other');
47+
$classMetadata->addAttributeMetadata($a3);
48+
49+
$a4 = new AttributeMetadata('a4');
50+
$a4->addGroup('test');
51+
$a4->addGroup('other');
52+
$classMetadata->addAttributeMetadata($a4);
53+
54+
$this->classMetadata->method('getMetadataFor')->willReturn($classMetadata);
55+
56+
$result = $this->normalizer->getAllowedAttributes('c', array('groups' => array('test')), true);
57+
$this->assertEquals(array('a2', 'a4'), $result);
58+
59+
$result = $this->normalizer->getAllowedAttributes('c', array('groups' => array('other')), true);
60+
$this->assertEquals(array('a3', 'a4'), $result);
61+
}
62+
63+
public function testGetAllowedAttributesAsObjects()
64+
{
65+
$classMetadata = new ClassMetadata('c');
66+
67+
$a1 = new AttributeMetadata('a1');
68+
$classMetadata->addAttributeMetadata($a1);
69+
70+
$a2 = new AttributeMetadata('a2');
71+
$a2->addGroup('test');
72+
$classMetadata->addAttributeMetadata($a2);
73+
74+
$a3 = new AttributeMetadata('a3');
75+
$a3->addGroup('other');
76+
$classMetadata->addAttributeMetadata($a3);
77+
78+
$a4 = new AttributeMetadata('a4');
79+
$a4->addGroup('test');
80+
$a4->addGroup('other');
81+
$classMetadata->addAttributeMetadata($a4);
82+
83+
$this->classMetadata->method('getMetadataFor')->willReturn($classMetadata);
84+
85+
$result = $this->normalizer->getAllowedAttributes('c', array('groups' => array('test')), false);
86+
$this->assertEquals(array($a2, $a4), $result);
87+
88+
$result = $this->normalizer->getAllowedAttributes('c', array('groups' => array('other')), false);
89+
$this->assertEquals(array($a3, $a4), $result);
90+
}
91+
}

0 commit comments

Comments
 (0)