Skip to content

Commit 4931970

Browse files
ENGCOM-2422: API-functional tests: assertResponseFields moved to the abstract class #122
- Merge Pull Request magento/graphql-ce#122 from magento/graphql-ce:assert-response-field-refactor - Merged commits: 1. 33a06d3 2. 16c17ba 3. cbd470b
2 parents 1a968e0 + cbd470b commit 4931970

File tree

13 files changed

+28
-299
lines changed

13 files changed

+28
-299
lines changed

dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQlAbstract.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ abstract class GraphQlAbstract extends WebapiAbstract
3434
* @param array $variables
3535
* @param string $operationName
3636
* @return array|int|string|float|bool GraphQL call results
37+
* @throws \Exception
3738
*/
3839
public function graphQlQuery(
3940
string $query,
@@ -98,4 +99,31 @@ private function getGraphQlClient()
9899
}
99100
return $this->graphQlClient;
100101
}
102+
103+
/**
104+
* Compare actual response fields with expected
105+
*
106+
* @param array $actualResponse
107+
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
108+
* OR [['response_field' => $field, 'expected_value' => $value], ...]
109+
*/
110+
protected function assertResponseFields($actualResponse, $assertionMap)
111+
{
112+
foreach ($assertionMap as $key => $assertionData) {
113+
$expectedValue = isset($assertionData['expected_value'])
114+
? $assertionData['expected_value']
115+
: $assertionData;
116+
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
117+
self::assertNotNull(
118+
$expectedValue,
119+
"Value of '{$responseField}' field must not be NULL"
120+
);
121+
self::assertEquals(
122+
$expectedValue,
123+
$actualResponse[$responseField],
124+
"Value of '{$responseField}' field in response does not match expected value: "
125+
. var_export($expectedValue, true)
126+
);
127+
}
128+
}
101129
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Bundle/BundleProductViewTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -285,31 +285,6 @@ private function assertBundleProductOptions($product, $actualResponse)
285285
);
286286
}
287287

288-
/**
289-
* @param array $actualResponse
290-
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
291-
* OR [['response_field' => $field, 'expected_value' => $value], ...]
292-
*/
293-
private function assertResponseFields($actualResponse, $assertionMap)
294-
{
295-
foreach ($assertionMap as $key => $assertionData) {
296-
$expectedValue = isset($assertionData['expected_value'])
297-
? $assertionData['expected_value']
298-
: $assertionData;
299-
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
300-
$this->assertNotNull(
301-
$expectedValue,
302-
"Value of '{$responseField}' field must not be NULL"
303-
);
304-
$this->assertEquals(
305-
$expectedValue,
306-
$actualResponse[$responseField],
307-
"Value of '{$responseField}' field in response does not match expected value: "
308-
. var_export($expectedValue, true)
309-
);
310-
}
311-
}
312-
313288
/**
314289
* @magentoApiDataFixture Magento/Bundle/_files/product_with_multiple_options_1.php
315290
*/

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsVariantsTest.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,4 @@ private function assertSimpleProductFields($product, $actualResponse)
7474

7575
$this->assertResponseFields($actualResponse, $assertionMap);
7676
}
77-
78-
/**
79-
* @param array $actualResponse
80-
* @param array $assertionMap
81-
*/
82-
private function assertResponseFields($actualResponse, $assertionMap)
83-
{
84-
foreach ($assertionMap as $key => $assertionData) {
85-
$expectedValue = isset($assertionData['expected_value'])
86-
? $assertionData['expected_value']
87-
: $assertionData;
88-
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
89-
self::assertNotNull(
90-
$expectedValue,
91-
"Value of '{$responseField}' field must not be NULL"
92-
);
93-
self::assertEquals(
94-
$expectedValue,
95-
$actualResponse[$responseField],
96-
"Value of '{$responseField}' field in response does not match expected value: "
97-
. var_export($expectedValue, true)
98-
);
99-
}
100-
}
10177
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -414,29 +414,4 @@ private function assertAttributes($actualResponse)
414414
$this->assertArrayHasKey($eavAttribute, $actualResponse);
415415
}
416416
}
417-
418-
/**
419-
* @param array $actualResponse
420-
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
421-
* OR [['response_field' => $field, 'expected_value' => $value], ...]
422-
*/
423-
private function assertResponseFields($actualResponse, $assertionMap)
424-
{
425-
foreach ($assertionMap as $key => $assertionData) {
426-
$expectedValue = isset($assertionData['expected_value'])
427-
? $assertionData['expected_value']
428-
: $assertionData;
429-
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
430-
self::assertNotNull(
431-
$expectedValue,
432-
"Value of '{$responseField}' field must not be NULL"
433-
);
434-
self::assertEquals(
435-
$expectedValue,
436-
$actualResponse[$responseField],
437-
"Value of '{$responseField}' field in response does not match expected value: "
438-
. var_export($expectedValue, true)
439-
);
440-
}
441-
}
442417
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductAttributeTypeTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -231,29 +231,4 @@ private function assertAttributeType($attributeTypes, $expectedAttributeCodes, $
231231
);
232232
}
233233
}
234-
235-
/**
236-
* @param array $actualResponse
237-
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
238-
* OR [['response_field' => $field, 'expected_value' => $value], ...]
239-
*/
240-
private function assertResponseFields(array $actualResponse, array $assertionMap)
241-
{
242-
foreach ($assertionMap as $key => $assertionData) {
243-
$expectedValue = isset($assertionData['expected_value'])
244-
? $assertionData['expected_value']
245-
: $assertionData;
246-
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
247-
$this->assertNotNull(
248-
$expectedValue,
249-
"Value of '{$responseField}' field must not be NULL"
250-
);
251-
$this->assertEquals(
252-
$expectedValue,
253-
$actualResponse[$responseField],
254-
"Value of '{$responseField}' field in response does not match expected value: "
255-
. var_export($expectedValue, true)
256-
);
257-
}
258-
}
259234
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,29 +1283,4 @@ private function assertProductItemsWithMaximalAndMinimalPriceCheck(array $filter
12831283
);
12841284
}
12851285
}
1286-
1287-
/**
1288-
* @param array $actualResponse
1289-
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
1290-
* OR [['response_field' => $field, 'expected_value' => $value], ...]
1291-
*/
1292-
private function assertResponseFields(array $actualResponse, array $assertionMap)
1293-
{
1294-
foreach ($assertionMap as $key => $assertionData) {
1295-
$expectedValue = isset($assertionData['expected_value'])
1296-
? $assertionData['expected_value']
1297-
: $assertionData;
1298-
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
1299-
$this->assertNotNull(
1300-
$expectedValue,
1301-
"Value of '{$responseField}' field must not be NULL"
1302-
);
1303-
$this->assertEquals(
1304-
$expectedValue,
1305-
$actualResponse[$responseField],
1306-
"Value of '{$responseField}' field in response does not match expected value: "
1307-
. var_export($expectedValue, true)
1308-
);
1309-
}
1310-
}
13111286
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductViewTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -957,29 +957,4 @@ private function eavAttributesToGraphQlSchemaFieldTranslator(string $eavAttribut
957957
}
958958
return $eavAttributeCode;
959959
}
960-
961-
/**
962-
* @param array $actualResponse
963-
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
964-
* OR [['response_field' => $field, 'expected_value' => $value], ...]
965-
*/
966-
private function assertResponseFields($actualResponse, $assertionMap)
967-
{
968-
foreach ($assertionMap as $key => $assertionData) {
969-
$expectedValue = isset($assertionData['expected_value'])
970-
? $assertionData['expected_value']
971-
: $assertionData;
972-
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
973-
self::assertNotNull(
974-
$expectedValue,
975-
"Value of '{$responseField}' field must not be NULL"
976-
);
977-
self::assertEquals(
978-
$expectedValue,
979-
$actualResponse[$responseField],
980-
"Value of '{$responseField}' field in response does not match expected value: "
981-
. var_export($expectedValue, true)
982-
);
983-
}
984-
}
985960
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/VirtualProductViewTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -134,29 +134,4 @@ private function assertBaseFields($product, $actualResponse)
134134

135135
$this->assertResponseFields($actualResponse, $assertionMap);
136136
}
137-
138-
/**
139-
* @param array $actualResponse
140-
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
141-
* OR [['response_field' => $field, 'expected_value' => $value], ...]
142-
*/
143-
private function assertResponseFields($actualResponse, $assertionMap)
144-
{
145-
foreach ($assertionMap as $key => $assertionData) {
146-
$expectedValue = isset($assertionData['expected_value'])
147-
? $assertionData['expected_value']
148-
: $assertionData;
149-
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
150-
$this->assertNotNull(
151-
$expectedValue,
152-
"Value of '{$responseField}' field must not be NULL"
153-
);
154-
$this->assertEquals(
155-
$expectedValue,
156-
$actualResponse[$responseField],
157-
"Value of '{$responseField}' field in response does not match expected value: "
158-
. var_export($expectedValue, true)
159-
);
160-
}
161-
}
162137
}

dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductViewTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -487,31 +487,6 @@ private function assertConfigurableProductOptions($actualResponse)
487487
}
488488
}
489489

490-
/**
491-
* @param array $actualResponse
492-
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
493-
* OR [['response_field' => $field, 'expected_value' => $value], ...]
494-
*/
495-
private function assertResponseFields(array $actualResponse, array $assertionMap)
496-
{
497-
foreach ($assertionMap as $key => $assertionData) {
498-
$expectedValue = isset($assertionData['expected_value'])
499-
? $assertionData['expected_value']
500-
: $assertionData;
501-
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
502-
$this->assertNotNull(
503-
$expectedValue,
504-
"Value of '{$responseField}' field must not be NULL"
505-
);
506-
$this->assertEquals(
507-
$expectedValue,
508-
$actualResponse[$responseField],
509-
"Value of '{$responseField}' field in response does not match expected value: "
510-
. var_export($expectedValue, true)
511-
);
512-
}
513-
}
514-
515490
private function getConfigurableOptions()
516491
{
517492
if (!empty($this->configurableOptions)) {

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CustomerAuthenticationTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -164,29 +164,4 @@ public function assertCustomerAddressesFields($customer, $actualResponse)
164164
$this->assertResponseFields($actualResponse['customer']['addresses'][$addressKey], $assertionMap);
165165
}
166166
}
167-
168-
/**
169-
* @param array $actualResponse
170-
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
171-
* OR [['response_field' => $field, 'expected_value' => $value], ...]
172-
*/
173-
private function assertResponseFields($actualResponse, $assertionMap)
174-
{
175-
foreach ($assertionMap as $key => $assertionData) {
176-
$expectedValue = isset($assertionData['expected_value'])
177-
? $assertionData['expected_value']
178-
: $assertionData;
179-
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
180-
$this->assertNotNull(
181-
$expectedValue,
182-
"Value of '{$responseField}' field must not be NULL"
183-
);
184-
$this->assertEquals(
185-
$expectedValue,
186-
$actualResponse[$responseField],
187-
"Value of '{$responseField}' field in response does not match expected value: "
188-
. var_export($expectedValue, true)
189-
);
190-
}
191-
}
192167
}

dev/tests/api-functional/testsuite/Magento/GraphQl/DownloadableProduct/DownloadableProductViewTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -261,29 +261,4 @@ private function assertDownloadableProductSamples($product, $actualResponse)
261261
]
262262
);
263263
}
264-
265-
/**
266-
* @param array $actualResponse
267-
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
268-
* OR [['response_field' => $field, 'expected_value' => $value], ...]
269-
*/
270-
private function assertResponseFields($actualResponse, $assertionMap)
271-
{
272-
foreach ($assertionMap as $key => $assertionData) {
273-
$expectedValue = isset($assertionData['expected_value'])
274-
? $assertionData['expected_value']
275-
: $assertionData;
276-
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
277-
$this->assertNotNull(
278-
$expectedValue,
279-
"Value of '{$responseField}' field must not be NULL"
280-
);
281-
$this->assertEquals(
282-
$expectedValue,
283-
$actualResponse[$responseField],
284-
"Value of '{$responseField}' field in response does not match expected value: "
285-
. var_export($expectedValue, true)
286-
);
287-
}
288-
}
289264
}

dev/tests/api-functional/testsuite/Magento/GraphQl/GroupedProduct/GroupedProductViewTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,4 @@ private function assertGroupedProductItems($product, $actualResponse)
9292
);
9393
}
9494
}
95-
96-
/**
97-
* @param array $actualResponse
98-
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
99-
* OR [['response_field' => $field, 'expected_value' => $value], ...]
100-
*/
101-
private function assertResponseFields($actualResponse, $assertionMap)
102-
{
103-
foreach ($assertionMap as $key => $assertionData) {
104-
$expectedValue = isset($assertionData['expected_value'])
105-
? $assertionData['expected_value']
106-
: $assertionData;
107-
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
108-
$this->assertNotNull(
109-
$expectedValue,
110-
"Value of '{$responseField}' field must not be NULL"
111-
);
112-
$this->assertEquals(
113-
$expectedValue,
114-
$actualResponse[$responseField],
115-
"Value of '{$responseField}' field in response does not match expected value: "
116-
. var_export($expectedValue, true)
117-
);
118-
}
119-
}
12095
}

0 commit comments

Comments
 (0)