diff --git a/src/Response/SearchByFeatureResponse.php b/src/Response/SearchByFeatureResponse.php index 969a67c..df0c270 100644 --- a/src/Response/SearchByFeatureResponse.php +++ b/src/Response/SearchByFeatureResponse.php @@ -20,7 +20,7 @@ private function __construct(array $uids) public static function fromArray(array $response): SearchByFeatureResponse { try { - $products = $response['products']; + $products = $response[0]['products']; $responseUids = array_map( static function ($item) { Assert::keyExists($item, 'uid'); diff --git a/tests/Unit/Response/SearchByFeatureResponseTest.php b/tests/Unit/Response/SearchByFeatureResponseTest.php index f7a341e..41f94be 100644 --- a/tests/Unit/Response/SearchByFeatureResponseTest.php +++ b/tests/Unit/Response/SearchByFeatureResponseTest.php @@ -16,15 +16,17 @@ class SearchByFeatureResponseTest extends TestCase public function correctlyReturnsUids(): void { $responseData = [ - 'products' => [ - [ - 'uid' => 'uid1', - ], - [ - 'uid' => 'uid2', - ], - [ - 'uid' => 'uid3', + [ + 'products' => [ + [ + 'uid' => 'uid1', + ], + [ + 'uid' => 'uid2', + ], + [ + 'uid' => 'uid3', + ], ], ], ]; @@ -47,15 +49,17 @@ public function correctlyReturnsUids(): void public function malformedResponseWithoutUidInOneItem(): void { $responseData = [ - 'products' => [ - [ - 'uid' => 'uid1', - ], - [ - 'id' => 'uid2', - ], - [ - 'uid' => 'uid3', + [ + 'products' => [ + [ + 'uid' => 'uid1', + ], + [ + 'id' => 'uid2', + ], + [ + 'uid' => 'uid3', + ], ], ], ]; @@ -70,12 +74,14 @@ public function malformedResponseWithoutUidInOneItem(): void public function malformedResponseWithoutUid(): void { $responseData = [ - 'products' => [ - [ - 'result' => 'uid1', - ], - [ - 'result' => 'uid2', + [ + 'products' => [ + [ + 'result' => 'uid1', + ], + [ + 'result' => 'uid2', + ], ], ], ]; @@ -91,13 +97,15 @@ public function malformedResponseWithoutProducts(): void { $responseData = [ [ - 'uid' => 'uid1', - ], - [ - 'uid' => 'uid2', - ], - [ - 'uid' => 'uid3', + [ + 'uid' => 'uid1', + ], + [ + 'uid' => 'uid2', + ], + [ + 'uid' => 'uid3', + ], ], ]; diff --git a/tests/Unit/Service/SearchByImageClientSearchByFeatureTest.php b/tests/Unit/Service/SearchByImageClientSearchByFeatureTest.php index c184112..fd73076 100644 --- a/tests/Unit/Service/SearchByImageClientSearchByFeatureTest.php +++ b/tests/Unit/Service/SearchByImageClientSearchByFeatureTest.php @@ -130,17 +130,19 @@ private function prepareProperResponse(string $uid1, string $uid2, string $uid3) { $result = [ 'results' => [ - 'products' => [ - [ - 'uid' => $uid1, - 'otherData' => 'some data', - ], - [ - 'uid' => $uid2, - ], - [ - 'uid' => $uid3, - 'category' => 'category', + [ + 'products' => [ + [ + 'uid' => $uid1, + 'otherData' => 'some data', + ], + [ + 'uid' => $uid2, + ], + [ + 'uid' => $uid3, + 'category' => 'category', + ], ], ], ], @@ -154,9 +156,11 @@ private function prepareNotProperResponse(): string return \json_encode( [ 'results' => [ - 'items' => [ - [ - 'uid' => 'uid', + [ + 'items' => [ + [ + 'uid' => 'uid', + ], ], ], ],