Skip to content

Commit 8bded8a

Browse files
committed
feature #42526 [FrameworkBundle] Add BrowserKitAssertionsTrait::assertThatForBrowser (koenreiniers)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] Add BrowserKitAssertionsTrait::assertThatForBrowser | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - I wanted to create a constraint that acts on the request and the response (an openapi schema validator constraint that needs the method and pathinfo from the request and the body from the response). But, there is currently no way to get the current client, since `BrowserKitAssertionsTrait::getClient` is private and there is no method to do an assertion on the client/browser (like `BrowserKitAssertionsTrait::assertThatForResponse` for the response). This small change will allow to do the following: ``` protected static function assertResponseMatchesOpenApiSchema(): void { self::assertThatForBrowser(new ResponseMatchesOpenApiSchema(self::getOpenApiValidator())); } ``` Commits ------- b2c32ea9fd [FrameworkBundle] Add BrowserKitAssertionsTrait::assertThatForBrowser
2 parents 294ca5c + 10eb409 commit 8bded8a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Test/BrowserKitAssertionsTrait.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@ public static function assertResponseCookieValueSame(string $name, string $expec
9696

9797
public static function assertBrowserHasCookie(string $name, string $path = '/', string $domain = null, string $message = ''): void
9898
{
99-
self::assertThat(self::getClient(), new BrowserKitConstraint\BrowserHasCookie($name, $path, $domain), $message);
99+
self::assertThatForClient(new BrowserKitConstraint\BrowserHasCookie($name, $path, $domain), $message);
100100
}
101101

102102
public static function assertBrowserNotHasCookie(string $name, string $path = '/', string $domain = null, string $message = ''): void
103103
{
104-
self::assertThat(self::getClient(), new LogicalNot(new BrowserKitConstraint\BrowserHasCookie($name, $path, $domain)), $message);
104+
self::assertThatForClient(new LogicalNot(new BrowserKitConstraint\BrowserHasCookie($name, $path, $domain)), $message);
105105
}
106106

107107
public static function assertBrowserCookieValueSame(string $name, string $expectedValue, bool $raw = false, string $path = '/', string $domain = null, string $message = ''): void
108108
{
109-
self::assertThat(self::getClient(), LogicalAnd::fromConstraints(
109+
self::assertThatForClient(LogicalAnd::fromConstraints(
110110
new BrowserKitConstraint\BrowserHasCookie($name, $path, $domain),
111111
new BrowserKitConstraint\BrowserCookieValueSame($name, $expectedValue, $raw, $path, $domain)
112112
), $message);
@@ -146,6 +146,11 @@ public static function assertThatForResponse(Constraint $constraint, string $mes
146146
}
147147
}
148148

149+
public static function assertThatForClient(Constraint $constraint, string $message = ''): void
150+
{
151+
self::assertThat(self::getClient(), $constraint, $message);
152+
}
153+
149154
private static function getClient(AbstractBrowser $newClient = null): ?AbstractBrowser
150155
{
151156
static $client;

0 commit comments

Comments
 (0)