Skip to content

Commit 61d9cdc

Browse files
committed
fix(test): remove SerializerAwareProvider mechanism and related compiler pass
Fixes phpstan error ignored in the config.
1 parent 77b292b commit 61d9cdc

File tree

8 files changed

+27
-128
lines changed

8 files changed

+27
-128
lines changed

phpstan.neon.dist

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ parameters:
104104
- src/Serializer/AbstractConstraintViolationListNormalizer.php
105105
- src/Symfony/Validator/Serializer/ValidationExceptionNormalizer.php
106106

107-
# See https://github.com/phpstan/phpstan-symfony/issues/27
108-
-
109-
message: '#^Service "[^"]+" is private.$#'
110-
path: src
111-
112-
113107
# Allow extra assertions in tests: https://github.com/phpstan/phpstan-strict-rules/issues/130
114108
- '#^Call to (static )?method PHPUnit\\Framework\\Assert::.* will always evaluate to true\.$#'
115109

src/State/SerializerAwareProviderInterface.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/State/SerializerAwareProviderTrait.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/Symfony/Bundle/ApiPlatformBundle.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\AttributeFilterPass;
1717
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\AttributeResourcePass;
1818
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\AuthenticatorManagerPass;
19-
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\DataProviderPass;
2019
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\ElasticsearchClientPass;
2120
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\FilterPass;
2221
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\GraphQlResolverPass;
@@ -43,7 +42,6 @@ public function build(ContainerBuilder $container): void
4342
{
4443
parent::build($container);
4544

46-
$container->addCompilerPass(new DataProviderPass());
4745
// Run the compiler pass before the {@see ResolveInstanceofConditionalsPass} to allow autoconfiguration of generated filter definitions.
4846
$container->addCompilerPass(new AttributeFilterPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 101);
4947
$container->addCompilerPass(new AttributeResourcePass());

src/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/Fixtures/TestBundle/State/SerializableProvider.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,26 @@
1515

1616
use ApiPlatform\Metadata\Operation;
1717
use ApiPlatform\State\ProviderInterface;
18-
use ApiPlatform\State\SerializerAwareProviderInterface;
19-
use ApiPlatform\State\SerializerAwareProviderTrait;
18+
use Psr\Container\ContainerInterface;
19+
use Symfony\Component\Serializer\SerializerInterface;
20+
use Symfony\Contracts\Service\ServiceSubscriberInterface;
2021

2122
/**
2223
* @author Vincent Chalamon <[email protected]>
2324
*/
24-
class SerializableProvider implements ProviderInterface, SerializerAwareProviderInterface
25+
readonly class SerializableProvider implements ProviderInterface, ServiceSubscriberInterface
2526
{
26-
use SerializerAwareProviderTrait;
27+
public function __construct(private ContainerInterface $container)
28+
{
29+
}
30+
31+
/**
32+
* @return array<string, string>
33+
*/
34+
public static function getSubscribedServices(): array
35+
{
36+
return ['serializer' => SerializerInterface::class];
37+
}
2738

2839
/**
2940
* {@inheritDoc}
@@ -39,4 +50,13 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
3950
JSON
4051
, $operation->getClass(), 'json');
4152
}
53+
54+
private function getSerializer(): SerializerInterface
55+
{
56+
if (!$this->container->has('serializer')) {
57+
throw new \LogicException('The serializer service is not available. Did you forget to install symfony/serializer?');
58+
}
59+
60+
return $this->container->get('serializer');
61+
}
4262
}

tests/Fixtures/app/config/config_common.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ services:
138138
class: 'ApiPlatform\Tests\Fixtures\TestBundle\State\SerializableProvider'
139139
tags:
140140
- name: 'api_platform.state_provider'
141+
arguments:
142+
- !service_locator
143+
serializer: '@Symfony\Component\Serializer\SerializerInterface'
141144

142145
ApiPlatform\Tests\Fixtures\TestBundle\State\FakeProvider:
143146
class: 'ApiPlatform\Tests\Fixtures\TestBundle\State\FakeProvider'

tests/Symfony/Bundle/ApiPlatformBundleTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\AttributeFilterPass;
1818
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\AttributeResourcePass;
1919
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\AuthenticatorManagerPass;
20-
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\DataProviderPass;
2120
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\ElasticsearchClientPass;
2221
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\FilterPass;
2322
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\GraphQlResolverPass;
@@ -42,7 +41,6 @@ class ApiPlatformBundleTest extends TestCase
4241
public function testBuild(): void
4342
{
4443
$containerProphecy = $this->prophesize(ContainerBuilder::class);
45-
$containerProphecy->addCompilerPass(Argument::type(DataProviderPass::class))->willReturn($containerProphecy->reveal())->shouldBeCalled();
4644
$containerProphecy->addCompilerPass(Argument::type(AttributeFilterPass::class), PassConfig::TYPE_BEFORE_OPTIMIZATION, 101)->willReturn($containerProphecy->reveal())->shouldBeCalled();
4745
$containerProphecy->addCompilerPass(Argument::type(AttributeResourcePass::class))->shouldBeCalled()->willReturn($containerProphecy->reveal())->shouldBeCalled();
4846
$containerProphecy->addCompilerPass(Argument::type(FilterPass::class))->willReturn($containerProphecy->reveal())->shouldBeCalled();

0 commit comments

Comments
 (0)