Skip to content

Commit a5a86e0

Browse files
authored
chore(deprecation): missing bc flag parameter (#4730)
1 parent 7f609dc commit a5a86e0

File tree

7 files changed

+85
-49
lines changed

7 files changed

+85
-49
lines changed

src/Core/EventListener/WriteListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class WriteListener
4747
private $iriConverter;
4848
private $metadataBackwardCompatibilityLayer;
4949

50-
public function __construct(DataPersisterInterface $dataPersister, $iriConverter = null, ResourceMetadataFactoryInterface $resourceMetadataFactory = null, ResourceClassResolverInterface $resourceClassResolver = null, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, bool $metadataBackwardCompatibilityLayer = null)
50+
public function __construct(DataPersisterInterface $dataPersister, $iriConverter = null, ResourceMetadataFactoryInterface $resourceMetadataFactory = null, ResourceClassResolverInterface $resourceClassResolver = null, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, ?bool $metadataBackwardCompatibilityLayer = null)
5151
{
5252
$this->dataPersister = $dataPersister;
5353
$this->iriConverter = $iriConverter;

src/Core/Metadata/Property/Factory/AnnotationPropertyMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(Reader $reader = null, PropertyMetadataFactoryInterf
4040
*/
4141
public function create(string $resourceClass, string $property, array $options = []): PropertyMetadata
4242
{
43-
if (false === ($options['deprecate'] ?? null)) {
43+
if (null === ($options['deprecate'] ?? null)) {
4444
trigger_deprecation('api-platform/core', '2.7', sprintf('Decorating the legacy %s is deprecated, use %s instead.', PropertyMetadataFactoryInterface::class, \ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface::class));
4545
}
4646

src/Core/Operation/Factory/SubresourceOperationFactory.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa
5050
*/
5151
public function create(string $resourceClass): array
5252
{
53-
trigger_deprecation('api-platform/core', '2.7', 'Subresources are deprecated, use alternate URLs instead.');
54-
5553
$tree = [];
5654

5755
try {
@@ -78,12 +76,13 @@ private function computeSubresourceOperations(string $resourceClass, array &$tre
7876
}
7977

8078
foreach ($this->propertyNameCollectionFactory->create($resourceClass) as $property) {
81-
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $property);
79+
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $property, ['deprecate' => false]);
8280

8381
if (!$subresource = $propertyMetadata->getSubresource()) {
8482
continue;
8583
}
8684

85+
trigger_deprecation('api-platform/core', '2.7', sprintf('A subresource is declared on "%s::%s". Subresources are deprecated, use another #[ApiResource] instead.', $resourceClass, $property));
8786
$subresourceClass = $subresource->getResourceClass();
8887
$subresourceMetadata = $this->resourceMetadataFactory->create($subresourceClass);
8988
$subresourceMetadata = $subresourceMetadata->withAttributes(($subresourceMetadata->getAttributes() ?: []) + ['identifiers' => !$this->identifiersExtractor ? [$property] : $this->identifiersExtractor->getIdentifiersFromResourceClass($subresourceClass)]);

src/Symfony/Bundle/Resources/config/v3/backward_compatibility.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
<argument type="service" id="api_platform.iri_converter" />
2828
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
2929
<argument type="service" id="api_platform.resource_class_resolver" />
30+
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory" />
31+
<argument>%api_platform.metadata_backward_compatibility_layer%</argument>
3032

3133
<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" priority="32" />
3234
</service>

tests/Core/Bridge/Symfony/Routing/ApiLoaderTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ private function getApiLoaderWithResourceMetadata(ResourceMetadata $resourceMeta
275275
$propertyNameCollectionFactoryProphecy->create(RelatedDummyEntity::class)->willReturn(new PropertyNameCollection(['id', 'recursivesubresource', 'secondrecursivesubresource']));
276276

277277
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
278-
$propertyMetadataFactoryProphecy->create(RelatedDummyEntity::class, 'id')->willReturn(new PropertyMetadata());
279-
$propertyMetadataFactoryProphecy->create(DummyEntity::class, 'id')->willReturn(new PropertyMetadata());
278+
$propertyMetadataFactoryProphecy->create(RelatedDummyEntity::class, 'id', Argument::type('array'))->willReturn(new PropertyMetadata());
279+
$propertyMetadataFactoryProphecy->create(DummyEntity::class, 'id', Argument::type('array'))->willReturn(new PropertyMetadata());
280280

281281
$relatedType = new Type(Type::BUILTIN_TYPE_OBJECT, false, RelatedDummyEntity::class);
282282

@@ -285,21 +285,21 @@ private function getApiLoaderWithResourceMetadata(ResourceMetadata $resourceMeta
285285
->withType(new Type(Type::BUILTIN_TYPE_ARRAY, false, \ArrayObject::class, true, null, $relatedType));
286286

287287
if (false === $recursiveSubresource) {
288-
$propertyMetadataFactoryProphecy->create(RelatedDummyEntity::class, 'recursivesubresource')->willReturn(new PropertyMetadata());
289-
$propertyMetadataFactoryProphecy->create(RelatedDummyEntity::class, 'secondrecursivesubresource')->willReturn(new PropertyMetadata());
288+
$propertyMetadataFactoryProphecy->create(RelatedDummyEntity::class, 'recursivesubresource', Argument::type('array'))->willReturn(new PropertyMetadata());
289+
$propertyMetadataFactoryProphecy->create(RelatedDummyEntity::class, 'secondrecursivesubresource', Argument::type('array'))->willReturn(new PropertyMetadata());
290290
} else {
291291
$dummyType = new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyEntity::class);
292-
$propertyMetadataFactoryProphecy->create(RelatedDummyEntity::class, 'recursivesubresource')
292+
$propertyMetadataFactoryProphecy->create(RelatedDummyEntity::class, 'recursivesubresource', Argument::type('array'))
293293
->willReturn((new PropertyMetadata())
294294
->withSubresource(new SubresourceMetadata(DummyEntity::class, false))
295295
->withType($dummyType));
296-
$propertyMetadataFactoryProphecy->create(RelatedDummyEntity::class, 'secondrecursivesubresource')
296+
$propertyMetadataFactoryProphecy->create(RelatedDummyEntity::class, 'secondrecursivesubresource', Argument::type('array'))
297297
->willReturn((new PropertyMetadata())
298298
->withSubresource(new SubresourceMetadata(DummyEntity::class, false))
299299
->withType($dummyType));
300300
}
301301

302-
$propertyMetadataFactoryProphecy->create(DummyEntity::class, 'subresource')->willReturn($subResourcePropertyMetadata);
302+
$propertyMetadataFactoryProphecy->create(DummyEntity::class, 'subresource', Argument::type('array'))->willReturn($subResourcePropertyMetadata);
303303

304304
$operationPathResolver = new CustomOperationPathResolver(new OperationPathResolver(new UnderscorePathSegmentNameGenerator()));
305305

tests/Core/Metadata/Property/Factory/AnnotationPropertyMetadataFactoryTest.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@
2424
use Doctrine\Common\Annotations\Reader;
2525
use PHPUnit\Framework\TestCase;
2626
use Prophecy\Argument;
27+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
2728

2829
/**
2930
* @author Kévin Dunglas <[email protected]>
30-
* @group legacy
3131
*/
3232
class AnnotationPropertyMetadataFactoryTest extends TestCase
3333
{
34+
use ExpectDeprecationTrait;
3435
use ProphecyTrait;
3536

3637
/**
3738
* @dataProvider dependenciesProvider
3839
*
3940
* @param mixed $reader
4041
* @param mixed $decorated
42+
* @group legacy
4143
*/
4244
public function testCreateProperty($reader, $decorated, string $description)
4345
{
@@ -57,9 +59,11 @@ public function testCreateProperty($reader, $decorated, string $description)
5759

5860
/**
5961
* @requires PHP 8.0
62+
* @group legacy
6063
*/
6164
public function testCreateAttribute()
6265
{
66+
$this->expectDeprecation('Since api-platform/core 2.7: Decorating the legacy ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface is deprecated, use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface instead.');
6367
$factory = new AnnotationPropertyMetadataFactory();
6468

6569
$metadata = $factory->create(DummyPhp8::class, 'id');
@@ -109,17 +113,25 @@ public function dependenciesProvider(): array
109113
];
110114
}
111115

116+
/**
117+
* @group legacy
118+
*/
112119
public function testClassNotFound()
113120
{
121+
$this->expectDeprecation('Since api-platform/core 2.7: Decorating the legacy ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface is deprecated, use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface instead.');
114122
$this->expectException(PropertyNotFoundException::class);
115123
$this->expectExceptionMessage('Property "foo" of class "\\DoNotExist" not found.');
116124

117125
$factory = new AnnotationPropertyMetadataFactory($this->prophesize(Reader::class)->reveal());
118126
$factory->create('\DoNotExist', 'foo');
119127
}
120128

129+
/**
130+
* @group legacy
131+
*/
121132
public function testClassNotFoundButParentFound()
122133
{
134+
$this->expectDeprecation('Since api-platform/core 2.7: Decorating the legacy ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface is deprecated, use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface instead.');
123135
$propertyMetadata = new PropertyMetadata();
124136

125137
$decoratedProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
@@ -128,4 +140,24 @@ public function testClassNotFoundButParentFound()
128140
$factory = new AnnotationPropertyMetadataFactory($this->prophesize(Reader::class)->reveal(), $decoratedProphecy->reveal());
129141
$this->assertEquals($propertyMetadata, $factory->create('\DoNotExist', 'foo'));
130142
}
143+
144+
public function testSkipDeprecation()
145+
{
146+
$annotation = new ApiProperty();
147+
$annotation->description = 'description';
148+
$annotation->readable = true;
149+
$annotation->writable = true;
150+
$annotation->readableLink = false;
151+
$annotation->writableLink = false;
152+
$annotation->identifier = false;
153+
$annotation->required = true;
154+
$annotation->iri = 'foo';
155+
$annotation->attributes = ['foo' => 'bar'];
156+
157+
$propertyReaderProphecy = $this->prophesize(Reader::class);
158+
$propertyReaderProphecy->getPropertyAnnotation(Argument::type(\ReflectionProperty::class), ApiProperty::class)->willReturn($annotation)->shouldBeCalled();
159+
160+
$factory = new AnnotationPropertyMetadataFactory($propertyReaderProphecy->reveal());
161+
$metadata = $factory->create(Dummy::class, 'name', ['deprecate' => false]);
162+
}
131163
}

0 commit comments

Comments
 (0)