|
27 | 27 | use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
|
28 | 28 | use Symfony\Component\Serializer\Serializer;
|
29 | 29 | use Symfony\Component\Serializer\SerializerInterface;
|
| 30 | +use Symfony\Component\Serializer\Tests\Fixtures\Dummy; |
30 | 31 | use Symfony\Component\Serializer\Tests\Fixtures\GroupDummy;
|
31 | 32 | use Symfony\Component\Serializer\Tests\Fixtures\GroupDummyChild;
|
32 | 33 | use Symfony\Component\Serializer\Tests\Fixtures\PropertyCircularReferenceDummy;
|
@@ -407,6 +408,52 @@ public function testInheritedPropertiesSupport()
|
407 | 408 | {
|
408 | 409 | $this->assertTrue($this->normalizer->supportsNormalization(new PropertyChildDummy()));
|
409 | 410 | }
|
| 411 | + |
| 412 | + public function testMultiDimensionObject() |
| 413 | + { |
| 414 | + $normalizer = $this->getDenormalizerForTypeEnforcement(); |
| 415 | + $root = $normalizer->denormalize([ |
| 416 | + 'children' => [[ |
| 417 | + ['foo' => 'one', 'bar' => 'two'], |
| 418 | + ['foo' => 'three', 'bar' => 'four'], |
| 419 | + ]], |
| 420 | + 'grandChildren' => [[[ |
| 421 | + ['foo' => 'five', 'bar' => 'six'], |
| 422 | + ['foo' => 'seven', 'bar' => 'eight'], |
| 423 | + ]]], |
| 424 | + 'intMatrix' => [ |
| 425 | + [0, 1, 2], |
| 426 | + [3, 4, 5], |
| 427 | + ], |
| 428 | + ], |
| 429 | + RootDummy::class, |
| 430 | + 'any' |
| 431 | + ); |
| 432 | + $this->assertEquals(\get_class($root), RootDummy::class); |
| 433 | + |
| 434 | + // children (two dimension array) |
| 435 | + $this->assertCount(1, $root->children); |
| 436 | + $this->assertCount(2, $root->children[0]); |
| 437 | + $firstChild = $root->children[0][0]; |
| 438 | + $this->assertInstanceOf(Dummy::class, $firstChild); |
| 439 | + $this->assertSame('one', $firstChild->foo); |
| 440 | + $this->assertSame('two', <
8000
span class=pl-s1>$firstChild->bar); |
| 441 | + |
| 442 | + // grand children (three dimension array) |
| 443 | + $this->assertCount(1, $root->grandChildren); |
| 444 | + $this->assertCount(1, $root->grandChildren[0]); |
| 445 | + $this->assertCount(2, $root->grandChildren[0][0]); |
| 446 | + $firstGrandChild = $root->grandChildren[0][0][0]; |
| 447 | + $this->assertInstanceOf(Dummy::class, $firstGrandChild); |
| 448 | + $this->assertSame('five', $firstGrandChild->foo); |
| 449 | + $this->assertSame('six', $firstGrandChild->bar); |
| 450 | + |
| 451 | + // int matrix |
| 452 | + $this->assertSame([ |
| 453 | + [0, 1, 2], |
| 454 | + [3, 4, 5], |
| 455 | + ], $root->intMatrix); |
| 456 | + } |
410 | 457 | }
|
411 | 458 |
|
412 | 459 | class PropertyDummy
|
@@ -472,3 +519,34 @@ class PropertyParentDummy
|
472 | 519 | class PropertyChildDummy extends PropertyParentDummy
|
473 | 520 | {
|
474 | 521 | }
|
| 522 | + |
| 523 | +class RootDummy |
| 524 | +{ |
| 525 | + public $children; |
| 526 | + public $grandChildren; |
| 527 | + public $intMatrix; |
| 528 | + |
| 529 | + /** |
| 530 | + * @return Dummy[][] |
| 531 | + */ |
| 532 | + public function getChildren(): array |
| 533 | + { |
| 534 | + return $this->children; |
| 535 | + } |
| 536 | + |
| 537 | + /** |
| 538 | + * @return Dummy[][][] |
| 539 | + */ |
| 540 | + public function getGrandChildren() |
| 541 | + { |
| 542 | + return $this->grandChildren; |
| 543 | + } |
| 544 | + |
| 545 | + /** |
| 546 | + * @return array |
| 547 | + */ |
| 548 | + public function getIntMatrix() |
| 549 | + { |
| 550 | + return $this->intMatrix; |
| 551 | + } |
| 552 | +} |
0 commit comments