Skip to content

Commit 0f7c257

Browse files
Add body assertions
1 parent b76e3ae commit 0f7c257

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Functions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ function bodyMatchesJson($constraints): Constraint
106106
);
107107
}
108108

109+
function bodyMatchesForm(array $constraints): Constraint
110+
{
111+
return Psr7Assertions::bodyMatchesForm($constraints);
112+
}
113+
109114
function isAbsoluteUri(): Constraint
110115
{
111116
return new IsAbsoluteUriConstraint();

src/Psr7Assertions.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public static function assertMessageBodyMatchesJson(MessageInterface $message, a
4747
Assert::assertThat($message, static::bodyMatchesJson($jsonConstraints));
4848
}
4949

50+
public static function assertMessageBodyMatchesForm(MessageInterface $message, array $formConstraints): void
51+
{
52+
Assert::assertThat($message, static::bodyMatchesForm($formConstraints));
53+
}
54+
5055
public static function assertResponseHasStatus(ResponseInterface $response, int $status): void
5156
{
5257
Assert::assertThat($response, static::hasStatus($status));
@@ -221,6 +226,14 @@ public static function bodyMatchesJson(array $constraints): Constraint
221226
);
222227
}
223228

229+
public static function bodyMatchesForm(array $constraints): Constraint
230+
{
231+
return Assert::logicalAnd(
232+
self::hasHeader('content-type', Assert::matchesRegularExpression(',^application/x-www-form-urlencoded(;.+)?$,')),
233+
self::bodyMatches(new HasQueryParametersConstraint($constraints))
234+
);
235+
}
236+
224237
/**
225238
* @return Constraint
226239
*/

0 commit comments

Comments
 (0)