@@ -1933,21 +1933,18 @@ public function testFilterProductsBySingleCategoryId(string $fieldName, string $
19331933 $ product = $ this ->productRepository ->get ($ links [$ itemIndex ]->getSku ());
19341934 $ this ->assertEquals ($ response ['products ' ]['items ' ][$ itemIndex ]['name ' ], $ product ->getName ());
19351935 $ 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 ' ),
19431940 $ response ['products ' ]['items ' ][$ itemIndex ]['categories ' ]
19441941 );
1945- foreach ($ categoryInResponse as $ key => $ categoryData ) {
1946- $ this ->assertNotEmpty ( $ categoryData );
1942+ foreach ($ categoryIds as $ categoryId ) {
1943+ $ this ->assertArrayHasKey ( $ categoryId , $ categoryInResponse );
19471944 /** @var CategoryInterface | Category $category */
1948- $ category = $ this ->categoryRepository ->get ($ categoryInResponse [ $ key ][ 0 ] );
1945+ $ category = $ this ->categoryRepository ->get ($ categoryId );
19491946 $ this ->assertResponseFields (
1950- $ categoryInResponse [$ key ][ 1 ],
1947+ $ categoryInResponse [$ categoryId ],
19511948 [
19521949 'name ' => $ category ->getName (),
19531950 'id ' => $ category ->getId (),
0 commit comments