Skip to content

Commit 7d835cb

Browse files
authored
fix: processor auto configuration (#4675)
1 parent bf21619 commit 7d835cb

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use ApiPlatform\GraphQl\Resolver\QueryCollectionResolverInterface;
3737
use ApiPlatform\GraphQl\Resolver\QueryItemResolverInterface;
3838
use ApiPlatform\GraphQl\Type\Definition\TypeInterface as GraphQlTypeInterface;
39+
use ApiPlatform\State\ProcessorInterface;
3940
use ApiPlatform\State\ProviderInterface;
4041
use ApiPlatform\Symfony\Validator\Metadata\Property\Restriction\PropertySchemaRestrictionMetadataInterface;
4142
use ApiPlatform\Symfony\Validator\ValidationGroupsGeneratorInterface;
@@ -142,10 +143,13 @@ public function load(array $configs, ContainerBuilder $container): void
142143
->addTag('api_platform.collection_data_provider');
143144
$container->registerForAutoconfiguration(SubresourceDataProviderInterface::class)
144145
->addTag('api_platform.subresource_data_provider');
146+
145147
$container->registerForAutoconfiguration(FilterInterface::class)
146148
->addTag('api_platform.filter');
147149
$container->registerForAutoconfiguration(ProviderInterface::class)
148150
->addTag('api_platform.state_provider');
151+
$container->registerForAutoconfiguration(ProcessorInterface::class)
152+
->addTag('api_platform.state_processor');
149153
}
150154

151155
private function registerCommonConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader, array $formats, array $patchFormats, array $errorFormats): void

tests/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,30 @@
1313

1414
namespace ApiPlatform\Tests\Symfony\Bundle\DependencyInjection;
1515

16+
use ApiPlatform\Api\FilterInterface;
1617
use ApiPlatform\Api\UrlGeneratorInterface;
18+
use ApiPlatform\Core\DataPersister\DataPersisterInterface;
19+
use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
20+
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
21+
use ApiPlatform\Core\DataProvider\SubresourceDataProviderInterface;
1722
use ApiPlatform\Core\Tests\ProphecyTrait;
23+
use ApiPlatform\DataTransformer\DataTransformerInitializerInterface;
24+
use ApiPlatform\DataTransformer\DataTransformerInterface;
25+
use ApiPlatform\Doctrine\Odm\Extension\AggregationCollectionExtensionInterface;
26+
use ApiPlatform\Doctrine\Odm\Extension\AggregationItemExtensionInterface;
27+
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface as DoctrineQueryCollectionExtensionInterface;
28+
use ApiPlatform\Doctrine\Orm\Extension\QueryItemExtensionInterface;
29+
use ApiPlatform\Elasticsearch\Extension\RequestBodySearchCollectionExtensionInterface;
30+
use ApiPlatform\GraphQl\Error\ErrorHandlerInterface;
31+
use ApiPlatform\GraphQl\Resolver\MutationResolverInterface;
32+
use ApiPlatform\GraphQl\Resolver\QueryCollectionResolverInterface;
33+
use ApiPlatform\GraphQl\Resolver\QueryItemResolverInterface;
34+
use ApiPlatform\GraphQl\Type\Definition\TypeInterface as GraphQlTypeInterface;
35+
use ApiPlatform\State\ProcessorInterface;
36+
use ApiPlatform\State\ProviderInterface;
1837
use ApiPlatform\Symfony\Bundle\DependencyInjection\ApiPlatformExtension;
38+
use ApiPlatform\Symfony\Validator\Metadata\Property\Restriction\PropertySchemaRestrictionMetadataInterface;
39+
use ApiPlatform\Symfony\Validator\ValidationGroupsGeneratorInterface;
1940
use Doctrine\Common\Annotations\Annotation;
2041
use phpDocumentor\Reflection\DocBlockFactoryInterface;
2142
use PHPUnit\Framework\TestCase;
@@ -1599,6 +1620,10 @@ public function testElasticsearchConfiguration(): void
15991620
];
16001621

16011622
$this->assertContainerHas($services, $aliases, $tags);
1623+
1624+
$autoconfiguredInstances = $this->container->getAutoconfiguredInstanceof();
1625+
$this->assertArrayHasKey(RequestBodySearchCollectionExtensionInterface::class, $autoconfiguredInstances);
1626+
$this->assertArrayHasKey('api_platform.elasticsearch.request_body_search_extension.collection', $autoconfiguredInstances[RequestBodySearchCollectionExtensionInterface::class]->getTags());
16021627
}
16031628

16041629
public function testSecurityConfiguration(): void
@@ -1796,4 +1821,43 @@ public function testRectorConfiguration(): void
17961821

17971822
$this->assertContainerHas($services, [], $tags);
17981823
}
1824+
1825+
public function testAutoConfigurableInterfaces(): void
1826+
{
1827+
$config = self::DEFAULT_CONFIG;
1828+
(new ApiPlatformExtension())->load($config, $this->container);
1829+
1830+
$interfaces = [
1831+
FilterInterface::class => 'api_platform.filter',
1832+
ProviderInterface::class => 'api_platform.state_provider',
1833+
ProcessorInterface::class => 'api_platform.state_processor',
1834+
DataPersisterInterface::class => 'api_platform.data_persister',
1835+
ItemDataProviderInterface::class => 'api_platform.item_data_provider',
1836+
CollectionDataProviderInterface::class => 'api_platform.collection_data_provider',
1837+
SubresourceDataProviderInterface::class => 'api_platform.subresource_data_provider',
1838+
DataTransformerInterface::class => 'api_platform.data_transformer',
1839+
DataTransformerInitializerInterface::class => 'api_platform.data_transformer',
1840+
ValidationGroupsGeneratorInterface::class => 'api_platform.validation_groups_generator',
1841+
PropertySchemaRestrictionMetadataInterface::class => 'api_platform.metadata.property_schema_restriction',
1842+
QueryItemResolverInterface::class => 'api_platform.graphql.query_resolver',
1843+
QueryCollectionResolverInterface::class => 'api_platform.graphql.query_resolver',
1844+
MutationResolverInterface::class => 'api_platform.graphql.mutation_resolver',
1845+
GraphQlTypeInterface::class => 'api_platform.graphql.type',
1846+
ErrorHandlerInterface::class => 'api_platform.graphql.error_handler',
1847+
QueryItemExtensionInterface::class => 'api_platform.doctrine.orm.query_extension.item',
1848+
DoctrineQueryCollectionExtensionInterface::class => 'api_platform.doctrine.orm.query_extension.collection',
1849+
AggregationItemExtensionInterface::class => 'api_platform.doctrine_mongodb.odm.aggregation_extension.item',
1850+
AggregationCollectionExtensionInterface::class => 'api_platform.doctrine_mongodb.odm.aggregation_extension.collection',
1851+
];
1852+
1853+
$has = [];
1854+
foreach ($this->container->getAutoconfiguredInstanceof() as $interface => $childDefinition) {
1855+
if (isset($interfaces[$interface])) {
1856+
$has[] = $interface;
1857+
$this->assertArrayHasKey($interfaces[$interface], $childDefinition->getTags());
1858+
}
1859+
}
1860+
1861+
$this->assertEmpty(array_diff(array_keys($interfaces), $has), 'Not all expected interfaces are autoconfigurable.');
1862+
}
17991863
}

0 commit comments

Comments
 (0)