1212use Magento \Catalog \Api \ProductRepositoryInterface ;
1313use Magento \Catalog \Model \CategoryRepository ;
1414use Magento \Catalog \Model \ResourceModel \Category \Collection as CategoryCollection ;
15+ use Magento \Framework \App \ResourceConnection ;
1516use Magento \Framework \DataObject ;
1617use Magento \Framework \EntityManager \MetadataPool ;
1718use Magento \Store \Model \Store ;
1819use Magento \Store \Model \StoreManagerInterface ;
1920use Magento \TestFramework \ObjectManager ;
21+ use Magento \TestFramework \Helper \Bootstrap ;
2022use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
2123use Magento \TestFramework \TestCase \GraphQlAbstract ;
2224
@@ -587,9 +589,12 @@ public function testCategoryImage(?string $imagePrefix)
587589 ->getFirstItem ();
588590 $ categoryId = $ categoryModel ->getId ();
589591
592+ /** @var ResourceConnection $resourceConnection */
593+ $ resourceConnection = Bootstrap::getObjectManager ()->create (ResourceConnection::class);
594+ $ connection = $ resourceConnection ->getConnection ();
595+
590596 if ($ imagePrefix !== null ) {
591- // update image to account for different stored image formats
592- $ connection = $ categoryCollection ->getConnection ();
597+ // update image to account for different stored image format
593598 $ productLinkField = $ this ->metadataPool
594599 ->getMetadata (\Magento \Catalog \Api \Data \ProductInterface::class)
595600 ->getLinkField ();
@@ -599,20 +604,20 @@ public function testCategoryImage(?string $imagePrefix)
599604 $ imageAttributeValue = $ imagePrefix . basename ($ categoryModel ->getImage ());
600605
601606 if (!empty ($ imageAttributeValue )) {
602- $ query = sprintf (
607+ $ sqlQuery = sprintf (
603608 'UPDATE %s SET `value` = "%s" ' .
604609 'WHERE `%s` = %d ' .
605610 'AND `store_id`= %d ' .
606611 'AND `attribute_id` = ' .
607612 '(SELECT `ea`.`attribute_id` FROM %s ea WHERE `ea`.`attribute_code` = "image" LIMIT 1) ' ,
608- $ connection ->getTableName ('catalog_category_entity_varchar ' ),
613+ $ resourceConnection ->getTableName ('catalog_category_entity_varchar ' ),
609614 $ imageAttributeValue ,
610615 $ productLinkField ,
611616 $ categoryModel ->getData ($ productLinkField ),
612617 $ defaultStoreId ,
613- $ connection ->getTableName ('eav_attribute ' )
618+ $ resourceConnection ->getTableName ('eav_attribute ' )
614619 );
615- $ connection ->query ($ query );
620+ $ connection ->query ($ sqlQuery );
616621 }
617622 }
618623
0 commit comments