Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

API-functional tests: assertResponseFields moved to the abstract class #122

Merged
merged 3 commits into from
Aug 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -97,4 +98,31 @@ private function getGraphQlClient()
$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