Skip to content

Commit 453a5e0

Browse files
committed
feat: customize header
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 017907f commit 453a5e0

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Given the response should be a JSON array with the following mandatory values
5555
Given /^set the display name of user "([^"]*)" to "([^"]*)"$/
5656
Given /^set the email of user "([^"]*)" to "([^"]*)"$/
5757
Given sending :verb to ocs :url
58+
Given /^set the custom http header "([^"]*)" with "([^"]*)" as value to next request$/
5859
Given the response should have a status code :code
5960
Given fetch field :path from previous JSON response
6061
Given the response should contain the initial state :name with the following values:

features/test.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Feature: Test this extension
77
Given sending "POST" to "/"
88
| status | 1 |
99

10+
Scenario: Test POST with success
11+
Given set the custom http header "GUSTOM_HEADER" with "custom-value" as value to next request
12+
Then sending "POST" to "/"
13+
| status | 1 |
14+
1015
Scenario: Test response of POST is numeric
1116
When set the response to:
1217
"""

src/NextcloudApiContext.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class NextcloudApiContext implements Context {
3333
protected static array $environments = [];
3434
protected static string $commandOutput = '';
3535
protected int $startWaitFor = 0;
36+
protected array $customHeaders = [];
3637

3738
/**
3839
* @var string[]
@@ -189,7 +190,8 @@ public function sendRequest(string $verb, string $url, $body = null, array $head
189190

190191
$options['headers'] = array_merge($headers, [
191192
'Accept' => 'application/json',
192-
]);
193+
], $this->customHeaders);
194+
193195
if ($this->currentUser === 'admin') {
194196
$options['auth'] = ['admin', $this->adminPassword];
195197
} elseif ($this->currentUser) {
@@ -207,6 +209,15 @@ public function sendRequest(string $verb, string $url, $body = null, array $head
207209
}
208210
}
209211

212+
#[Given('/^set the custom http header "([^"]*)" with "([^"]*)" as value to next request$/')]
213+
public function setTheCustomHttpHeaderAsValueToNextRequest(string $header, string $value):void {
214+
if (empty($value)) {
215+
unset($this->customHeaders[$header]);
216+
return;
217+
}
218+
$this->customHeaders[$header] = $this->parseText($value);
219+
}
220+
210221
protected function beforeRequest(string $fullUrl, array $options): array {
211222
$options = $this->parseFormParams($options);
212223
$fullUrl = $this->parseText($fullUrl);

0 commit comments

Comments
 (0)