@@ -1933,21 +1933,20 @@ public function testFilterProductsBySingleCategoryId(string $fieldName, string $
1933
1933
$ product = $ this ->productRepository ->get ($ links [$ itemIndex ]->getSku ());
1934
1934
$ this ->assertEquals ($ response ['products ' ]['items ' ][$ itemIndex ]['name ' ], $ product ->getName ());
1935
1935
$ this ->assertEquals ($ response ['products ' ]['items ' ][$ itemIndex ]['type_id ' ], $ product ->getTypeId ());
1936
- $ categoryIds = $ product ->getCategoryIds ();
1937
- foreach ($ categoryIds as $ index => $ value ) {
1938
- $ categoryIds [$ index ] = (int )$ value ;
1939
- }
1940
- $ categoryInResponse = array_map (
1941
- null ,
1942
- $ categoryIds ,
1936
+ $ categoryIds = array_map ('intval ' , $ product ->getCategoryIds ());
1937
+ $ categoryInResponse = array_combine (
1938
+ array_column ($ response ['products ' ]['items ' ][$ itemIndex ]['categories ' ], 'id ' ),
1943
1939
$ response ['products ' ]['items ' ][$ itemIndex ]['categories ' ]
1944
1940
);
1945
- foreach ($ categoryInResponse as $ key => $ categoryData ) {
1946
- $ this ->assertNotEmpty ($ categoryData );
1941
+ sort ($ categoryIds );
1942
+ ksort ($ categoryInResponse );
1943
+ $ this ->assertCount (count ($ categoryIds ), $ categoryInResponse );
1944
+ foreach ($ categoryIds as $ categoryId ) {
1945
+ $ this ->assertArrayHasKey ($ categoryId , $ categoryInResponse );
1947
1946
/** @var CategoryInterface | Category $category */
1948
- $ category = $ this ->categoryRepository ->get ($ categoryInResponse [ $ key ][ 0 ] );
1947
+ $ category = $ this ->categoryRepository ->get ($ categoryId );
1949
1948
$ this ->assertResponseFields (
1950
- $ categoryInResponse [$ key ][ 1 ],
1949
+ $ categoryInResponse [$ categoryId ],
1951
1950
[
1952
1951
'name ' => $ category ->getName (),
1953
1952
'id ' => $ category ->getId (),
0 commit comments