Skip to content
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
8 changes: 8 additions & 0 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ public function setTheResponseTo(PyStringNode $response): void {
));
}

#[Given('set the response with :header header :value to:')]
public function setTheResponseWithHeaderTo(string $header, string $value, PyStringNode $response): void {
$this->mockServer->setDefaultResponse(new MockWebServerResponse(
(string) $response,
[$header => $value]
));
}

/**
* @inheritDoc
*/
Expand Down
24 changes: 24 additions & 0 deletions features/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,27 @@ Feature: Test this extension
Scenario: Wait for seconds
When wait for 1 seconds
When past 1 second since wait step

Scenario: Test response header assertion matches expected value
When set the response with "Content-Type" header "application/json" to:
"""
{"ok":true}
"""
And sending "POST" to "/"
Then the response header "Content-Type" should contain "application/json"

Scenario: Test response body is not empty
When set the response to:
"""
hello
"""
And sending "POST" to "/"
Then the response body should not be empty

Scenario: Test response body matches a regular expression
When set the response to:
"""
%PDF-1.4 binary content here
"""
And sending "POST" to "/"
Then the response body should match the regular expression "^%PDF"
19 changes: 19 additions & 0 deletions src/NextcloudApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,25 @@ public function theResponseShouldHaveStatusCode(string $code): void {
Assert::assertEquals($code, $currentCode, $this->response->getBody()->getContents());
}

#[Given('the response header :header should contain :value')]
public function theResponseHeaderShouldContain(string $header, string $value): void {
$actual = strtolower($this->response->getHeaderLine($header));
Assert::assertStringContainsString(strtolower($value), $actual, sprintf('Response header "%s" does not contain "%s"', $header, $value));
}

#[Given('the response body should not be empty')]
public function theResponseBodyShouldNotBeEmpty(): void {
$this->response->getBody()->rewind();
Assert::assertNotSame('', $this->response->getBody()->getContents(), 'Response body is empty');
}

#[Given('the response body should match the regular expression :pattern')]
public function theResponseBodyShouldMatchTheRegularExpression(string $pattern): void {
$this->response->getBody()->rewind();
$content = $this->response->getBody()->getContents();
Assert::assertMatchesRegularExpression('#' . $pattern . '#', $content, sprintf('Response body does not match pattern "%s"', $pattern));
}

/**
* @throws \InvalidArgumentException
*/
Expand Down
Loading