diff --git a/src/Dto2DataConverter.php b/src/Dto2DataConverter.php index 67d41f0..f6fce26 100644 --- a/src/Dto2DataConverter.php +++ b/src/Dto2DataConverter.php @@ -65,7 +65,7 @@ class Dto2DataConverter public function convertArrayByMap($data, ?array $map, array $tags = []): ?array { - $isAssociative = count($data) && !array_key_exists(0, $data); + // $isAssociative = count($data) && !array_key_exists(0, $data); $tempValue = []; foreach ($data as $key => $item) { diff --git a/tests/unit/Converter/FillTest.php b/tests/unit/Converter/FillTest.php index 0900a39..30151d0 100644 --- a/tests/unit/Converter/FillTest.php +++ b/tests/unit/Converter/FillTest.php @@ -6,6 +6,8 @@ use Rinsvent\DTO2Data\Dto2DataConverter; use Rinsvent\DTO2Data\Tests\unit\Converter\fixtures\FillTest\Author; use Rinsvent\DTO2Data\Tests\unit\Converter\fixtures\FillTest\Bar; use Rinsvent\DTO2Data\Tests\unit\Converter\fixtures\FillTest\BuyRequest; +use Rinsvent\DTO2Data\Tests\unit\Converter\fixtures\FillTest\Collection; +use Rinsvent\DTO2Data\Tests\unit\Converter\fixtures\FillTest\CollectionItem; use Rinsvent\DTO2Data\Tests\unit\Converter\fixtures\FillTest\HelloRequest; use Rinsvent\DTO2Data\Tests\unit\Converter\fixtures\FillTest\UUID; @@ -69,6 +71,13 @@ class FillTest extends \Codeception\Test\Unit $bar->barField = 32; $helloRequest->bar = $bar; $helloRequest->uuid = new UUID('qwerqw-qwerqwe-werqw-qwerqw'); + $collection = new Collection(); + $collection->items = [ + new CollectionItem('3'), + new CollectionItem('1'), + new CollectionItem('2'), + ]; + $helloRequest->collection = $collection; $dto = $dto2DataConverter->convert($helloRequest); // codecept_debug(json_encode($dto)); @@ -106,7 +115,18 @@ class FillTest extends \Codeception\Test\Unit "bar" => [ "barField" => 32 ], - 'uuid' => 'qwerqw-qwerqwe-werqw-qwerqw' + 'uuid' => 'qwerqw-qwerqwe-werqw-qwerqw', + 'collection' => [ + [ + 'value' => '3', + ], + [ + 'value' => '1', + ], + [ + 'value' => '2', + ], + ], ], $dto); } } diff --git a/tests/unit/Converter/fixtures/FillTest/Collection.php b/tests/unit/Converter/fixtures/FillTest/Collection.php new file mode 100644 index 0000000..6458f25 --- /dev/null +++ b/tests/unit/Converter/fixtures/FillTest/Collection.php @@ -0,0 +1,34 @@ +position = 0; + } + + public function current() + { + return $this->items[$this->position]; + } + + public function key() + { + return $this->position; + } + + public function next() + { + ++$this->position; + } + + public function valid() + { + return isset($this->items[$this->position]); + } +} diff --git a/tests/unit/Converter/fixtures/FillTest/CollectionItem.php b/tests/unit/Converter/fixtures/FillTest/CollectionItem.php new file mode 100644 index 0000000..ce8380c --- /dev/null +++ b/tests/unit/Converter/fixtures/FillTest/CollectionItem.php @@ -0,0 +1,13 @@ +value = $value; + } +} diff --git a/tests/unit/Converter/fixtures/FillTest/HelloRequest.php b/tests/unit/Converter/fixtures/FillTest/HelloRequest.php index fac8df5..fab3d2c 100644 --- a/tests/unit/Converter/fixtures/FillTest/HelloRequest.php +++ b/tests/unit/Converter/fixtures/FillTest/HelloRequest.php @@ -21,4 +21,5 @@ class HelloRequest public BarInterface $bar; #[PropertyPath(path: 'uuid.id')] public UUID $uuid; + public Collection $collection; } diff --git a/tests/unit/Converter/fixtures/FillTest/HelloSchema.php b/tests/unit/Converter/fixtures/FillTest/HelloSchema.php index 9162f63..f5a84c1 100644 --- a/tests/unit/Converter/fixtures/FillTest/HelloSchema.php +++ b/tests/unit/Converter/fixtures/FillTest/HelloSchema.php @@ -26,6 +26,9 @@ class HelloSchema extends Schema 'bar' => [ 'barField' ], - 'uuid' + 'uuid', + 'collection' => [ + 'value' + ], ]; }