12
12
use Magento \Catalog \Api \ProductRepositoryInterface ;
13
13
use Magento \Catalog \Model \CategoryRepository ;
14
14
use Magento \Catalog \Model \ResourceModel \Category \Collection as CategoryCollection ;
15
+ use Magento \Framework \App \ResourceConnection ;
15
16
use Magento \Framework \DataObject ;
16
17
use Magento \Framework \EntityManager \MetadataPool ;
17
18
use Magento \Store \Model \Store ;
18
19
use Magento \Store \Model \StoreManagerInterface ;
20
+ use Magento \TestFramework \Helper \Bootstrap ;
19
21
use Magento \TestFramework \ObjectManager ;
20
22
use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
21
23
use Magento \TestFramework \TestCase \GraphQlAbstract ;
22
24
23
25
/**
24
26
* Test loading of category tree
27
+ *
28
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25
29
*/
26
30
class CategoryTest extends GraphQlAbstract
27
31
{
@@ -47,7 +51,7 @@ class CategoryTest extends GraphQlAbstract
47
51
48
52
protected function setUp (): void
49
53
{
50
- $ this ->objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
54
+ $ this ->objectManager = Bootstrap::getObjectManager ();
51
55
$ this ->categoryRepository = $ this ->objectManager ->get (CategoryRepository::class);
52
56
$ this ->store = $ this ->objectManager ->get (Store::class);
53
57
$ this ->metadataPool = $ this ->objectManager ->get (MetadataPool::class);
@@ -587,9 +591,12 @@ public function testCategoryImage(?string $imagePrefix)
587
591
->getFirstItem ();
588
592
$ categoryId = $ categoryModel ->getId ();
589
593
594
+ /** @var ResourceConnection $resourceConnection */
595
+ $ resourceConnection = Bootstrap::getObjectManager ()->create (ResourceConnection::class);
596
+ $ connection = $ resourceConnection ->getConnection ();
597
+
590
598
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
593
600
$ productLinkField = $ this ->metadataPool
594
601
->getMetadata (\Magento \Catalog \Api \Data \ProductInterface::class)
595
602
->getLinkField ();
@@ -599,20 +606,20 @@ public function testCategoryImage(?string $imagePrefix)
599
606
$ imageAttributeValue = $ imagePrefix . basename ($ categoryModel ->getImage ());
600
607
601
608
if (!empty ($ imageAttributeValue )) {
602
- $ query = sprintf (
609
+ $ sqlQuery = sprintf (
603
610
'UPDATE %s SET `value` = "%s" ' .
604
611
'WHERE `%s` = %d ' .
605
612
'AND `store_id`= %d ' .
606
613
'AND `attribute_id` = ' .
607
614
'(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 ' ),
609
616
$ imageAttributeValue ,
610
617
$ productLinkField ,
611
618
$ categoryModel ->getData ($ productLinkField ),
612
619
$ defaultStoreId ,
613
- $ connection ->getTableName ('eav_attribute ' )
620
+ $ resourceConnection ->getTableName ('eav_attribute ' )
614
621
);
615
- $ connection ->query ($ query );
622
+ $ connection ->query ($ sqlQuery );
616
623
}
617
624
}
618
625
0 commit comments