Skip to content

Commit 322bd6c

Browse files
committed
- Fix CR notes
1 parent e3b1308 commit 322bd6c

File tree

9 files changed

+46
-37
lines changed

9 files changed

+46
-37
lines changed

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class OperationDefinitionObjectHandler implements ObjectHandlerInterface
2424
const ENTITY_OPERATION_STORE_CODE = 'storeCode';
2525
const ENTITY_OPERATION_SUCCESS_REGEX = 'successRegex';
2626
const ENTITY_OPERATION_RETURN_REGEX = 'returnRegex';
27+
const ENTITY_OPERATION_RETURN_INDEX = 'returnIndex';
2728
const ENTITY_OPERATION_HEADER = 'header';
2829
const ENTITY_OPERATION_CONTENT_TYPE = 'contentType';
2930
const ENTITY_OPERATION_HEADER_PARAM = 'param';
@@ -144,6 +145,7 @@ private function initialize()
144145
$auth = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_AUTH] ?? null;
145146
$successRegex = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_SUCCESS_REGEX] ?? null;
146147
$returnRegex = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_RETURN_REGEX] ?? null;
148+
$returnIndex = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_RETURN_INDEX] ?? null;
147149
$contentType = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_CONTENT_TYPE][0]['value']
148150
?? null;
149151
$headers = $this->initializeHeaders($opDefArray);
@@ -216,7 +218,8 @@ private function initialize()
216218
$contentType,
217219
$removeBackend,
218220
$successRegex,
219-
$returnRegex
221+
$returnRegex,
222+
$returnIndex
220223
);
221224
}
222225
}

src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationDefinitionObject.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ class OperationDefinitionObject
104104
*/
105105
private $returnRegex;
106106

107+
/**
108+
* Index of element to be returned from "returnRegex" matches.
109+
*
110+
* @var string
111+
*/
112+
private $returnIndex;
113+
107114
/**
108115
* Determines if operation should remove backend_name from URL.
109116
* @var boolean
@@ -125,6 +132,7 @@ class OperationDefinitionObject
125132
* @param boolean $removeBackend
126133
* @param string $successRegex
127134
* @param string $returnRegex
135+
* @param string $returnIndex
128136
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
129137
*/
130138
public function __construct(
@@ -140,7 +148,8 @@ public function __construct(
140148
$contentType,
141149
$removeBackend,
142150
$successRegex = null,
143-
$returnRegex = null
151+
$returnRegex = null,
152+
$returnIndex = null
144153
) {
145154
$this->name = $name;
146155
$this->operation = $operation;
@@ -153,6 +162,7 @@ public function __construct(
153162
$this->operationMetadata = $metaData;
154163
$this->successRegex = $successRegex;
155164
$this->returnRegex = $returnRegex;
165+
$this->returnIndex = $returnIndex;
156166
$this->removeBackend = $removeBackend;
157167
$this->apiUrl = null;
158168

@@ -284,6 +294,16 @@ public function getReturnRegex()
284294
return $this->returnRegex;
285295
}
286296

297+
/**
298+
* Getter for return regex matches index.
299+
*
300+
* @return string|null
301+
*/
302+
public function getReturnIndex()
303+
{
304+
return $this->returnIndex;
305+
}
306+
287307
/**
288308
* Function to append or add query parameters
289309
*

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,10 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers
136136
}
137137

138138
/**
139-
* Read response from server.
140-
*
141-
* @param string $successRegex
142-
* @param string $returnRegex
143-
* @return string|array
139+
* @inheritdoc
144140
* @throws TestFrameworkException
145141
*/
146-
public function read($successRegex = null, $returnRegex = null)
142+
public function read($successRegex = null, $returnRegex = null, $returnIndex = null)
147143
{
148144
$this->response = $this->transport->read();
149145
$this->setFormKey();
@@ -158,10 +154,9 @@ public function read($successRegex = null, $returnRegex = null)
158154
if (!empty($returnRegex)) {
159155
preg_match($returnRegex, $this->response, $returnMatches);
160156
if (!empty($returnMatches)) {
161-
if (count($returnMatches) > 1) {
162-
unset($returnMatches);
163-
}
164-
return reset($returnMatches);
157+
return isset($returnIndex, $returnMatches[$returnIndex])
158+
? $returnMatches[$returnIndex]
159+
: $returnMatches;
165160
}
166161
}
167162
return $this->response;

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/FrontendExecutor.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,10 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers
156156
}
157157

158158
/**
159-
* Read response from server.
160-
*
161-
* @param string $successRegex
162-
* @param string $returnRegex
163-
* @return string|array
159+
* @inheritdoc
164160
* @throws TestFrameworkException
165161
*/
166-
public function read($successRegex = null, $returnRegex = null)
162+
public function read($successRegex = null, $returnRegex = null, $returnIndex = null)
167163
{
168164
$this->response = $this->transport->read();
169165
$this->setCookies();
@@ -179,10 +175,9 @@ public function read($successRegex = null, $returnRegex = null)
179175
if (!empty($returnRegex)) {
180176
preg_match($returnRegex, $this->response, $returnMatches);
181177
if (!empty($returnMatches)) {
182-
if (count($returnMatches) > 1) {
183-
unset($returnMatches);
184-
}
185-
return reset($returnMatches);
178+
return isset($returnIndex, $returnMatches[$returnIndex])
179+
? $returnMatches[$returnIndex]
180+
: $returnMatches;
186181
}
187182
}
188183
return $this->response;

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,10 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers
135135
}
136136

137137
/**
138-
* Read response from server.
139-
*
140-
* @param string $successRegex
141-
* @param string $returnRegex
142-
* @return string
138+
* @inheritdoc
143139
* @throws TestFrameworkException
144140
*/
145-
public function read($successRegex = null, $returnRegex = null)
141+
public function read($successRegex = null, $returnRegex = null, $returnIndex = null)
146142
{
147143
$this->response = $this->transport->read();
148144
return $this->response;

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public function executeRequest($dependentEntities)
107107
$executor = null;
108108
$successRegex = null;
109109
$returnRegex = null;
110+
$returnIndex = null;
110111

111112
if ((null !== $dependentEntities) && is_array($dependentEntities)) {
112113
$entities = array_merge([$this->entityObject], $dependentEntities);
@@ -119,6 +120,7 @@ public function executeRequest($dependentEntities)
119120
$contentType = $this->operationDefinition->getContentType();
120121
$successRegex = $this->operationDefinition->getSuccessRegex();
121122
$returnRegex = $this->operationDefinition->getReturnRegex();
123+
$returnIndex = $this->operationDefinition->getReturnIndex();
122124
$method = $this->operationDefinition->getApiMethod();
123125

124126
$operationDataResolver = new OperationDataArrayResolver($dependentEntities);
@@ -161,7 +163,7 @@ public function executeRequest($dependentEntities)
161163
$headers
162164
);
163165

164-
$response = $executor->read($successRegex, $returnRegex);
166+
$response = $executor->read($successRegex, $returnRegex, $returnIndex);
165167
$executor->close();
166168

167169
return $response;

src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<xs:attribute type="operationMethodEnum" name="method"/>
3030
<xs:attribute type="xs:string" name="successRegex"/>
3131
<xs:attribute type="xs:string" name="returnRegex"/>
32+
<xs:attribute type="xs:string" name="returnIndex" use="optional"/>
3233
<xs:attribute type="xs:string" name="filename"/>
3334
</xs:complexType>
3435
</xs:element>
@@ -93,7 +94,7 @@
9394
<xs:enumeration value="anonymous" />
9495
</xs:restriction>
9596
</xs:simpleType>
96-
<xs:simpleType name="operationMethodEnum" final="restriction" >
97+
<xs:simpleType name="operationMethodEnum" final="restriction">
9798
<xs:restriction base="xs:string">
9899
<xs:enumeration value="GET" />
99100
<xs:enumeration value="PUT" />

src/Magento/FunctionalTestingFramework/Util/Protocol/CurlInterface.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ public function write($url, $body = [], $method = CurlInterface::POST, $headers
4444
*
4545
* @param string $successRegex
4646
* @param string $returnRegex
47+
* @param string|null $returnIndex
4748
* @return string|array
4849
*/
49-
public function read($successRegex = null, $returnRegex = null);
50+
public function read($successRegex = null, $returnRegex = null, $returnIndex = null);
5051

5152
/**
5253
* Close the connection to the server.

src/Magento/FunctionalTestingFramework/Util/Protocol/CurlTransport.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,10 @@ public function write($url, $body = [], $method = CurlInterface::POST, $headers
159159
}
160160

161161
/**
162-
* Read response from server.
163-
*
164-
* @param string $successRegex
165-
* @param string $returnRegex
166-
* @return string
162+
* @inheritdoc
167163
* @throws TestFrameworkException
168164
*/
169-
public function read($successRegex = null, $returnRegex = null)
165+
public function read($successRegex = null, $returnRegex = null, $returnIndex = null)
170166
{
171167
$response = curl_exec($this->getResource());
172168

0 commit comments

Comments
 (0)