Skip to content

Commit 04d5cff

Browse files
committed
test: property info deprecation
1 parent 76c80a6 commit 04d5cff

File tree

9 files changed

+391
-37
lines changed

9 files changed

+391
-37
lines changed

src/Doctrine/Odm/Tests/PropertyInfo/DoctrineExtractorTest.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Doctrine\Common\Collections\Collection;
2828
use Doctrine\ODM\MongoDB\DocumentManager;
2929
use Doctrine\ODM\MongoDB\Types\Type as MongoDbType;
30+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
3031
use PHPUnit\Framework\TestCase;
3132
use Symfony\Component\PropertyInfo\Type as LegacyType;
3233
use Symfony\Component\TypeInfo\Type;
@@ -83,7 +84,7 @@ public function testTestGetPropertiesWithEmbedded(): void
8384
);
8485
}
8586

86-
#[\PHPUnit\Framework\Attributes\Group('legacy')]
87+
#[IgnoreDeprecations]
8788
#[\PHPUnit\Framework\Attributes\DataProvider('legacyTypesProvider')]
8889
public function testExtractLegacy(string $property, ?array $type = null): void
8990
{
@@ -96,7 +97,7 @@ public function testExtract(string $property, ?Type $type): void
9697
$this->assertEquals($type, $this->createExtractor()->getType(DoctrineDummy::class, $property));
9798
}
9899

99-
#[\PHPUnit\Framework\Attributes\Group('legacy')]
100+
#[IgnoreDeprecations]
100101
public function testExtractWithEmbedOneLegacy(): void
101102
{
102103
$expectedTypes = [
@@ -123,7 +124,7 @@ public function testExtractWithEmbedOne(): void
123124
);
124125
}
125126

126-
#[\PHPUnit\Framework\Attributes\Group('legacy')]
127+
#[IgnoreDeprecations]
127128
public function testExtractWithEmbedManyLegacy(): void
128129
{
129130
$expectedTypes = [
@@ -153,7 +154,7 @@ public function testExtractWithEmbedMany(): void
153154
);
154155
}
155156

156-
#[\PHPUnit\Framework\Attributes\Group('legacy')]
157+
#[IgnoreDeprecations]
157158
public function testExtractEnumLegacy(): void
158159
{
159160
$this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, EnumString::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumString'));
@@ -168,6 +169,7 @@ public function testExtractEnum(): void
168169
$this->assertNull($this->createExtractor()->getType(DoctrineEnum::class, 'enumCustom'));
169170
}
170171

172+
#[IgnoreDeprecations]
171173
public static function legacyTypesProvider(): array
172174
{
173175
return [
@@ -258,7 +260,7 @@ public function testGetPropertiesCatchException(): void
258260
$this->assertNull($this->createExtractor()->getProperties('Not\Exist'));
259261
}
260262

261-
#[\PHPUnit\Framework\Attributes\Group('legacy')]
263+
#[IgnoreDeprecations]
262264
public function testGetTypesCatchExceptionLegacy(): void
263265
{
264266
$this->assertNull($this->createExtractor()->getTypes('Not\Exist', 'baz'));
@@ -278,7 +280,7 @@ public function testGeneratedValueNotWritable(): void
278280
$this->assertNull($extractor->isReadable(DoctrineGeneratedValue::class, 'foo'));
279281
}
280282

281-
#[\PHPUnit\Framework\Attributes\Group('legacy')]
283+
#[IgnoreDeprecations]
282284
public function testGetTypesWithEmbedManyOmittingTargetDocumentLegacy(): void
283285
{
284286
$actualTypes = $this->createExtractor()->getTypes(

src/Elasticsearch/Tests/Extension/SortExtensionTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use ApiPlatform\Metadata\GetCollection;
2121
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
2222
use ApiPlatform\Metadata\ResourceClassResolverInterface;
23+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
2324
use PHPUnit\Framework\TestCase;
2425
use Prophecy\PhpUnit\ProphecyTrait;
2526
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
@@ -53,6 +54,7 @@ public function testApplyToCollection(): void
5354
self::assertEquals(['sort' => [['name' => ['order' => 'asc']], ['bar' => ['order' => 'desc']]]], $sortExtension->applyToCollection([], Foo::class, (new GetCollection())->withOrder(['name', 'bar' => 'desc'])));
5455
}
5556

57+
#[IgnoreDeprecations]
5658
public function testApplyToCollectionWithNestedProperty(): void
5759
{
5860
$fooType = Type::list(Type::object(Foo::class));

src/Elasticsearch/Tests/Metadata/Resource/Factory/ElasticsearchProviderResourceMetadataCollectionFactoryTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
use ApiPlatform\Elasticsearch\Metadata\Resource\Factory\ElasticsearchProviderResourceMetadataCollectionFactory;
1717
use ApiPlatform\Elasticsearch\Tests\Fixtures\Foo;
1818
use ApiPlatform\Metadata\ApiResource;
19+
use ApiPlatform\Metadata\Get;
1920
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
2021
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
21-
use ApiPlatform\Metadata\Tests\Fixtures\Metadata\Get;
2222
use PHPUnit\Framework\TestCase;
2323
use Prophecy\PhpUnit\ProphecyTrait;
2424

src/Hydra/Tests/Serializer/DocumentationNormalizerTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use ApiPlatform\Metadata\Resource\ResourceNameCollection;
3333
use ApiPlatform\Metadata\ResourceClassResolverInterface;
3434
use ApiPlatform\Metadata\UrlGeneratorInterface;
35+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
3536
use PHPUnit\Framework\TestCase;
3637
use Prophecy\Argument;
3738
use Prophecy\PhpUnit\ProphecyTrait;
@@ -46,6 +47,7 @@ class DocumentationNormalizerTest extends TestCase
4647
{
4748
use ProphecyTrait;
4849

50+
#[IgnoreDeprecations]
4951
public function testNormalize(): void
5052
{
5153
$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);

src/JsonApi/Tests/Serializer/ConstraintViolationNormalizerTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ApiPlatform\JsonApi\Tests\Fixtures\RelatedDummy;
1919
use ApiPlatform\Metadata\ApiProperty;
2020
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
21+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
2122
use PHPUnit\Framework\TestCase;
2223
use Prophecy\PhpUnit\ProphecyTrait;
2324
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
@@ -47,6 +48,7 @@ public function testSupportNormalization(): void
4748
$this->assertSame([ConstraintViolationListInterface::class => true], $normalizer->getSupportedTypes($normalizer::FORMAT));
4849
}
4950

51+
#[IgnoreDeprecations]
5052
public function testNormalize(): void
5153
{
5254
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);

src/JsonSchema/Tests/Metadata/Property/Factory/SchemaPropertyMetadataFactoryTest.php

+67-5
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,58 @@
2020
use ApiPlatform\Metadata\ApiProperty;
2121
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
2222
use ApiPlatform\Metadata\ResourceClassResolverInterface;
23+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
2324
use PHPUnit\Framework\TestCase;
24-
use Symfony\Component\PropertyInfo\Type;
25+
use Symfony\Component\PropertyInfo\Type as LegacyType;
26+
use Symfony\Component\TypeInfo\Type;
2527

2628
class SchemaPropertyMetadataFactoryTest extends TestCase
2729
{
30+
#[IgnoreDeprecations]
31+
public function testEnumLegacy(): void
32+
{
33+
$this->expectUserDeprecationMessage('Since api_platform/metadata 4.2: The "builtinTypes" argument of "ApiPlatform\Metadata\ApiProperty" is deprecated, use "nativeType" instead.');
34+
$resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
35+
$apiProperty = new ApiProperty(builtinTypes: [new LegacyType(builtinType: 'object', nullable: true, class: IntEnumAsIdentifier::class)]);
36+
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
37+
$decorated->expects($this->once())->method('create')->with(DummyWithEnum::class, 'intEnumAsIdentifier')->willReturn($apiProperty);
38+
$schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
39+
$apiProperty = $schemaPropertyMetadataFactory->create(DummyWithEnum::class, 'intEnumAsIdentifier');
40+
$this->assertEquals(['type' => ['integer', 'null'], 'enum' => [1, 2, null]], $apiProperty->getSchema());
41+
}
42+
2843
public function testEnum(): void
2944
{
3045
$resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
31-
$apiProperty = new ApiProperty(builtinTypes: [new Type(builtinType: 'object', nullable: true, class: IntEnumAsIdentifier::class)]);
46+
$apiProperty = new ApiProperty(nativeType: Type::nullable(Type::enum(IntEnumAsIdentifier::class))); // @phpstan-ignore-line
3247
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
3348
$decorated->expects($this->once())->method('create')->with(DummyWithEnum::class, 'intEnumAsIdentifier')->willReturn($apiProperty);
3449
$schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
3550
$apiProperty = $schemaPropertyMetadataFactory->create(DummyWithEnum::class, 'intEnumAsIdentifier');
3651
$this->assertEquals(['type' => ['integer', 'null'], 'enum' => [1, 2, null]], $apiProperty->getSchema());
3752
}
3853

54+
#[IgnoreDeprecations]
55+
public function testWithCustomOpenApiContextLegacy(): void
56+
{
57+
$this->expectUserDeprecationMessage('Since api_platform/metadata 4.2: The "builtinTypes" argument of "ApiPlatform\Metadata\ApiProperty" is deprecated, use "nativeType" instead.');
58+
$resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
59+
$apiProperty = new ApiProperty(
60+
builtinTypes: [new LegacyType(builtinType: 'object', nullable: true, class: IntEnumAsIdentifier::class)],
61+
openapiContext: ['type' => 'object', 'properties' => ['alpha' => ['type' => 'integer']]],
62+
);
63+
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
64+
$decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'acme')->willReturn($apiProperty);
65+
$schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
66+
$apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'acme');
67+
$this->assertEquals([], $apiProperty->getSchema());
68+
}
69+
3970
public function testWithCustomOpenApiContext(): void
4071
{
4172
$resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
4273
$apiProperty = new ApiProperty(
43-
builtinTypes: [new Type(builtinType: 'object', nullable: true, class: IntEnumAsIdentifier::class)],
74+
nativeType: Type::nullable(Type::enum(IntEnumAsIdentifier::class)), // @phpstan-ignore-line
4475
openapiContext: ['type' => 'object', 'properties' => ['alpha' => ['type' => 'integer']]],
4576
);
4677
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
@@ -50,12 +81,43 @@ public function testWithCustomOpenApiContext(): void
5081
$this->assertEquals([], $apiProperty->getSchema());
5182
}
5283

84+
#[IgnoreDeprecations]
85+
public function testWithCustomOpenApiContextWithoutTypeDefinitionLegacy(): void
86+
{
87+
$this->expectUserDeprecationMessage('Since api_platform/metadata 4.2: The "builtinTypes" argument of "ApiPlatform\Metadata\ApiProperty" is deprecated, use "nativeType" instead.');
88+
$resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
89+
$apiProperty = new ApiProperty(
90+
openapiContext: ['description' => 'My description'],
91+
builtinTypes: [new LegacyType(builtinType: 'bool')],
92+
);
93+
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
94+
$decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'foo')->willReturn($apiProperty);
95+
$schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
96+
$apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'foo');
97+
$this->assertEquals([
98+
'type' => 'boolean',
99+
], $apiProperty->getSchema());
100+
101+
$apiProperty = new ApiProperty(
102+
openapiContext: ['iris' => 'https://schema.org/Date'],
103+
builtinTypes: [new LegacyType(builtinType: 'object', class: \DateTimeImmutable::class)],
104+
);
105+
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
106+
$decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'bar')->willReturn($apiProperty);
107+
$schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
108+
$apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'bar');
109+
$this->assertEquals([
110+
'type' => 'string',
111+
'format' => 'date-time',
112+
], $apiProperty->getSchema());
113+
}
114+
53115
public function testWithCustomOpenApiContextWithoutTypeDefinition(): void
54116
{
55117
$resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
56118
$apiProperty = new ApiProperty(
57119
openapiContext: ['description' => 'My description'],
58-
builtinTypes: [new Type(builtinType: 'bool')],
120+
nativeType: Type::bool(),
59121
);
60122
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
61123
$decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'foo')->willReturn($apiProperty);
@@ -67,7 +129,7 @@ public function testWithCustomOpenApiContextWithoutTypeDefinition(): void
67129

68130
$apiProperty = new ApiProperty(
69131
openapiContext: ['iris' => 'https://schema.org/Date'],
70-
builtinTypes: [new Type(builtinType: 'object', class: \DateTimeImmutable::class)],
132+
nativeType: Type::object(\DateTimeImmutable::class),
71133
);
72134
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
73135
$decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'bar')->willReturn($apiProperty);

0 commit comments

Comments
 (0)