-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
523 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ public function __construct() | |
* Create instance T class | ||
* | ||
* @param class-string<T> $class | ||
* @param iterable<mixed>|object|string ...$args | ||
* @param iterable<mixed>|object ...$args | ||
* | ||
* @return null|T | ||
* @throws ClassNotFoundException|InstantiableClassException|ReflectionException|InvalidArgumentException | ||
|
@@ -78,4 +78,22 @@ public function createMultiple(array $classes, array $args): ?array | |
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* Create instance T class | ||
* | ||
* @param class-string<T> $class | ||
* @param string $json | ||
* | ||
* @return null|T | ||
* @throws ClassNotFoundException | ||
* @throws InvalidArgumentException | ||
* @throws ReflectionException | ||
*/ | ||
public function createFromJson(string $class, string $json): mixed | ||
{ | ||
$data = json_decode($json, true); | ||
|
||
return $this->create($class, $data); | ||
Check failure on line 97 in src/Hydrator.php GitHub Actions / psalmMissingThrowsDocblock
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
use Tests\Integration\DTO\BasketDTO; | ||
use Tests\Integration\DTO\ProductDTO; | ||
use Tests\Integration\DTO\PurchaseDTO; | ||
use Tests\Integration\DTO\Full\PurchaseDTO as FullPurchaseDto; | ||
use Tests\Integration\DTO\EmptyClassDto; | ||
use Tests\Integration\DTO\ArrayScalarDTO; | ||
use Tests\Integration\DTO\UserEmptyTypeDTO; | ||
|
@@ -204,10 +205,7 @@ public function testTripleRecursiveArray(): void | |
} | ||
} | ||
} | ||
|
||
/** | ||
* @throws ReflectionException|ClassNotFoundException | ||
*/ | ||
|
||
public function testEmptyTypeObject(): void | ||
{ | ||
$data = $this->getBaseArrayData(); | ||
|
@@ -219,4 +217,159 @@ public function testEmptyTypeObject(): void | |
self::assertEquals($data['email'], $userDTO->email); | ||
self::assertEquals($data['balance'], $userDTO->balance); | ||
} | ||
|
||
public function testFull(): void | ||
{ | ||
$data = $this->getPurcheseObject(); | ||
$object = (new Hydrator)->create(FullPurchaseDto::class, $data); | ||
$this->assertEquals($data['user']['id'], $object->user->id); | ||
} | ||
|
||
public function getPurcheseObject(): array | ||
{ | ||
return [ | ||
'products' => [ | ||
[ | ||
'id' => 1, | ||
'name' => 'phone', | ||
'price' => 43.03, | ||
'description' => 'test description for phone', | ||
'count' => 123 | ||
], | ||
[ | ||
'id' => 2, | ||
'name' => 'bread', | ||
'price' => 10.56, | ||
'description' => 'test description for bread', | ||
'count' => 321 | ||
], | ||
[ | ||
'id' => 3, | ||
'name' => 'book', | ||
'price' => 5.5, | ||
'description' => 'test description for book', | ||
'count' => 333 | ||
], | ||
[ | ||
'id' => 4, | ||
'name' => 'PC', | ||
'price' => 100, | ||
'description' => 'test description for PC', | ||
'count' => 7 | ||
] | ||
], | ||
'user' => [ | ||
'id' => 1, | ||
'contact' => '[email protected]', | ||
'balance' => 10012.23, | ||
'type' => 'admin', | ||
'realAddress' => 'test address', | ||
'createdAt' => '2023-04-10', | ||
], | ||
'createdAt' => '2023-04-10', | ||
'address' => $this->getAddress() | ||
]; | ||
} | ||
|
||
private function getAddress() | ||
{ | ||
return [ | ||
"source" => "мск сухонска 11/-89", | ||
"result" => "г Москва, ул Сухонская, д 11, кв 89", | ||
"postal_code" => "127642", | ||
"country" => "Россия", | ||
"country_iso_code" => "RU", | ||
"federal_district" => "Центральный", | ||
"region_fias_id" => "0c5b2444-70a0-4932-980c-b4dc0d3f02b5", | ||
"region_kladr_id" => "7700000000000", | ||
"region_iso_code" => "RU-MOW", | ||
"region_with_type" => "г Москва", | ||
"region_type" => "г", | ||
"region_type_full" => "город", | ||
"region" => "Москва", | ||
"area_fias_id" => null, | ||
"area_kladr_id" => null, | ||
"area_with_type" => null, | ||
"area_type" => null, | ||
"area_type_full" => null, | ||
"area" => null, | ||
"city_fias_id" => null, | ||
"city_kladr_id" => null, | ||
"city_with_type" => null, | ||
"city_type" => null, | ||
"city_type_full" => null, | ||
"city" => null, | ||
"city_area" => "Северо-восточный", | ||
"city_district_fias_id" => null, | ||
"city_district_kladr_id" => null, | ||
"city_district_with_type" => "р-н Северное Медведково", | ||
"city_district_type" => "р-н", | ||
"city_district_type_full" => "район", | ||
"city_district" => "Северное Медведково", | ||
"settlement_fias_id" => null, | ||
"settlement_kladr_id" => null, | ||
"settlement_with_type" => null, | ||
"settlement_type" => null, | ||
"settlement_type_full" => null, | ||
"settlement" => null, | ||
"street_fias_id" => "95dbf7fb-0dd4-4a04-8100-4f6c847564b5", | ||
"street_kladr_id" => "77000000000283600", | ||
"street_with_type" => "ул Сухонская", | ||
"street_type" => "ул", | ||
"street_type_full" => "улица", | ||
"street" => "Сухонская", | ||
"house_fias_id" => "5ee84ac0-eb9a-4b42-b814-2f5f7c27c255", | ||
"house_kladr_id" => "7700000000028360004", | ||
"house_type" => "д", | ||
"house_type_full" => "дом", | ||
"house" => "11", | ||
"block_type" => null, | ||
"block_type_full" => null, | ||
"block" => null, | ||
"flat_fias_id" => "f26b876b-6857-4951-b060-ec6559f04a9a", | ||
"flat_type" => "кв", | ||
"flat_type_full" => "квартира", | ||
"flat" => "89", | ||
"flat_area" => "34.6", | ||
"square_meter_price" => "239953", | ||
"flat_price" => "8302374", | ||
"postal_box" => null, | ||
"fias_id" => "f26b876b-6857-4951-b060-ec6559f04a9a", | ||
"fias_code" => "77000000000000028360004", | ||
"fias_level" => "9", | ||
"kladr_id" => "7700000000028360004", | ||
"capital_marker" => "0", | ||
"okato" => "45280583000", | ||
"oktmo" => "45362000", | ||
"tax_office" => "7715", | ||
"tax_office_legal" => "7715", | ||
"timezone" => "UTC+3", | ||
"geo_lat" => "55.8782557", | ||
"geo_lon" => "37.65372", | ||
"beltway_hit" => "IN_MKAD", | ||
"beltway_distance" => null, | ||
"qc_geo" => 0, | ||
"qc_complete" => 0, | ||
"qc_house" => 2, | ||
"qc" => 0, | ||
"unparsed_parts" => null, | ||
"metro" => [ | ||
[ | ||
"distance" => 1.1, | ||
"line" => "Калужско-Рижская", | ||
"name" => "Бабушкинская" | ||
], | ||
[ | ||
"distance" => 1.2, | ||
"line" => "Калужско-Рижская", | ||
"name" => "Медведково" | ||
], | ||
[ | ||
"distance" => 2.5, | ||
"line" => "Калужско-Рижская", | ||
"name" => "Свиблово" | ||
] | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.