Skip to content

Commit 9b1edbe

Browse files
committed
Merge remote-tracking branch 'origin/MC-21003' into 2.3-develop-com-pr5
2 parents 8e43958 + b3eafd4 commit 9b1edbe

29 files changed

+1722
-178
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\TestFramework\Eav\Model\ResourceModel;
9+
10+
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set as AttributeSetResource;
11+
12+
/**
13+
* Search and return attribute data from eav entity attribute table.
14+
*/
15+
class GetEntityIdByAttributeId
16+
{
17+
/**
18+
* @var AttributeSetResource
19+
*/
20+
private $attributeSetResource;
21+
22+
/**
23+
* @param AttributeSetResource $setResource
24+
*/
25+
public function __construct(
26+
AttributeSetResource $setResource
27+
) {
28+
$this->attributeSetResource = $setResource;
29+
}
30+
31+
/**
32+
* Returns entity attribute by id.
33+
*
34+
* @param int $setId
35+
* @param int $attributeId
36+
* @return int|null
37+
*/
38+
public function execute(int $setId, int $attributeId): ?int
39+
{
40+
$select = $this->attributeSetResource->getConnection()->select()
41+
->from($this->attributeSetResource->getTable('eav_entity_attribute'))
42+
->where('attribute_set_id = ?', $setId)
43+
->where('attribute_id = ?', $attributeId);
44+
45+
$result = $this->attributeSetResource->getConnection()->fetchOne($select);
46+
return $result ? (int)$result : null;
47+
}
48+
}

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/SetTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set as AttributeSetResource;
1717
use Magento\Framework\Api\AttributeInterface;
1818
use Magento\Framework\ObjectManagerInterface;
19-
use Magento\TestFramework\Helper\Bootstrap;
2019
use Magento\TestFramework\Eav\Model\GetAttributeGroupByName;
20+
use Magento\TestFramework\Eav\Model\ResourceModel\GetEntityIdByAttributeId;
21+
use Magento\TestFramework\Helper\Bootstrap;
2122

2223
/**
2324
* Provides tests for attribute set model saving.
2425
*
2526
* @magentoDbIsolation enabled
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2628
*/
2729
class SetTest extends \PHPUnit\Framework\TestCase
2830
{
@@ -66,6 +68,11 @@ class SetTest extends \PHPUnit\Framework\TestCase
6668
*/
6769
private $attributeGroupByName;
6870

71+
/**
72+
* @var GetEntityIdByAttributeId
73+
*/
74+
private $getEntityIdByAttributeId;
75+
6976
/**
7077
* @inheritdoc
7178
*/
@@ -80,6 +87,7 @@ protected function setUp()
8087
$this->attributeSetResource = $this->objectManager->get(AttributeSetResource::class);
8188
$this->attributeCollectionFactory = $this->objectManager->get(CollectionFactory ::class);
8289
$this->attributeGroupByName = $this->objectManager->get(GetAttributeGroupByName::class);
90+
$this->getEntityIdByAttributeId = $this->objectManager->get(GetEntityIdByAttributeId::class);
8391
}
8492

8593
/**
@@ -263,11 +271,6 @@ private function getSetExcludedAttributes(int $setId): array
263271
*/
264272
private function getEntityAttributeId(int $setId, int $attributeId): int
265273
{
266-
$select = $this->attributeSetResource->getConnection()->select()
267-
->from($this->attributeSetResource->getTable('eav_entity_attribute'), ['entity_attribute_id'])
268-
->where('attribute_set_id = ?', $setId)
269-
->where('attribute_id = ?', $attributeId);
270-
271-
return (int)$this->attributeSetResource->getConnection()->fetchOne($select);
274+
return $this->getEntityIdByAttributeId->execute($setId, $attributeId);
272275
}
273276
}

0 commit comments

Comments
 (0)