Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a15a534

Browse files
committed
Fabbot patches
1 parent a64a48c commit a15a534

File tree

2 files changed

+164
-167
lines changed

2 files changed

+164
-167
lines changed

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,9 @@ private function updateData(array $data, string $attribute, mixed $attributeValu
702702

703703
if ($this->nameConverter) {
704704
$attribute = $this->nameConverter->normalize($attribute, $class, $format, $context);
705-
} elseif ($flattenNestedAttributes) {
706-
throw new LogicException('A metadata aware name converter must be provided in the constructor when setting "flatten_nested_attributes" to true.');
707-
}
705+
} elseif ($flattenNestedAttributes) {
706+
throw new LogicException('A metadata aware name converter must be provided in the constructor when setting "flatten_nested_attributes" to true.');
707+
}
708708

709709
if ($flattenNestedAttributes && false !== strpos($attribute, self::FLATTENER)) {
710710
$elements = explode(self::FLATTENER, $attribute);
@@ -854,7 +854,7 @@ private function setNestedValue($data, $elements, $value)
854854
throw new LogicException(sprintf('The element you are trying to set is already populated: "%s".', $element));
855855
}
856856
if (0 === \count($elements)) {
857-
$data[$element] = $value;
857+
$data[$element] = $value;
858858
} else {
859859
if (!isset($data[$element])) {
860860
$data[$element] = [];

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php

+160-163
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
1717
use Symfony\Component\PropertyInfo\Type;
1818
use Symfony\Component\Serializer\Annotation\SerializedName;
19-
use Symfony\Component\Serializer\Encoder\JsonEncoder;
20-
use Symfony\Component\Serializer\Encoder\XmlEncoder;
2119
use Symfony\Component\Serializer\Exception\ExtraAttributesException;
2220
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
2321
use Symfony\Component\Serializer\Exception\LogicException;
@@ -106,146 +104,146 @@ public function testDenormalizeWithExtraAttributesAndNoGroupsWithMetadataFactory
106104
);
107105
}
108106

109-
public function testDenormalizeWithNestedAttributesAndNoMetadataFactory()
110-
{
111-
$this->expectException(LogicException::class);
107+
public function testDenormalizeWithNestedAttributesAndNoMetadataFactory()
108+
{
109+
$this->expectException(LogicException::class);
112110
$this->expectExceptionMessage('A class metadata factory must be provided in the constructor when setting "flatten_nested_attributes" to true.');
113-
$normalizer = new ObjectNormalizer();
114-
$normalizer->denormalize(
115-
[],
116-
NestedDummy::class,
117-
'any',
118-
['flatten_nested_attributes' => true]
119-
);
120-
}
121-
122-
public function testDenormalizeWithDuplicateNestedAttributes()
123-
{
124-
$this->expectException(LogicException::class);
111+
$normalizer = new ObjectNormalizer();
112+
$normalizer->denormalize(
113+
[],
114+
NestedDummy::class,
115+
'any',
116+
['flatten_nested_attributes' => true]
117+
);
118+
}
119+
120+
public function testDenormalizeWithDuplicateNestedAttributes()
121+
{
122+
$this->expectException(LogicException::class);
125123
$this->expectExceptionMessage('Duplicate serialized name: "one.two.three"');
126124
$normalizer = new AbstractObjectNormalizerWithMetadata();
127-
$normalizer->denormalize(
128-
[],
129-
DuplicateNestedDummy::class,
130-
'any',
131-
['flatten_nested_attributes' => true]
132-
);
133-
}
134-
135-
public function testDenormalizeWithNestedAttributes()
136-
{
125+
$normalizer->denormalize(
126+
[],
127+
DuplicateNestedDummy::class,
128+
'any',
129+
['flatten_nested_attributes' => true]
130+
);
131+
}
132+
133+
public function testDenormalizeWithNestedAttributes()
134+
{
137135
$normalizer = new AbstractObjectNormalizerWithMetadata();
138-
$data = [
139-
'one' => [
140-
'two' => [
141-
'three' => 'foo'
142-
],
143-
'four' => 'bar'
144-
]
145-
];
146-
$test = $normalizer->denormalize(
147-
$data,
148-
NestedDummy::class,
149-
'any',
150-
['flatten_nested_attributes' => true]
151-
);
152-
$this->assertEquals('foo', $test->foo);
153-
$this->assertEquals('bar', $test->bar);
154-
}
155-
156-
public function testNormalizeWithNestedAttributesAndNoMetadataNameConverter()
157-
{
158-
$this->expectException(LogicException::class);
136+
$data = [
137+
'one' => [
138+
'two' => [
139+
'three' => 'foo',
140+
],
141+
'four' => 'bar',
142+
],
143+
];
144+
$test = $normalizer->denormalize(
145+
$data,
146+
NestedDummy::class,
147+
'any',
148+
['flatten_nested_attributes' => true]
149+
);
150+
$this->assertEquals('foo', $test->foo);
151+
$this->assertEquals('bar', $test->bar);
152+
}
153+
154+
public function testNormalizeWithNestedAttributesAndNoMetadataNameConverter()
155+
{
156+
$this->expectException(LogicException::class);
159157
$this->expectExceptionMessage('A metadata aware name converter must be provided in the constructor when setting "flatten_nested_attributes" to true.');
160-
$foobar = new NestedDummy();
161-
$foobar->foo = 'foo';
162-
$foobar->bar = 'bar';
163-
$normalizer = new ObjectNormalizer();
164-
$normalizer->normalize(
165-
$foobar,
166-
'any',
167-
['flatten_nested_attributes' => true]
168-
);
169-
}
170-
171-
public function testNormalizeWithNestedAttributesMixingArrayTypes()
172-
{
173-
$this->expectException(LogicException::class);
158+
$foobar = new NestedDummy();
159+
$foobar->foo = 'foo';
160+
$foobar->bar = 'bar';
161+
$normalizer = new ObjectNormalizer();
162+
$normalizer->normalize(
163+
$foobar,
164+
'any',
165+
['flatten_nested_attributes' => true]
166+
);
167+
}
168+
169+
public function testNormalizeWithNestedAttributesMixingArrayTypes()
170+
{
171+
$this->expectException(LogicException::class);
174172
$this->expectExceptionMessage('The element you are trying to set is already populated: "two"');
175-
$foobar = new AlreadyPopulatedNestedDummy();
176-
$foobar->foo = 'foo';
177-
$foobar->bar = 'bar';
178-
$normalizer = new ObjectNormalizer(
179-
null,
180-
new MetadataAwareNameConverter(
181-
new ClassMetadataFactory(
182-
new AnnotationLoader(
183-
new AnnotationReader()
184-
)
185-
)
186-
)
187-
);
188-
$normalizer->normalize(
189-
$foobar,
190-
'any',
191-
['flatten_nested_attributes' => true]
192-
);
193-
}
194-
195-
public function testNormalizeWithNestedAttributesElementAlreadySet()
196-
{
197-
$this->expectException(LogicException::class);
173+
$foobar = new AlreadyPopulatedNestedDummy();
174+
$foobar->foo = 'foo';
175+
$foobar->bar = 'bar';
176+
$normalizer = new ObjectNormalizer(
177+
null,
178+
new MetadataAwareNameConverter(
179+
new ClassMetadataFactory(
180+
new AnnotationLoader(
181+
new AnnotationReader()
182+
)
183+
)
184+
)
185+
);
186+
$normalizer->normalize(
187+
$foobar,
188+
'any',
189+
['flatten_nested_attributes' => true]
190+
);
191+
}
192+
193+
public function testNormalizeWithNestedAttributesElementAlreadySet()
194+
{
195+
$this->expectException(LogicException::class);
198196
$this->expectExceptionMessage('The element you are trying to set is already populated: "three"');
199-
$foobar = new DuplicateNestedDummy();
200-
$foobar->foo = 'foo';
201-
$foobar->bar = 'bar';
202-
$normalizer = new ObjectNormalizer(
203-
null,
204-
new MetadataAwareNameConverter(
205-
new ClassMetadataFactory(
206-
new AnnotationLoader(
207-
new AnnotationReader()
208-
)
209-
)
210-
)
211-
);
212-
$normalizer->normalize(
213-
$foobar,
214-
'any',
215-
['flatten_nested_attributes' => true]
216-
);
217-
}
218-
219-
public function testNormalizeWithNestedAttributes()
220-
{
221-
$foobar = new NestedDummy();
222-
$foobar->foo = 'foo';
223-
$foobar->bar = 'bar';
224-
$data = [
225-
'one' => [
226-
'two' => [
227-
'three' => 'foo'
228-
],
229-
'four' => 'bar'
230-
]
231-
];
232-
$normalizer = new ObjectNormalizer(
233-
null,
234-
new MetadataAwareNameConverter(
235-
new ClassMetadataFactory(
236-
new AnnotationLoader(
237-
new AnnotationReader()
238-
)
239-
)
240-
)
241-
);
242-
$test = $normalizer->normalize(
243-
$foobar,
244-
'any',
245-
['flatten_nested_attributes' => true]
246-
);
247-
$this->assertEquals($data, $test);
248-
}
197+
$foobar = new DuplicateNestedDummy();
198+
$foobar->foo = 'foo';
199+
$foobar->bar = 'bar';
200+
$normalizer = new ObjectNormalizer(
201+
null,
202+
new MetadataAwareNameConverter(
203+
new ClassMetadataFactory(
204+
new AnnotationLoader(
205+
new AnnotationReader()
206+
)
207+
)
208+
)
209+
);
210+
$normalizer->normalize(
211+
$foobar,
212+
'any',
213+
['flatten_nested_attributes' => true]
214+
);
215+
}
216+
217+
public function testNormalizeWithNestedAttributes()
218+
{
219+
$foobar = new NestedDummy();
220+
$foobar->foo = 'foo';
221+
$foobar->bar = 'bar';
222+
$data = [
223+
'one' => [
224+
'two' => [
225+
'three' => 'foo',
226+
],
227+
'four' => 'bar',
228+
],
229+
];
230+
$normalizer = new ObjectNormalizer(
231+
null,
232+
new MetadataAwareNameConverter(
233+
new ClassMetadataFactory(
234+
new AnnotationLoader(
235+
new AnnotationReader()
236+
)
237+
)
238+
)
239+
);
240+
$test = $normalizer->normalize(
241+
$foobar,
242+
'any',
243+
['flatten_nested_attributes' => true]
244+
);
245+
$this->assertEquals($data, $test);
246+
}
249247

250248
public function testDenormalizeCollectionDecodedFromXmlWithOneChild()
251249
{
@@ -574,42 +572,41 @@ class EmptyDummy
574572

575573
class AlreadyPopulatedNestedDummy
576574
{
577-
/**
578-
* @SerializedName("one.two.three")
579-
*/
580-
public $foo;
581-
582-
/**
583-
* @SerializedName("one.two")
584-
*/
585-
public $bar;
586-
}
575+
/**
576+
* @SerializedName("one.two.three")
577+
*/
578+
public $foo;
587579

580+
/**
581+
* @SerializedName("one.two")
582+
*/
583+
public $bar;
584+
}
588585

589586
class DuplicateNestedDummy
590587
{
591-
/**
592-
* @SerializedName("one.two.three")
593-
*/
594-
public $foo;
595-
596-
/**
597-
* @SerializedName("one.two.three")
598-
*/
599-
public $bar;
588+
/**
589+
* @SerializedName("one.two.three")
590+
*/
591+
public $foo;
592+
593+
/**
594+
* @SerializedName("one.two.three")
595+
*/
596+
public $bar;
600597
}
601598

602599
class NestedDummy
603600
{
604-
/**
605-
* @SerializedName("one.two.three")
606-
*/
607-
public $foo;
608-
609-
/**
610-
* @SerializedName("one.four")
611-
*/
612-
public $bar;
601+
/**
602+
* @SerializedName("one.two.three")
603+
*/
604+
public $foo;
605+
606+
/**
607+
* @SerializedName("one.four")
608+
*/
609+
public $bar;
613610
}
614611

615612
class AbstractObjectNormalizerWithMetadata extends AbstractObjectNormalizer

0 commit comments

Comments
 (0)