Skip to content

Commit 0526d97

Browse files
committed
feat: add response header and body assertion steps
Add three new composable step definitions to NextcloudApiContext: - 'the response header :header should contain :value' Asserts that the given response header contains the expected substring (case-insensitive). - 'the response body should not be empty' Asserts that the response body is non-empty. - 'the response body should match the regular expression :pattern' Asserts that the response body matches the given regex pattern. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 6dc5a65 commit 0526d97

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/NextcloudApiContext.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,25 @@ public function theResponseShouldHaveStatusCode(string $code): void {
359359
Assert::assertEquals($code, $currentCode, $this->response->getBody()->getContents());
360360
}
361361

362+
#[Given('the response header :header should contain :value')]
363+
public function theResponseHeaderShouldContain(string $header, string $value): void {
364+
$actual = strtolower((string)$this->response->getHeaderLine($header));
365+
Assert::assertStringContainsString(strtolower($value), $actual, sprintf('Response header "%s" does not contain "%s"', $header, $value));
366+
}
367+
368+
#[Given('the response body should not be empty')]
369+
public function theResponseBodyShouldNotBeEmpty(): void {
370+
$this->response->getBody()->rewind();
371+
Assert::assertNotSame('', $this->response->getBody()->getContents(), 'Response body is empty');
372+
}
373+
374+
#[Given('the response body should match the regular expression :pattern')]
375+
public function theResponseBodyShouldMatchTheRegularExpression(string $pattern): void {
376+
$this->response->getBody()->rewind();
377+
$content = $this->response->getBody()->getContents();
378+
Assert::assertMatchesRegularExpression('#' . $pattern . '#', $content, sprintf('Response body does not match pattern "%s"', $pattern));
379+
}
380+
362381
/**
363382
* @throws \InvalidArgumentException
364383
*/

0 commit comments

Comments
 (0)