Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakhar Shokel committed Apr 19, 2024
1 parent 5de4d22 commit b47dd88
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/Functional/Fixtures/config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ doctrine:

services:
logger:
class: Symfony\Component\ErrorHandler\BufferingLogger
class: Psr\Log\NullLogger
public: true
rest_registry:
alias: paysera_api.rest_request_options_registry
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Fixtures/config/legacy_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ doctrine:

services:
logger:
class: Symfony\Component\Debug\BufferingLogger
class: Psr\Log\NullLogger
public: true
rest_registry:
alias: paysera_api.rest_request_options_registry
Expand Down
102 changes: 95 additions & 7 deletions tests/Functional/FunctionalAnnotationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,33 @@ protected function setUp(): void
* @dataProvider restRequestsConfigurationProvider
* @param Response $expectedResponse
* @param Request $request
* @param Response|null $extraResponseVersion
*/
public function testRestRequestConfiguration(Response $expectedResponse, Request $request)
{
public function testRestRequestConfiguration(
Response $expectedResponse,
Request $request,
Response $extraResponseVersion = null
) {
$response = $this->handleRequest($request);
$this->assertEquals(
$expectedResponse->getContent(),
$response->getContent(),
'expected correct content'
);
$assertionMessage = 'expected correct content';

if ($extraResponseVersion === null) {
$this->assertEquals(
$expectedResponse->getContent(),
$response->getContent(),
$assertionMessage
);
} else {
$this->assertThat(
$response->getContent(),
$this->logicalOr(
$this->equalTo($expectedResponse->getContent()),
$this->equalTo($extraResponseVersion->getContent())
),
$assertionMessage
);
}

$this->assertEquals(
$expectedResponse->getStatusCode(),
$response->getStatusCode(),
Expand Down Expand Up @@ -188,6 +206,20 @@ public function restRequestsConfigurationProvider()
'/annotated/testBodyNormalizationWithValidation',
['field1' => 'not an email']
),
new Response(
json_encode([
'error' => 'invalid_parameters',
'error_description' => 'Some required parameter is missing or it\'s format is invalid',
'errors' => [
[
'code' => 'invalid_format',
'message' => 'This value is not a valid email address.',
'field' => 'my_mapped_key',
],
],
]),
400
),
],
'testBodyNormalizationWithInnerTypeValidation - should convert to snake case' => [
new Response(
Expand All @@ -209,6 +241,20 @@ public function restRequestsConfigurationProvider()
'/annotated/testBodyNormalizationWithInnerTypeValidation',
['field1' => 'blah', 'internal' => ['field1' => 'not an email']]
),
new Response(
json_encode([
'error' => 'invalid_parameters',
'error_description' => 'Some required parameter is missing or it\'s format is invalid',
'errors' => [
[
'code' => 'invalid_format',
'message' => 'Custom message',
'field' => 'internal_field1', // <-- this is converted from internalField1
],
],
]),
400
),
],
'testBodyValidationCanBeTurnedOff' => [
new Response('OK', 200),
Expand Down Expand Up @@ -344,6 +390,20 @@ public function restRequestsConfigurationProvider()
'GET',
'/annotated/testQueryResolverValidationWithInvalidData?field1=not_an_email'
),
new Response(
json_encode([
'error' => 'invalid_parameters',
'error_description' => 'Some required parameter is missing or it\'s format is invalid',
'errors' => [
[
'code' => 'invalid_format',
'message' => 'This value is not a valid email address.',
'field' => 'mapped_key',
],
],
]),
400
),
],
'testRequiredPermissions without auth' => [
new Response(
Expand Down Expand Up @@ -451,6 +511,20 @@ public function restRequestsConfigurationProvider()
'/annotated/class/testValidation',
['field1' => 'not an email', 'internal' => ['field1' => 'also not an email']]
),
new Response(
json_encode([
'error' => 'invalid_parameters',
'error_description' => 'Some required parameter is missing or it\'s format is invalid',
'errors' => [
[
'code' => 'invalid_format',
'message' => 'This value is not a valid email address.',
'field' => 'my_mapped_key',
],
],
]),
400
),
],
'testValidation with class annotation' => [
new Response(
Expand All @@ -472,6 +546,20 @@ public function restRequestsConfigurationProvider()
'/annotated/class/testValidationFromClass',
['field1' => 'not an email', 'internal' => ['field1' => 'also not an email']]
),
new Response(
json_encode([
'error' => 'invalid_parameters',
'error_description' => 'Some required parameter is missing or it\'s format is invalid',
'errors' => [
[
'code' => 'invalid_format',
'message' => 'Custom message',
'field' => 'internal.field1',
],
],
]),
400
),
],
'testResponseNormalization' => [
new Response('{"field1_custom":"hi"}'),
Expand Down

0 comments on commit b47dd88

Please sign in to comment.