@@ -1933,21 +1933,18 @@ 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
+ $ this ->assertCount (count ($ categoryIds ), $ response ['products ' ]['items ' ][$ itemIndex ]['categories ' ]);
1938
+ $ categoryInResponse = array_combine (
1939
+ array_column ($ response ['products ' ]['items ' ][$ itemIndex ]['categories ' ], 'id ' ),
1943
1940
$ response ['products ' ]['items ' ][$ itemIndex ]['categories ' ]
1944
1941
);
1945
- foreach ($ categoryInResponse as $ key => $ categoryData ) {
1946
- $ this ->assertNotEmpty ( $ categoryData );
1942
+ foreach ($ categoryIds as $ categoryId ) {
1943
+ $ this ->assertArrayHasKey ( $ categoryId , $ categoryInResponse );
1947
1944
/** @var CategoryInterface | Category $category */
1948
- $ category = $ this ->categoryRepository ->get ($ categoryInResponse [ $ key ][ 0 ] );
1945
+ $ category = $ this ->categoryRepository ->get ($ categoryId );
1949
1946
$ this ->assertResponseFields (
1950
- $ categoryInResponse [$ key ][ 1 ],
1947
+ $ categoryInResponse [$ categoryId ],
1951
1948
[
1952
1949
'name ' => $ category ->getName (),
1953
1950
'id ' => $ category ->getId (),
0 commit comments