Skip to content

Non-API operations fixes #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 28, 2019
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 @@ -24,6 +24,7 @@ class OperationDefinitionObjectHandler implements ObjectHandlerInterface
const ENTITY_OPERATION_STORE_CODE = 'storeCode';
const ENTITY_OPERATION_SUCCESS_REGEX = 'successRegex';
const ENTITY_OPERATION_RETURN_REGEX = 'returnRegex';
const ENTITY_OPERATION_RETURN_INDEX = 'returnIndex';
const ENTITY_OPERATION_HEADER = 'header';
const ENTITY_OPERATION_CONTENT_TYPE = 'contentType';
const ENTITY_OPERATION_HEADER_PARAM = 'param';
Expand Down Expand Up @@ -144,6 +145,7 @@ private function initialize()
$auth = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_AUTH] ?? null;
$successRegex = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_SUCCESS_REGEX] ?? null;
$returnRegex = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_RETURN_REGEX] ?? null;
$returnIndex = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_RETURN_INDEX] ?? 0;
$contentType = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_CONTENT_TYPE][0]['value']
?? null;
$headers = $this->initializeHeaders($opDefArray);
Expand Down Expand Up @@ -216,7 +218,8 @@ private function initialize()
$contentType,
$removeBackend,
$successRegex,
$returnRegex
$returnRegex,
$returnIndex
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ class OperationDefinitionObject
*/
private $returnRegex;

/**
* Index of element to be returned from "returnRegex" matches.
*
* @var string
*/
private $returnIndex;

/**
* Determines if operation should remove backend_name from URL.
* @var boolean
Expand All @@ -125,6 +132,7 @@ class OperationDefinitionObject
* @param boolean $removeBackend
* @param string $successRegex
* @param string $returnRegex
* @param string $returnIndex
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -140,7 +148,8 @@ public function __construct(
$contentType,
$removeBackend,
$successRegex = null,
$returnRegex = null
$returnRegex = null,
$returnIndex = null
) {
$this->name = $name;
$this->operation = $operation;
Expand All @@ -153,6 +162,7 @@ public function __construct(
$this->operationMetadata = $metaData;
$this->successRegex = $successRegex;
$this->returnRegex = $returnRegex;
$this->returnIndex = $returnIndex;
$this->removeBackend = $removeBackend;
$this->apiUrl = null;

Expand Down Expand Up @@ -284,6 +294,16 @@ public function getReturnRegex()
return $this->returnRegex;
}

/**
* Getter for return regex matches index.
*
* @return string|null
*/
public function getReturnIndex()
{
return $this->returnIndex;
}

/**
* Function to append or add query parameters
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers
/**
* Read response from server.
*
* @param string $successRegex
* @param string $returnRegex
* @param string $successRegex
* @param string $returnRegex
* @param string|null $returnIndex
* @return string|array
* @throws TestFrameworkException
*/
public function read($successRegex = null, $returnRegex = null)
public function read($successRegex = null, $returnRegex = null, $returnIndex = null)
{
$this->response = $this->transport->read();
$this->setFormKey();
Expand All @@ -158,7 +159,7 @@ public function read($successRegex = null, $returnRegex = null)
if (!empty($returnRegex)) {
preg_match($returnRegex, $this->response, $returnMatches);
if (!empty($returnMatches)) {
return $returnMatches;
return $returnMatches[$returnIndex] ?? $returnMatches[0];
}
}
return $this->response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,13 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers
/**
* Read response from server.
*
* @param string $successRegex
* @param string $returnRegex
* @param string $successRegex
* @param string $returnRegex
* @param string|null $returnIndex
* @return string|array
* @throws TestFrameworkException
*/
public function read($successRegex = null, $returnRegex = null)
public function read($successRegex = null, $returnRegex = null, $returnIndex = null)
{
$this->response = $this->transport->read();
$this->setCookies();
Expand All @@ -179,7 +180,7 @@ public function read($successRegex = null, $returnRegex = null)
if (!empty($returnRegex)) {
preg_match($returnRegex, $this->response, $returnMatches);
if (!empty($returnMatches)) {
return $returnMatches;
return $returnMatches[$returnIndex] ?? $returnMatches[0];
}
}
return $this->response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers
/**
* Read response from server.
*
* @param string $successRegex
* @param string $returnRegex
* @param string $successRegex
* @param string $returnRegex
* @param string|null $returnIndex
* @return string
* @throws TestFrameworkException
*/
public function read($successRegex = null, $returnRegex = null)
public function read($successRegex = null, $returnRegex = null, $returnIndex = null)
{
$this->response = $this->transport->read();
return $this->response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function executeRequest($dependentEntities)
$executor = null;
$successRegex = null;
$returnRegex = null;
$returnIndex = null;

if ((null !== $dependentEntities) && is_array($dependentEntities)) {
$entities = array_merge([$this->entityObject], $dependentEntities);
Expand All @@ -119,6 +120,8 @@ public function executeRequest($dependentEntities)
$contentType = $this->operationDefinition->getContentType();
$successRegex = $this->operationDefinition->getSuccessRegex();
$returnRegex = $this->operationDefinition->getReturnRegex();
$returnIndex = $this->operationDefinition->getReturnIndex();
$method = $this->operationDefinition->getApiMethod();

$operationDataResolver = new OperationDataArrayResolver($dependentEntities);
$this->requestData = $operationDataResolver->resolveOperationDataArray(
Expand Down Expand Up @@ -156,11 +159,11 @@ public function executeRequest($dependentEntities)
$executor->write(
$apiUrl,
$this->requestData,
self::$curlMethodMapping[$this->operation],
$method ?? self::$curlMethodMapping[$this->operation],
$headers
);

$response = $executor->read($successRegex, $returnRegex);
$response = $executor->read($successRegex, $returnRegex, $returnIndex);
$executor->close();

return $response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
<xs:attribute type="xs:string" name="url"/>
<xs:attribute type="authEnum" name="auth"/>
<xs:attribute type="xs:boolean" name="removeBackend" use="optional" default="true"/>
<xs:attribute type="xs:string" name="method"/>
<xs:attribute type="operationMethodEnum" name="method"/>
<xs:attribute type="xs:string" name="successRegex"/>
<xs:attribute type="xs:string" name="returnRegex"/>
<xs:attribute type="xs:string" name="returnIndex" use="optional"/>
<xs:attribute type="xs:string" name="filename"/>
</xs:complexType>
</xs:element>
Expand Down Expand Up @@ -93,4 +94,12 @@
<xs:enumeration value="anonymous" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="operationMethodEnum" final="restriction">
<xs:restriction base="xs:string">
<xs:enumeration value="GET" />
<xs:enumeration value="PUT" />
<xs:enumeration value="POST" />
<xs:enumeration value="DELETE" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ public function write($url, $body = [], $method = CurlInterface::POST, $headers
/**
* Read response from server.
*
* @param string $successRegex
* @param string $returnRegex
* @param string $successRegex
* @param string $returnRegex
* @param string|null $returnIndex
* @return string|array
*/
public function read($successRegex = null, $returnRegex = null);
public function read($successRegex = null, $returnRegex = null, $returnIndex = null);

/**
* Close the connection to the server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,13 @@ public function write($url, $body = [], $method = CurlInterface::POST, $headers
/**
* Read response from server.
*
* @param string $successRegex
* @param string $returnRegex
* @param string $successRegex
* @param string $returnRegex
* @param string|null $returnIndex
* @return string
* @throws TestFrameworkException
*/
public function read($successRegex = null, $returnRegex = null)
public function read($successRegex = null, $returnRegex = null, $returnIndex = null)
{
$response = curl_exec($this->getResource());

Expand Down