|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace ApiPlatform\Tests\Symfony\Bundle\DependencyInjection\Compiler; |
| 15 | + |
| 16 | +use ApiPlatform\Core\Api\IriConverterInterface; |
| 17 | +use ApiPlatform\Core\Tests\ProphecyTrait; |
| 18 | +use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\DeprecateLegacyIriConverterPass; |
| 19 | +use PHPUnit\Framework\TestCase; |
| 20 | +use Symfony\Component\Config\Definition\BaseNode; |
| 21 | +use Symfony\Component\DependencyInjection\Alias; |
| 22 | +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
| 23 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 24 | +use Symfony\Component\DependencyInjection\Definition; |
| 25 | + |
| 26 | +final class DeprecateLegacyIriConverterPassTest extends TestCase |
| 27 | +{ |
| 28 | + use ProphecyTrait; |
| 29 | + |
| 30 | + public function testProcess(): void |
| 31 | + { |
| 32 | + $deprecateIriConverterPass = new DeprecateLegacyIriConverterPass(); |
| 33 | + |
| 34 | + $this->assertInstanceOf(CompilerPassInterface::class, $deprecateIriConverterPass); |
| 35 | + |
| 36 | + $containerBuilderProphecy = $this->prophesize(ContainerBuilder::class); |
| 37 | + $aliasProphecy = $this->prophesize(Alias::class); |
| 38 | + $definitionProphecy = $this->prophesize(Definition::class); |
| 39 | + |
| 40 | + $containerBuilderProphecy |
| 41 | + ->hasDefinition(IriConverterInterface::class) |
| 42 | + ->willReturn(true); |
| 43 | + |
| 44 | + $containerBuilderProphecy |
| 45 | + ->hasAlias(IriConverterInterface::class) |
| 46 | + ->willReturn(true); |
| 47 | + |
| 48 | + $containerBuilderProphecy |
| 49 | + ->hasDefinition('api_platform.iri_converter.legacy') |
| 50 | + ->willReturn(true); |
| 51 | + |
| 52 | + $containerBuilderProphecy |
| 53 | + ->getDefinition(IriConverterInterface::class) |
| 54 | + ->willReturn($definitionProphecy->reveal()) |
| 55 | + ->shouldBeCalled(); |
| 56 | + |
| 57 | + $containerBuilderProphecy |
| 58 | + ->getAlias(IriConverterInterface::class) |
| 59 | + ->willReturn($aliasProphecy->reveal()) |
| 60 | + ->shouldBeCalled(); |
| 61 | + |
| 62 | + $containerBuilderProphecy |
| 63 | + ->getDefinition('api_platform.iri_converter.legacy') |
| 64 | + ->willReturn($definitionProphecy->reveal()) |
| 65 | + ->shouldBeCalled(); |
| 66 | + |
| 67 | + $setDeprecatedAliasArgs = method_exists(BaseNode::class, 'getDeprecation') |
| 68 | + ? ['api-platform/core', '2.7', 'Using "%alias_id%" is deprecated since API Platform 2.7. Use "ApiPlatform\Api\IriConverterInterface" instead.'] |
| 69 | + : ['Using "%alias_id%" is deprecated since API Platform 2.7. Use "ApiPlatform\Api\IriConverterInterface" instead.']; |
| 70 | + |
| 71 | + $setDeprecatedDefinitionArgs = method_exists(BaseNode::class, 'getDeprecation') |
| 72 | + ? ['api-platform/core', '2.7', 'Using "%service_id%" is deprecated since API Platform 2.7. Use "ApiPlatform\Api\IriConverterInterface" instead.'] |
| 73 | + : ['Using "%service_id%" is deprecated since API Platform 2.7. Use "ApiPlatform\Api\IriConverterInterface" instead.']; |
| 74 | + |
| 75 | + $aliasProphecy |
| 76 | + ->setDeprecated(...$setDeprecatedAliasArgs) |
| 77 | + ->willReturn($aliasProphecy->reveal()) |
| 78 | + ->shouldBeCalled(); |
| 79 | + |
| 80 | + $definitionProphecy |
| 81 | + ->setDeprecated(...$setDeprecatedDefinitionArgs) |
| 82 | + ->willReturn($definitionProphecy->reveal()) |
| 83 | + ->shouldBeCalled(); |
| 84 | + |
| 85 | + $deprecateIriConverterPass->process($containerBuilderProphecy->reveal()); |
| 86 | + } |
| 87 | + |
| 88 | + public function testProcessWithoutDefinition(): void |
| 89 | + { |
| 90 | + $deprecateIriConverterPass = new DeprecateLegacyIriConverterPass(); |
| 91 | + $containerBuilderProphecy = $this->prophesize(ContainerBuilder::class); |
| 92 | + |
| 93 | + $containerBuilderProphecy |
| 94 | + ->hasDefinition(IriConverterInterface::class) |
| 95 | + ->willReturn(false); |
| 96 | + |
| 97 | + $containerBuilderProphecy |
| 98 | + ->hasAlias(IriConverterInterface::class) |
| 99 | + ->willReturn(false); |
| 100 | + |
| 101 | + $containerBuilderProphecy |
| 102 | + ->hasDefinition('api_platform.iri_converter.legacy') |
| 103 | + ->willReturn(false); |
| 104 | + |
| 105 | + $containerBuilderProphecy |
| 106 | + ->getDefinition(IriConverterInterface::class) |
| 107 | + ->shouldNotBeCalled(); |
| 108 | + |
| 109 | + $containerBuilderProphecy |
| 110 | + ->getAlias(IriConverterInterface::class) |
| 111 | + ->shouldNotBeCalled(); |
| 112 | + |
| 113 | + $containerBuilderProphecy |
| 114 | + ->getDefinition('api_platform.iri_converter.legacy') |
| 115 | + ->shouldNotBeCalled(); |
| 116 | + |
| 117 | + $deprecateIriConverterPass->process($containerBuilderProphecy->reveal()); |
| 118 | + } |
| 119 | +} |
0 commit comments