Skip to content

Commit 780c4e1

Browse files
committed
LYNX-100: Refactoring
1 parent 5a97157 commit 780c4e1

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

app/code/Magento/EavGraphQl/Model/Resolver/EntityTypeAttributesList.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function resolve(
7474
$errors = [];
7575

7676
if (!$args['entity_type']) {
77-
throw new GraphQlInputException(__("Missing rquired 'entity_type' argument"));
77+
throw new GraphQlInputException(__('Required parameter "%1" of type string.', 'entity_type'));
7878
}
7979

8080
$entityType = $this->enumLookup->getEnumValueFromField(
@@ -108,22 +108,14 @@ private function getAtrributesMetadata($attributesList)
108108
return array_map(function ($attribute) {
109109
return [
110110
'uid' => $attribute->getAttributeId(),
111-
'is_unique' => $attribute->getIsUnique(),
112-
'scope' => $attribute->getData('scope'),
113-
'frontend_class' => $attribute->getData('frontend_class'),
114-
'frontend_input' => $attribute->getData('frontend_input'),
115111
'attribute_code' => $attribute->getData('attribute_code'),
116-
'is_required' => $attribute->getData('is_required'),
117-
'options' => $attribute->getData('options'),
118-
'is_user_defined' => $attribute->getData('is_user_defined'),
119112
'frontend_label' => $attribute->getData('frontend_label'),
120-
'note' => $attribute->getData('note'),
121-
'frontend_labels' => $attribute->getData('frontend_labels'),
122-
'backend_type' => $attribute->getData('backend_type'),
123-
'source_model' => $attribute->getData('source_model'),
124-
'backend_model' => $attribute->getData('backend_model'),
125-
'validate_rules' => $attribute->getData('validate_rules'),
126-
'entity_type_id' => $attribute->getData('entity_type_id')
113+
'entity_type_id' => $attribute->getData('entity_type_id'),
114+
'frontend_input' => $attribute->getData('frontend_input'),
115+
'is_required' => $attribute->getData('is_required'),
116+
'default_value' => $attribute->getData('default_value'),
117+
'is_unique' => $attribute->getIsUnique(),
118+
'options' => $attribute->getData('options')
127119
];
128120
}, $attributesList);
129121
}

dev/tests/api-functional/testsuite/Magento/GraphQl/EavGraphQl/EntityTypeAttributesListTest.php

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Customer\Api\CustomerMetadataInterface;
1111
use Magento\Catalog\Setup\CategorySetup;
1212
use Magento\Eav\Test\Fixture\Attribute;
13+
use Magento\Sales\Setup\SalesSetup;
1314
use Magento\TestFramework\Fixture\DataFixture;
1415
use Magento\TestFramework\TestCase\GraphQlAbstract;
1516

@@ -61,8 +62,17 @@ class EntityTypeAttributesListTest extends GraphQlAbstract
6162
],
6263
'attribute4'
6364
)
65+
,
66+
DataFixture(
67+
Attribute::class,
68+
[
69+
'entity_type_id' => SalesSetup::CREDITMEMO_PRODUCT_ENTITY_TYPE_ID,
70+
'attribute_code' => 'attribute_5'
71+
],
72+
'attribute5'
73+
)
6474
]
65-
public function testAttributesList(): void
75+
public function testEntityTypeAttributesList(): void
6676
{
6777
$queryResult = $this->graphQlQuery(<<<QRY
6878
{
@@ -82,18 +92,26 @@ public function testAttributesList(): void
8292
$this->assertArrayHasKey('items', $queryResult['entityTypeAttributesList'], 'Query result does not contain items');
8393
$this->assertGreaterThanOrEqual(3, count($queryResult['entityTypeAttributesList']['items']));
8494

85-
$this->assertNotEmpty(
86-
$this->getAttributeByCode($queryResult['entityTypeAttributesList']['items'], 'attribute_0'),
95+
$this->assertEquals(
96+
'attribute_0',
97+
$this->getAttributeByCode($queryResult['entityTypeAttributesList']['items'], 'attribute_0')['attribute_code'],
8798
self::ATTRIBUTE_NOT_FOUND_ERROR
8899
);
89-
$this->assertNotEmpty(
90-
$this->getAttributeByCode($queryResult['entityTypeAttributesList']['items'], 'attribute_1'),
100+
101+
$this->assertEquals(
102+
'attribute_1',
103+
$this->getAttributeByCode($queryResult['entityTypeAttributesList']['items'], 'attribute_1')['attribute_code'],
91104
self::ATTRIBUTE_NOT_FOUND_ERROR
92105
);
93-
$this->assertNotEmpty(
94-
$this->getAttributeByCode($queryResult['entityTypeAttributesList']['items'], 'attribute_2'),
106+
$this->assertEquals(
107+
'attribute_2',
108+
$this->getAttributeByCode($queryResult['entityTypeAttributesList']['items'], 'attribute_2')['attribute_code'],
95109
self::ATTRIBUTE_NOT_FOUND_ERROR
96110
);
111+
$this->assertEquals(
112+
[],
113+
$this->getAttributeByCode($queryResult['entityTypeAttributesList']['items'], 'attribute_5')
114+
);
97115

98116
$queryResult = $this->graphQlQuery(<<<QRY
99117
{
@@ -112,14 +130,20 @@ public function testAttributesList(): void
112130
$this->assertArrayHasKey('items', $queryResult['entityTypeAttributesList'], 'Query result does not contain items');
113131
$this->assertGreaterThanOrEqual(2, count($queryResult['entityTypeAttributesList']['items']));
114132

115-
$this->assertNotEmpty(
116-
$this->getAttributeByCode($queryResult['entityTypeAttributesList']['items'], 'attribute_3'),
133+
$this->assertEquals(
134+
'attribute_3',
135+
$this->getAttributeByCode($queryResult['entityTypeAttributesList']['items'], 'attribute_3')['attribute_code'],
117136
self::ATTRIBUTE_NOT_FOUND_ERROR
118137
);
119-
$this->assertNotEmpty(
120-
$this->getAttributeByCode($queryResult['entityTypeAttributesList']['items'], 'attribute_4'),
138+
$this->assertEquals(
139+
'attribute_4',
140+
$this->getAttributeByCode($queryResult['entityTypeAttributesList']['items'], 'attribute_4')['attribute_code'],
121141
self::ATTRIBUTE_NOT_FOUND_ERROR
122142
);
143+
$this->assertEquals(
144+
[],
145+
$this->getAttributeByCode($queryResult['entityTypeAttributesList']['items'], 'attribute_5')
146+
);
123147
}
124148

125149
/**
@@ -131,8 +155,9 @@ public function testAttributesList(): void
131155
*/
132156
private function getAttributeByCode($items, $attribute_code)
133157
{
134-
return array_filter($items, function ($item) use ($attribute_code) {
158+
$attribute = array_filter($items, function ($item) use ($attribute_code) {
135159
return $item['attribute_code'] == $attribute_code;
136160
});
161+
return $attribute[array_key_first($attribute)] ?? [];
137162
}
138163
}

0 commit comments

Comments
 (0)