-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added response body stream assertions [SLE-192]
- Loading branch information
1 parent
bc5ba10
commit af90d1f
Showing
16 changed files
with
110 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,10 +44,13 @@ public function testPasswordForgottenEmailSubmit(): void | |
// Simulate logged-in user with id 2 | ||
$this->container->get(SessionInterface::class)->set('user_id', $userId); | ||
|
||
$request = $this->createFormRequest('POST', // Request to change password | ||
$this->urlFor('password-forgotten-email-submit'), [ | ||
$request = $this->createFormRequest( | ||
'POST', // Request to change password | ||
$this->urlFor('password-forgotten-email-submit'), | ||
[ | ||
'email' => $email, | ||
]); | ||
] | ||
); | ||
|
||
$response = $this->app->handle($request); | ||
|
||
|
@@ -108,10 +111,13 @@ public function testPasswordForgottenEmailSubmitUserNotExisting(): void | |
{ | ||
// Not inserting user as it shouldn't exist | ||
|
||
$request = $this->createFormRequest('POST', // Request to change password | ||
$this->urlFor('password-forgotten-email-submit'), [ | ||
$request = $this->createFormRequest( | ||
'POST', // Request to change password | ||
$this->urlFor('password-forgotten-email-submit'), | ||
[ | ||
'email' => '[email protected]', | ||
]); | ||
] | ||
); | ||
|
||
$response = $this->app->handle($request); | ||
|
||
|
@@ -135,17 +141,25 @@ public function testPasswordForgottenEmailSubmitInvalidData(): void | |
// Simulate logged-in user with id 2 | ||
$this->container->get(SessionInterface::class)->set('user_id', $userRow['id']); | ||
|
||
$request = $this->createFormRequest('POST', // Request to change password | ||
$this->urlFor('password-forgotten-email-submit'), [ | ||
$request = $this->createFormRequest( | ||
'POST', // Request to change password | ||
$this->urlFor('password-forgotten-email-submit'), | ||
[ | ||
'email' => 'inval$d@ema$l.com', | ||
]); | ||
] | ||
); | ||
|
||
$response = $this->app->handle($request); | ||
|
||
// Assert that response has error status 422 | ||
self::assertSame(StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY, $response->getStatusCode()); | ||
|
||
// As form is directly rendered with validation errors it's not possible to test them as response is a stream | ||
// There is a visual test in insomnia for this, but I couldn't manage to keep the login session | ||
// Get response body as string from stream | ||
$stream = $response->getBody(); | ||
$stream->rewind(); | ||
$body = $stream->getContents(); | ||
|
||
// Assert that response body contains validation error | ||
self::assertStringContainsString('Invalid email', $body); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,26 +81,27 @@ public static function authenticationSecurityCases(): array | |
public static function invalidLoginCredentialsProvider(): array | ||
{ | ||
return [ | ||
[ | ||
'Invalid email' => [ | ||
[ | ||
// Invalid email | ||
'email' => 'admin@exam$ple.com', | ||
'password' => '12345678', | ||
], | ||
'validationErrorMessage' => 'Invalid email', | ||
], | ||
[ | ||
'Missing email' => [ | ||
[ | ||
// Missing email | ||
'email' => '', | ||
'password' => '12345678', | ||
], | ||
'validationErrorMessage' => 'Invalid email', | ||
], | ||
[ | ||
'Missing password' => [ | ||
[ | ||
// Missing password | ||
'email' => '[email protected]', | ||
'password' => '', | ||
], | ||
'validationErrorMessage' => 'Invalid password', | ||
], | ||
]; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.