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 ;
20+ use Magento \TestFramework \Helper \Bootstrap ;
1921use Magento \TestFramework \ObjectManager ;
2022use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
2123use Magento \TestFramework \TestCase \GraphQlAbstract ;
2224
2325/**
2426 * Test loading of category tree
27+ *
28+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2529 */
2630class CategoryTest extends GraphQlAbstract
2731{
@@ -47,7 +51,7 @@ class CategoryTest extends GraphQlAbstract
4751
4852 protected function setUp (): void
4953 {
50- $ this ->objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
54+ $ this ->objectManager = Bootstrap::getObjectManager ();
5155 $ this ->categoryRepository = $ this ->objectManager ->get (CategoryRepository::class);
5256 $ this ->store = $ this ->objectManager ->get (Store::class);
5357 $ this ->metadataPool = $ this ->objectManager ->get (MetadataPool::class);
@@ -587,9 +591,12 @@ public function testCategoryImage(?string $imagePrefix)
587591 ->getFirstItem ();
588592 $ categoryId = $ categoryModel ->getId ();
589593
594+ /** @var ResourceConnection $resourceConnection */
595+ $ resourceConnection = Bootstrap::getObjectManager ()->create (ResourceConnection::class);
596+ $ connection = $ resourceConnection ->getConnection ();
597+
590598 if ($ imagePrefix !== null ) {
591- // update image to account for different stored image formats
592- $ connection = $ categoryCollection ->getConnection ();
599+ // update image to account for different stored image format
593600 $ productLinkField = $ this ->metadataPool
594601 ->getMetadata (\Magento \Catalog \Api \Data \ProductInterface::class)
595602 ->getLinkField ();
@@ -599,20 +606,20 @@ public function testCategoryImage(?string $imagePrefix)
599606 $ imageAttributeValue = $ imagePrefix . basename ($ categoryModel ->getImage ());
600607
601608 if (!empty ($ imageAttributeValue )) {
602- $ query = sprintf (
609+ $ sqlQuery = sprintf (
603610 'UPDATE %s SET `value` = "%s" ' .
604611 'WHERE `%s` = %d ' .
605612 'AND `store_id`= %d ' .
606613 'AND `attribute_id` = ' .
607614 '(SELECT `ea`.`attribute_id` FROM %s ea WHERE `ea`.`attribute_code` = "image" LIMIT 1) ' ,
608- $ connection ->getTableName ('catalog_category_entity_varchar ' ),
615+ $ resourceConnection ->getTableName ('catalog_category_entity_varchar ' ),
609616 $ imageAttributeValue ,
610617 $ productLinkField ,
611618 $ categoryModel ->getData ($ productLinkField ),
612619 $ defaultStoreId ,
613- $ connection ->getTableName ('eav_attribute ' )
620+ $ resourceConnection ->getTableName ('eav_attribute ' )
614621 );
615- $ connection ->query ($ query );
622+ $ connection ->query ($ sqlQuery );
616623 }
617624 }
618625
0 commit comments