Skip to content

Commit

Permalink
ENGCOM-2422: API-functional tests: assertResponseFields moved to the …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
magento-engcom-team committed Aug 16, 2018
2 parents 1a968e0 + cbd470b commit 4931970
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ abstract class GraphQlAbstract extends WebapiAbstract
* @param array $variables
* @param string $operationName
* @return array|int|string|float|bool GraphQL call results
* @throws \Exception
*/
public function graphQlQuery(
string $query,
Expand Down Expand Up @@ -98,4 +99,31 @@ private function getGraphQlClient()
}
return $this->graphQlClient;
}

/**
* Compare actual response fields with expected
*
* @param array $actualResponse
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
* OR [['response_field' => $field, 'expected_value' => $value], ...]
*/
protected function assertResponseFields($actualResponse, $assertionMap)
{
foreach ($assertionMap as $key => $assertionData) {
$expectedValue = isset($assertionData['expected_value'])
? $assertionData['expected_value']
: $assertionData;
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
self::assertNotNull(
$expectedValue,
"Value of '{$responseField}' field must not be NULL"
);
self::assertEquals(
$expectedValue,
$actualResponse[$responseField],
"Value of '{$responseField}' field in response does not match expected value: "
. var_export($expectedValue, true)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,31 +285,6 @@ private function assertBundleProductOptions($product, $actualResponse)
);
}

/**
* @param array $actualResponse
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
* OR [['response_field' => $field, 'expected_value' => $value], ...]
*/
private function assertResponseFields($actualResponse, $assertionMap)
{
foreach ($assertionMap as $key => $assertionData) {
$expectedValue = isset($assertionData['expected_value'])
? $assertionData['expected_value']
: $assertionData;
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
$this->assertNotNull(
$expectedValue,
"Value of '{$responseField}' field must not be NULL"
);
$this->assertEquals(
$expectedValue,
$actualResponse[$responseField],
"Value of '{$responseField}' field in response does not match expected value: "
. var_export($expectedValue, true)
);
}
}

/**
* @magentoApiDataFixture Magento/Bundle/_files/product_with_multiple_options_1.php
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,4 @@ private function assertSimpleProductFields($product, $actualResponse)

$this->assertResponseFields($actualResponse, $assertionMap);
}

/**
* @param array $actualResponse
* @param array $assertionMap
*/
private function assertResponseFields($actualResponse, $assertionMap)
{
foreach ($assertionMap as $key => $assertionData) {
$expectedValue = isset($assertionData['expected_value'])
? $assertionData['expected_value']
: $assertionData;
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
self::assertNotNull(
$expectedValue,
"Value of '{$responseField}' field must not be NULL"
);
self::assertEquals(
$expectedValue,
$actualResponse[$responseField],
"Value of '{$responseField}' field in response does not match expected value: "
. var_export($expectedValue, true)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -414,29 +414,4 @@ private function assertAttributes($actualResponse)
$this->assertArrayHasKey($eavAttribute, $actualResponse);
}
}

/**
* @param array $actualResponse
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
* OR [['response_field' => $field, 'expected_value' => $value], ...]
*/
private function assertResponseFields($actualResponse, $assertionMap)
{
foreach ($assertionMap as $key => $assertionData) {
$expectedValue = isset($assertionData['expected_value'])
? $assertionData['expected_value']
: $assertionData;
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
self::assertNotNull(
$expectedValue,
"Value of '{$responseField}' field must not be NULL"
);
self::assertEquals(
$expectedValue,
$actualResponse[$responseField],
"Value of '{$responseField}' field in response does not match expected value: "
. var_export($expectedValue, true)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,29 +231,4 @@ private function assertAttributeType($attributeTypes, $expectedAttributeCodes, $
);
}
}

/**
* @param array $actualResponse
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
* OR [['response_field' => $field, 'expected_value' => $value], ...]
*/
private function assertResponseFields(array $actualResponse, array $assertionMap)
{
foreach ($assertionMap as $key => $assertionData) {
$expectedValue = isset($assertionData['expected_value'])
? $assertionData['expected_value']
: $assertionData;
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
$this->assertNotNull(
$expectedValue,
"Value of '{$responseField}' field must not be NULL"
);
$this->assertEquals(
$expectedValue,
$actualResponse[$responseField],
"Value of '{$responseField}' field in response does not match expected value: "
. var_export($expectedValue, true)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1283,29 +1283,4 @@ private function assertProductItemsWithMaximalAndMinimalPriceCheck(array $filter
);
}
}

/**
* @param array $actualResponse
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
* OR [['response_field' => $field, 'expected_value' => $value], ...]
*/
private function assertResponseFields(array $actualResponse, array $assertionMap)
{
foreach ($assertionMap as $key => $assertionData) {
$expectedValue = isset($assertionData['expected_value'])
? $assertionData['expected_value']
: $assertionData;
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
$this->assertNotNull(
$expectedValue,
"Value of '{$responseField}' field must not be NULL"
);
$this->assertEquals(
$expectedValue,
$actualResponse[$responseField],
"Value of '{$responseField}' field in response does not match expected value: "
. var_export($expectedValue, true)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -957,29 +957,4 @@ private function eavAttributesToGraphQlSchemaFieldTranslator(string $eavAttribut
}
return $eavAttributeCode;
}

/**
* @param array $actualResponse
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
* OR [['response_field' => $field, 'expected_value' => $value], ...]
*/
private function assertResponseFields($actualResponse, $assertionMap)
{
foreach ($assertionMap as $key => $assertionData) {
$expectedValue = isset($assertionData['expected_value'])
? $assertionData['expected_value']
: $assertionData;
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
self::assertNotNull(
$expectedValue,
"Value of '{$responseField}' field must not be NULL"
);
self::assertEquals(
$expectedValue,
$actualResponse[$responseField],
"Value of '{$responseField}' field in response does not match expected value: "
. var_export($expectedValue, true)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,4 @@ private function assertBaseFields($product, $actualResponse)

$this->assertResponseFields($actualResponse, $assertionMap);
}

/**
* @param array $actualResponse
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
* OR [['response_field' => $field, 'expected_value' => $value], ...]
*/
private function assertResponseFields($actualResponse, $assertionMap)
{
foreach ($assertionMap as $key => $assertionData) {
$expectedValue = isset($assertionData['expected_value'])
? $assertionData['expected_value']
: $assertionData;
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
$this->assertNotNull(
$expectedValue,
"Value of '{$responseField}' field must not be NULL"
);
$this->assertEquals(
$expectedValue,
$actualResponse[$responseField],
"Value of '{$responseField}' field in response does not match expected value: "
. var_export($expectedValue, true)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -487,31 +487,6 @@ private function assertConfigurableProductOptions($actualResponse)
}
}

/**
* @param array $actualResponse
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
* OR [['response_field' => $field, 'expected_value' => $value], ...]
*/
private function assertResponseFields(array $actualResponse, array $assertionMap)
{
foreach ($assertionMap as $key => $assertionData) {
$expectedValue = isset($assertionData['expected_value'])
? $assertionData['expected_value']
: $assertionData;
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
$this->assertNotNull(
$expectedValue,
"Value of '{$responseField}' field must not be NULL"
);
$this->assertEquals(
$expectedValue,
$actualResponse[$responseField],
"Value of '{$responseField}' field in response does not match expected value: "
. var_export($expectedValue, true)
);
}
}

private function getConfigurableOptions()
{
if (!empty($this->configurableOptions)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,29 +164,4 @@ public function assertCustomerAddressesFields($customer, $actualResponse)
$this->assertResponseFields($actualResponse['customer']['addresses'][$addressKey], $assertionMap);
}
}

/**
* @param array $actualResponse
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
* OR [['response_field' => $field, 'expected_value' => $value], ...]
*/
private function assertResponseFields($actualResponse, $assertionMap)
{
foreach ($assertionMap as $key => $assertionData) {
$expectedValue = isset($assertionData['expected_value'])
? $assertionData['expected_value']
: $assertionData;
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
$this->assertNotNull(
$expectedValue,
"Value of '{$responseField}' field must not be NULL"
);
$this->assertEquals(
$expectedValue,
$actualResponse[$responseField],
"Value of '{$responseField}' field in response does not match expected value: "
. var_export($expectedValue, true)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,29 +261,4 @@ private function assertDownloadableProductSamples($product, $actualResponse)
]
);
}

/**
* @param array $actualResponse
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
* OR [['response_field' => $field, 'expected_value' => $value], ...]
*/
private function assertResponseFields($actualResponse, $assertionMap)
{
foreach ($assertionMap as $key => $assertionData) {
$expectedValue = isset($assertionData['expected_value'])
? $assertionData['expected_value']
: $assertionData;
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
$this->assertNotNull(
$expectedValue,
"Value of '{$responseField}' field must not be NULL"
);
$this->assertEquals(
$expectedValue,
$actualResponse[$responseField],
"Value of '{$responseField}' field in response does not match expected value: "
. var_export($expectedValue, true)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,4 @@ private function assertGroupedProductItems($product, $actualResponse)
);
}
}

/**
* @param array $actualResponse
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
* OR [['response_field' => $field, 'expected_value' => $value], ...]
*/
private function assertResponseFields($actualResponse, $assertionMap)
{
foreach ($assertionMap as $key => $assertionData) {
$expectedValue = isset($assertionData['expected_value'])
? $assertionData['expected_value']
: $assertionData;
$responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key;
$this->assertNotNull(
$expectedValue,
"Value of '{$responseField}' field must not be NULL"
);
$this->assertEquals(
$expectedValue,
$actualResponse[$responseField],
"Value of '{$responseField}' field in response does not match expected value: "
. var_export($expectedValue, true)
);
}
}
}
Loading

0 comments on commit 4931970

Please sign in to comment.