-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zakhar Shokel
committed
Apr 24, 2024
1 parent
8d73ff6
commit 9ff07dc
Showing
14 changed files
with
514 additions
and
66 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
31 changes: 31 additions & 0 deletions
31
...al/Fixtures/FixtureTestBundle/Controller/AttributedClassRequiredPermissionsController.php
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller; | ||
|
||
use Paysera\Bundle\ApiBundle\Attribute\RequiredPermissions; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
#[RequiredPermissions(permissions: ['ROLE_USER'])] | ||
class AttributedClassRequiredPermissionsController | ||
{ | ||
/** | ||
* @Route(path="/attributed/class/testRequiredPermissions", methods={"GET"}) | ||
*/ | ||
#[RequiredPermissions(permissions: ['ROLE_USER'])] | ||
#[RequiredPermissions(permissions: ['ROLE_ADMIN'])] | ||
#[RequiredPermissions(permissions: ['ROLE_USER'])] | ||
public function test(): Response | ||
{ | ||
return new Response('OK'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/class/simpleAction", methods={"GET"}) | ||
*/ | ||
public function simpleAction(): Response | ||
{ | ||
return new Response('OK'); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../Functional/Fixtures/FixtureTestBundle/Controller/AttributedClassValidationController.php
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller; | ||
|
||
use Paysera\Bundle\ApiBundle\Attribute\Body; | ||
use Paysera\Bundle\ApiBundle\Attribute\Validation; | ||
use Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Entity\MyObject; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
#[Validation(groups: ['internal_field1_email'], violationPathMap: ['internalField1' => 'internal.field1'])] | ||
class AttributedClassValidationController | ||
{ | ||
/** | ||
* @Route(path="/attributed/class/testValidation", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'resource')] | ||
#[Validation(groups: ['field1_email'], violationPathMap: ['field1' => 'my_mapped_key'])] | ||
public function testValidation(MyObject $resource): Response | ||
{ | ||
// should fail validation | ||
return new Response('FAIL'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/class/testValidationFromClass", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'resource')] | ||
public function testValidationFromClass(MyObject $resource): Response | ||
{ | ||
// should fail validation | ||
return new Response('FAIL'); | ||
} | ||
} |
264 changes: 264 additions & 0 deletions
264
tests/Functional/Fixtures/FixtureTestBundle/Controller/AttributedController.php
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 |
---|---|---|
@@ -0,0 +1,264 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Controller; | ||
|
||
use Paysera\Bundle\ApiBundle\Attribute\Body; | ||
use Paysera\Bundle\ApiBundle\Attribute\BodyContentType; | ||
use Paysera\Bundle\ApiBundle\Attribute\PathAttribute; | ||
use Paysera\Bundle\ApiBundle\Attribute\Query; | ||
use Paysera\Bundle\ApiBundle\Attribute\RequiredPermissions; | ||
use Paysera\Bundle\ApiBundle\Attribute\ResponseNormalization; | ||
use Paysera\Bundle\ApiBundle\Attribute\Validation; | ||
use Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Entity\MyObject; | ||
use Paysera\Pagination\Entity\Pager; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class AttributedController | ||
{ | ||
/** | ||
* @Route(path="/attributed/testBodyNormalizationWithExtractedKeyValue", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'keyValueInBody', denormalizationType: 'extract:key')] | ||
public function testBodyNormalizationWithExtractedKeyValue(string $keyValueInBody = 'default'): Response | ||
{ | ||
return new Response($keyValueInBody); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testBodyNormalizationWithDenormalizationGroup", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'keyValueInBody', denormalizationType: 'extract:key', denormalizationGroup: 'custom')] | ||
public function testBodyNormalizationWithDenormalizationGroup(string $keyValueInBody = 'default'): Response | ||
{ | ||
return new Response($keyValueInBody); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testBodyNormalizationWithRequiredBody", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'body', denormalizationType: 'extract:key')] | ||
public function testBodyNormalizationWithRequiredBody(string $body): Response | ||
{ | ||
// should fail as we don't pass any body | ||
return new Response('FAIL'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testBodyAndResponseNormalization", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'resource')] | ||
public function testBodyAndResponseNormalization(MyObject $resource): MyObject | ||
{ | ||
return $resource; | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testBodyNormalizationWithCustomContentType", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'body', denormalizationType: 'prefixed')] | ||
#[BodyContentType(supportedContentTypes: ['text/plain'])] | ||
public function testBodyNormalizationWithCustomContentType(string $body): Response | ||
{ | ||
return new Response($body); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testBodyNormalizationWithCustomContentTypeAndJsonDecode", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'keyValueInBody', denormalizationType: 'extract:key')] | ||
#[BodyContentType(supportedContentTypes: ['text/plain'], jsonEncodedBody: true)] | ||
public function testBodyNormalizationWithCustomContentTypeAndJsonDecode(string $keyValueInBody): Response | ||
{ | ||
return new Response($keyValueInBody); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testBodyNormalizationWithSemiContentTypeRestriction", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'body', denormalizationType: 'prefixed')] | ||
#[BodyContentType(supportedContentTypes: ['image/jpeg', 'text/*'])] | ||
public function testBodyNormalizationWithSemiContentTypeRestriction(string $body): Response | ||
{ | ||
return new Response($body); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testBodyNormalizationWithValidation", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'resource')] | ||
#[Validation(groups: ['field1_email'], violationPathMap: ['field1' => 'my_mapped_key'])] | ||
public function testBodyNormalizationWithValidation(MyObject $resource): Response | ||
{ | ||
// should fail validation | ||
return new Response('FAIL'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testBodyNormalizationWithInnerTypeValidation", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'resource')] | ||
#[Validation(groups: ['internal_field1_email'])] | ||
public function testBodyNormalizationWithInnerTypeValidation(MyObject $resource): Response | ||
{ | ||
// should fail validation | ||
return new Response('FAIL'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testBodyValidationCanBeTurnedOff", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'resource')] | ||
#[Validation(enabled: false)] | ||
public function testBodyValidationCanBeTurnedOff(MyObject $resource): Response | ||
{ | ||
return new Response('OK'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testBodyValidationCanBeTurnedOffWithEmptyGroups", methods={"POST"}) | ||
*/ | ||
#[Body(parameterName: 'resource')] | ||
#[Validation(groups: [])] | ||
public function testBodyValidationCanBeTurnedOffWithEmptyGroups(MyObject $resource): Response | ||
{ | ||
return new Response('OK'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testPathAttribute/{id}", methods={"GET"}) | ||
* @Route(path="/attributed/testPathAttribute", methods={"GET"}) | ||
*/ | ||
#[PathAttribute(parameterName: 'parameter', pathPartName: 'id', resolverType: 'prefixed')] | ||
public function testPathAttribute(string $parameter = 'default'): Response | ||
{ | ||
return new Response($parameter); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testPathAttributeWithFindingObject/{id}", methods={"GET"}) | ||
*/ | ||
#[PathAttribute(parameterName: 'myObject', pathPartName: 'id')] | ||
public function testPathAttributeWithFindingObject(MyObject $myObject): Response | ||
{ | ||
return new Response($myObject->getField1()); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testPathAttributeWithFailedResolution/{id}", methods={"GET"}) | ||
*/ | ||
#[PathAttribute(parameterName: 'myObject', pathPartName: 'id', resolverType: 'always_null')] | ||
public function testPathAttributeWithFailedResolution(MyObject $myObject): Response | ||
{ | ||
// should fail before calling controller | ||
return new Response('FAIL'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testQueryResolver", methods={"GET"}) | ||
*/ | ||
#[Query(parameterName: 'parameter', denormalizationType: 'extract:parameter')] | ||
public function testQueryResolver(string $parameter): Response | ||
{ | ||
return new Response($parameter); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testQueryResolverWithDenormalizationGroup", methods={"GET"}) | ||
*/ | ||
#[Query(parameterName: 'parameter', denormalizationType: 'extract:parameter', denormalizationGroup: 'custom')] | ||
public function testQueryResolverWithDenormalizationGroup(string $parameter): Response | ||
{ | ||
return new Response($parameter); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testQueryResolverPagerLimitIs42", methods={"GET"}) | ||
*/ | ||
#[Query(parameterName: 'pager')] | ||
public function testQueryResolverPagerLimitIs42(Pager $pager): Response | ||
{ | ||
return new Response($pager->getLimit() === 42 ? 'OK' : 'FAIL'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testQueryResolverHasDefaultValidation", methods={"GET"}) | ||
*/ | ||
#[Query(parameterName: 'myObject')] | ||
public function testQueryResolverHasDefaultValidation(MyObject $myObject): Response | ||
{ | ||
// should fail validation | ||
return new Response('FAIL'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testQueryResolverCanTurnOffValidation", methods={"GET"}) | ||
*/ | ||
#[Query(parameterName: 'myObject', validation: new Validation(enabled: false))] | ||
public function testQueryResolverCanTurnOffValidation(MyObject $myObject): Response | ||
{ | ||
return new Response('OK'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testQueryResolverCanTurnOffValidationWithEmptyGroups", methods={"GET"}) | ||
*/ | ||
#[Query(parameterName: 'myObject', validation: new Validation(groups: []))] | ||
public function testQueryResolverCanTurnOffValidationWithEmptyGroups(MyObject $myObject): Response | ||
{ | ||
return new Response('OK'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testQueryResolverValidationWithInvalidData", methods={"GET"}) | ||
*/ | ||
#[Query(parameterName: 'myObject', validation: new Validation(groups: ['field1_email'], violationPathMap: ['field1' => 'mapped_key']))] | ||
public function testQueryResolverValidationWithInvalidData(MyObject $myObject): Response | ||
{ | ||
// should fail validation | ||
return new Response('FAIL'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testRequiredPermissions", methods={"GET"}) | ||
*/ | ||
#[RequiredPermissions(permissions: ['ROLE_USER', 'ROLE_ADMIN'])] | ||
public function testRequiredPermissions(): Response | ||
{ | ||
return new Response('OK'); | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testResponseNormalization", methods={"GET"}) | ||
*/ | ||
#[ResponseNormalization(normalizationType: 'my_object_custom')] | ||
public function testResponseNormalization(): MyObject | ||
{ | ||
return (new MyObject()) | ||
->setField1('hi') | ||
; | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testResponseNormalizationWithNormalizationGroup", methods={"GET"}) | ||
*/ | ||
#[ResponseNormalization(normalizationGroup: 'custom')] | ||
public function testResponseNormalizationWithNormalizationGroup(): MyObject | ||
{ | ||
return (new MyObject()) | ||
->setField1('hi') | ||
; | ||
} | ||
|
||
/** | ||
* @Route(path="/attributed/testResponseNormalizationWithGuessedNormalizer", methods={"GET"}) | ||
*/ | ||
#[ResponseNormalization] | ||
public function testResponseNormalizationWithGuessedNormalizer(): MyObject | ||
{ | ||
return (new MyObject()) | ||
->setField1('hi') | ||
; | ||
} | ||
} |
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.