Skip to content

Commit

Permalink
fix 7.4?
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Aug 3, 2021
1 parent db8f3bf commit 7e23650
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 123 deletions.
Expand Up @@ -24,7 +24,7 @@
final class PayloadArgumentResolver implements ArgumentValueResolverInterface
{
use OperationRequestInitiatorTrait;
private SerializerContextBuilderInterface $serializationContextBuilder;
private $serializationContextBuilder;

public function __construct(
ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
Expand Down
Expand Up @@ -196,6 +196,9 @@ public function testIntegration(Request $request, callable $controller, array $e
self::assertSame($expectedArguments, $arguments);
}

/**
* @requires php 8.0
*/
public function provideIntegrationCases(): iterable
{
$resource = new ResourceImplementation();
Expand Down
87 changes: 27 additions & 60 deletions tests/Bridge/Symfony/Routing/ApiLoaderTest.php
Expand Up @@ -53,45 +53,21 @@ public function testApiLoader()
{
$path = '/dummies/{id}.{_format}';

$resourceCollection = new ResourceMetadataCollection(Dummy::class, [new ApiResource(
shortName: 'dummy',
operations: [
$resourceCollection = new ResourceMetadataCollection(Dummy::class, [
(new ApiResource())->withShortName('dummy')->withOperations([
// Default operations based on OperationResourceMetadataFactory
'api_dummies_get_item' => new Get(
uriTemplate: $path,
defaults: ['my_default' => 'default_value', '_controller' => 'should_not_be_overriden'],
requirements: ['id' => '\d+'],
controller: 'api_platform.action.get_item',
),
'api_dummies_put_item' => new Put(uriTemplate: $path),
'api_dummies_delete_item' => new Delete(uriTemplate: $path),
'api_dummies_get_item' => (new Get())->withIdentifiers(['id'])->withUriTemplate($path)->withDefaults(['my_default' => 'default_value', '_controller' => 'should_not_be_overriden'])->withRequirements(['id' => '\d+'])->withController('api_platform.action.get_item'),
'api_dummies_put_item' => (new Put())->withUriTemplate($path),
'api_dummies_delete_item' => (new Delete())->withUriTemplate($path),
// Custom operations
'api_dummies_my_op_collection' => new Get(
uriTemplate: $path,
defaults: ['my_default' => 'default_value', '_format' => 'a valid format'],
requirements: ['_format' => 'a valid format'],
condition: "request.headers.get('User-Agent') matches '/firefox/i'",
controller: 'some.service.name',
collection: true
), // With controller
'api_dummies_my_second_op_collection' => new Post(
uriTemplate: $path,
options: ['option' => 'option_value'],
host: '{subdomain}.api-platform.com',
schemes: ['https'],
), //without controller, takes the default one
'api_dummies_my_path_op_collection' => new Get(
uriTemplate: 'some/custom/path',
collection: true,
), // Custom path
'api_dummies_my_stateless_op_collection' => new Get(
uriTemplate: $path,
stateless: true,
collection: true
),
],
identifiers: ['id']
)]);
'api_dummies_my_op_collection' => (new Get())->withUriTemplate('/dummies.{_format}')->withDefaults(['my_default' => 'default_value', '_format' => 'a valid format'])->withRequirements(['_format' => 'a valid format'])->withCondition("request.headers.get('User-Agent') matches '/firefox/i'")->withController('some.service.name')->withCollection(true),
'api_dummies_my_second_op_collection' => (new Post())->withUriTemplate('/dummies.{_format}')->withOptions(['option' => 'option_value'])->withHost('{subdomain}.api-platform.com')->withSchemes(['https'])->withCollection(true),
//without controller, takes the default one
'api_dummies_my_path_op_collection' => (new Get())->withUriTemplate('some/custom/path')->withCollection(true),
// Custom path
'api_dummies_my_stateless_op_collection' => (new Get())->withUriTemplate('/dummies.{_format}')->withStateless(true)->withCollection(true),
]),
]);

$routeCollection = $this->getApiLoaderWithResourceMetadataCollection($resourceCollection)->load(null);

Expand Down Expand Up @@ -142,7 +118,7 @@ public function testApiLoader()

$this->assertEquals(
$this->getRoute(
$path,
'/dummies.{_format}',
'some.service.name',
null,
RelatedDummyEntity::class,
Expand All @@ -154,14 +130,14 @@ public function testApiLoader()
[],
'',
[],
"request.headers.get('User-Agent') matches '/firefox/i'",
"request.headers.get('User-Agent') matches '/firefox/i'"
),
$routeCollection->get('api_dummies_my_op_collection')
);

$this->assertEquals(
$this->getRoute(
$path,
'/dummies.{_format}',
'api_platform.action.placeholder',
null,
RelatedDummyEntity::class,
Expand All @@ -172,7 +148,7 @@ public function testApiLoader()
[],
['option' => 'option_value'],
'{subdomain}.api-platform.com',
['https'],
['https']
),
$routeCollection->get('api_dummies_my_second_op_collection')
);
Expand All @@ -187,22 +163,22 @@ public function testApiLoader()
'api_dummies_my_path_op_collection',
[],
['GET'],
[],
[]
),
$routeCollection->get('api_dummies_my_path_op_collection')
);

$this->assertEquals(
$this->getRoute(
$path,
'/dummies.{_format}',
'api_platform.action.placeholder',
true,
RelatedDummyEntity::class,
[],
'api_dummies_my_stateless_op_collection',
[],
['GET'],
[],
[]
),
$routeCollection->get('api_dummies_my_stateless_op_collection')
);
Expand All @@ -213,20 +189,11 @@ public function testApiLoaderWithPrefix()
$prefix = '/foobar-prefix';
$path = '/dummies/{id}.{_format}';

$resourceCollection = new ResourceMetadataCollection(Dummy::class, [new ApiResource(
shortName: 'dummy',
operations: [
'api_dummies_get_item' => new Get(
uriTemplate: $path,
routePrefix: $prefix,
defaults: ['my_default' => 'default_value', '_controller' => 'should_not_be_overriden'],
requirements: ['id' => '\d+'],
),
'api_dummies_put_item' => new Put(uriTemplate: $path, routePrefix: $prefix),
'api_dummies_delete_item' => new Delete(uriTemplate: $path, routePrefix: $prefix),
],
identifiers: ['id'],
)]);
$resourceCollection = new ResourceMetadataCollection(Dummy::class, [(new ApiResource())->withShortName('dummy')->withOperations([
'api_dummies_get_item' => (new Get())->withUriTemplate($path)->withRoutePrefix($prefix)->withDefaults(['my_default' => 'default_value', '_controller' => 'should_not_be_overriden'])->withRequirements(['id' => '\d+']),
'api_dummies_put_item' => (new Put())->withUriTemplate($path)->withRoutePrefix($prefix),
'api_dummies_delete_item' => (new Delete())->withUriTemplate($path)->withRoutePrefix($prefix),
])]);

$routeCollection = $this->getApiLoaderWithResourceMetadataCollection($resourceCollection)->load(null);

Expand Down Expand Up @@ -256,7 +223,7 @@ public function testApiLoaderWithPrefix()
[],
'api_dummies_delete_item',
[],
['DELETE'],
['DELETE']
),
$routeCollection->get('api_dummies_delete_item')
);
Expand All @@ -270,7 +237,7 @@ public function testApiLoaderWithPrefix()
[],
'api_dummies_put_item',
[],
['PUT'],
['PUT']
),
$routeCollection->get('api_dummies_put_item')
);
Expand Down
122 changes: 60 additions & 62 deletions tests/OpenApi/Factory/OpenApiFactoryTest.php
Expand Up @@ -66,76 +66,74 @@ public function testInvoke(): void
'class' => OutputDto::class,
])->withPaginationClientItemsPerPage(true);

$dummyResource = new ApiResource(
operations: [
'getDummyItem' => (new Get())->withUriTemplate('/dummies/{id}')->withOperation($baseOperation)->withIdentifiers(['id' => [Dummy::class, 'id']]),
'putDummyItem' => (new Put())->withUriTemplate('/dummies/{id}')->withOperation($baseOperation)->withIdentifiers(['id' => [Dummy::class, 'id']]),
'deleteDummyItem' => (new Delete())->withUriTemplate('/dummies/{id}')->withOperation($baseOperation)->withIdentifiers(['id' => [Dummy::class, 'id']]),
'customDummyItem' => (new Operation())->withMethod(Operation::METHOD_HEAD)->withUriTemplate('/foo/{id}')->withOperation($baseOperation)->withIdentifiers(['id' => [Dummy::class, 'id']])->withOpenapiContext([
'x-visibility' => 'hide',
'description' => 'Custom description',
'parameters' => [
['description' => 'Test parameter', 'name' => 'param', 'in' => 'path', 'required' => true],
['description' => 'Replace parameter', 'name' => 'id', 'in' => 'path', 'required' => true, 'schema' => ['type' => 'string', 'format' => 'uuid']],
],
'tags' => ['Dummy', 'Profile'],
'responses' => [
'202' => [
'description' => 'Success',
'content' => [
'application/json' => [
'schema' => ['$ref' => '#/components/schemas/Dummy'],
],
],
'headers' => [
'Foo' => ['description' => 'A nice header', 'schema' => ['type' => 'integer']],
],
'links' => [
'Foo' => ['$ref' => '#/components/schemas/Dummy'],
$dummyResource = (new ApiResource())->withOperations([
'getDummyItem' => (new Get())->withUriTemplate('/dummies/{id}')->withOperation($baseOperation)->withIdentifiers(['id' => [Dummy::class, 'id']]),
'putDummyItem' => (new Put())->withUriTemplate('/dummies/{id}')->withOperation($baseOperation)->withIdentifiers(['id' => [Dummy::class, 'id']]),
'deleteDummyItem' => (new Delete())->withUriTemplate('/dummies/{id}')->withOperation($baseOperation)->withIdentifiers(['id' => [Dummy::class, 'id']]),
'customDummyItem' => (new Operation())->withMethod(Operation::METHOD_HEAD)->withUriTemplate('/foo/{id}')->withOperation($baseOperation)->withIdentifiers(['id' => [Dummy::class, 'id']])->withOpenapiContext([
'x-visibility' => 'hide',
'description' => 'Custom description',
'parameters' => [
['description' => 'Test parameter', 'name' => 'param', 'in' => 'path', 'required' => true],
['description' => 'Replace parameter', 'name' => 'id', 'in' => 'path', 'required' => true, 'schema' => ['type' => 'string', 'format' => 'uuid']],
],
'tags' => ['Dummy', 'Profile'],
'responses' => [
'202' => [
'description' => 'Success',
'content' => [
'application/json' => [
'schema' => ['$ref' => '#/components/schemas/Dummy'],
],
],
'205' => [],
'headers' => [
'Foo' => ['description' => 'A nice header', 'schema' => ['type' => 'integer']],
],
'links' => [
'Foo' => ['$ref' => '#/components/schemas/Dummy'],
],
],
'requestBody' => [
'required' => true,
'description' => 'Custom request body',
'content' => [
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'file' => [
'type' => 'string',
'format' => 'binary',
],
'205' => [],
],
'requestBody' => [
'required' => true,
'description' => 'Custom request body',
'content' => [
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'file' => [
'type' => 'string',
'format' => 'binary',
],
],
],
],
],
'externalDocs' => ['url' => 'http://schema.example.com/Dummy', 'description' => 'See also'],
]
),
'custom-http-verb' => (new Operation())->withMethod('TEST')->withOperation($baseOperation),
'formatsDummyItem' => (new Put())->withOperation($baseOperation)->withUriTemplate('/formatted/{id}')->withIdentifiers(['id' => [Dummy::class, 'id']])->withInputFormats(['json' => ['application/json'], 'csv' => ['text/csv']])->withOutputFormats(['json' => ['application/json'], 'csv' => ['text/csv']]),
'getDummyCollection' => (new GetCollection())->withUriTemplate('/dummies')->withOpenApiContext([
'parameters' => [
['description' => 'Test modified collection page number', 'name' => 'page', 'in' => 'query', 'required' => false, 'schema' => ['type' => 'integer', 'default' => 1], 'allowEmptyValue' => true],
],
],
)->withOperation($baseOperation),
'postDummyCollection' => (new Post())->withUriTemplate('/dummies')->withOperation($baseOperation),
// Filtered
'filteredDummyCollection' => (new Get())->withUriTemplate('/filtered')->withCollection(true)->withFilters(['f1', 'f2', 'f3', 'f4', 'f5'])->withOperation($baseOperation),
// Paginated
'paginatedDummyCollection' => (new Get())->withUriTemplate('/paginated')
->withCollection(true)
->withPaginationClientEnabled(true)
->withPaginationClientItemsPerPage(true)
->withPaginationItemsPerPage(20)
->withPaginationMaximumItemsPerPage(80)
->withOperation($baseOperation),
],
'externalDocs' => ['url' => 'http://schema.example.com/Dummy', 'description' => 'See also'],
]
),
'custom-http-verb' => (new Operation())->withMethod('TEST')->withOperation($baseOperation),
'formatsDummyItem' => (new Put())->withOperation($baseOperation)->withUriTemplate('/formatted/{id}')->withIdentifiers(['id' => [Dummy::class, 'id']])->withInputFormats(['json' => ['application/json'], 'csv' => ['text/csv']])->withOutputFormats(['json' => ['application/json'], 'csv' => ['text/csv']]),
'getDummyCollection' => (new GetCollection())->withUriTemplate('/dummies')->withOpenApiContext([
'parameters' => [
['description' => 'Test modified collection page number', 'name' => 'page', 'in' => 'query', 'required' => false, 'schema' => ['type' => 'integer', 'default' => 1], 'allowEmptyValue' => true],
],
])->withOperation($baseOperation),
'postDummyCollection' => (new Post())->withUriTemplate('/dummies')->withOperation($baseOperation),
// Filtered
'filteredDummyCollection' => (new Get())->withUriTemplate('/filtered')->withCollection(true)->withFilters(['f1', 'f2', 'f3', 'f4', 'f5'])->withOperation($baseOperation),
// Paginated
'paginatedDummyCollection' => (new Get())->withUriTemplate('/paginated')
->withCollection(true)
->withPaginationClientEnabled(true)
->withPaginationClientItemsPerPage(true)
->withPaginationItemsPerPage(20)
->withPaginationMaximumItemsPerPage(80)
->withOperation($baseOperation),
]
);

$resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class);
Expand Down Expand Up @@ -235,7 +233,7 @@ public function testInvoke(): void
'name' => 'key',
],
]),
new PaginationOptions(true, 'page', true, 'itemsPerPage', true, 'pagination'),
new PaginationOptions(true, 'page', true, 'itemsPerPage', true, 'pagination')
);

$dummySchema = new Schema('openapi');
Expand Down

0 comments on commit 7e23650

Please sign in to comment.