From 20317698e9785f8977ade6286f650b7b70a334b7 Mon Sep 17 00:00:00 2001 From: Rinsvent Date: Sun, 29 Aug 2021 17:11:17 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D1=83=20Traver?= =?UTF-8?q?sable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Dto2DataConverter.php | 2 +- tests/unit/Converter/FillTest.php | 22 +++++++++++- .../fixtures/FillTest/Collection.php | 34 +++++++++++++++++++ .../fixtures/FillTest/CollectionItem.php | 13 +++++++ .../fixtures/FillTest/HelloRequest.php | 1 + .../fixtures/FillTest/HelloSchema.php | 5 ++- 6 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 tests/unit/Converter/fixtures/FillTest/Collection.php create mode 100644 tests/unit/Converter/fixtures/FillTest/CollectionItem.php 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' + ], ]; }