• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 14836358929

05 May 2025 12:24PM UTC coverage: 8.396% (-15.0%) from 23.443%
14836358929

push

github

soyuka
test: property info deprecation

0 of 300 new or added lines in 4 files covered. (0.0%)

2655 existing lines in 165 files now uncovered.

13444 of 160118 relevant lines covered (8.4%)

22.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/JsonSchema/Tests/Metadata/Property/Factory/SchemaPropertyMetadataFactoryTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
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\JsonSchema\Tests\Metadata\Property\Factory;
15

16
use ApiPlatform\JsonSchema\Metadata\Property\Factory\SchemaPropertyMetadataFactory;
17
use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithCustomOpenApiContext;
18
use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithEnum;
19
use ApiPlatform\JsonSchema\Tests\Fixtures\Enum\IntEnumAsIdentifier;
20
use ApiPlatform\Metadata\ApiProperty;
21
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
22
use ApiPlatform\Metadata\ResourceClassResolverInterface;
23
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
24
use PHPUnit\Framework\TestCase;
25
use Symfony\Component\PropertyInfo\Type as LegacyType;
26
use Symfony\Component\TypeInfo\Type;
27

28
class SchemaPropertyMetadataFactoryTest extends TestCase
29
{
30
    #[IgnoreDeprecations]
31
    public function testEnumLegacy(): void
32
    {
NEW
33
        $this->expectUserDeprecationMessage('Since api_platform/metadata 4.2: The "builtinTypes" argument of "ApiPlatform\Metadata\ApiProperty" is deprecated, use "nativeType" instead.');
×
NEW
34
        $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
×
NEW
35
        $apiProperty = new ApiProperty(builtinTypes: [new LegacyType(builtinType: 'object', nullable: true, class: IntEnumAsIdentifier::class)]);
×
NEW
36
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
NEW
37
        $decorated->expects($this->once())->method('create')->with(DummyWithEnum::class, 'intEnumAsIdentifier')->willReturn($apiProperty);
×
NEW
38
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
NEW
39
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithEnum::class, 'intEnumAsIdentifier');
×
NEW
40
        $this->assertEquals(['type' => ['integer', 'null'], 'enum' => [1, 2, null]], $apiProperty->getSchema());
×
41
    }
42

43
    public function testEnum(): void
44
    {
45
        $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
×
NEW
46
        $apiProperty = new ApiProperty(nativeType: Type::nullable(Type::enum(IntEnumAsIdentifier::class))); // @phpstan-ignore-line
×
47
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
48
        $decorated->expects($this->once())->method('create')->with(DummyWithEnum::class, 'intEnumAsIdentifier')->willReturn($apiProperty);
×
49
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
50
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithEnum::class, 'intEnumAsIdentifier');
×
51
        $this->assertEquals(['type' => ['integer', 'null'], 'enum' => [1, 2, null]], $apiProperty->getSchema());
×
52
    }
53

54
    #[IgnoreDeprecations]
55
    public function testWithCustomOpenApiContextLegacy(): void
56
    {
NEW
57
        $this->expectUserDeprecationMessage('Since api_platform/metadata 4.2: The "builtinTypes" argument of "ApiPlatform\Metadata\ApiProperty" is deprecated, use "nativeType" instead.');
×
NEW
58
        $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
×
NEW
59
        $apiProperty = new ApiProperty(
×
NEW
60
            builtinTypes: [new LegacyType(builtinType: 'object', nullable: true, class: IntEnumAsIdentifier::class)],
×
NEW
61
            openapiContext: ['type' => 'object', 'properties' => ['alpha' => ['type' => 'integer']]],
×
NEW
62
        );
×
NEW
63
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
NEW
64
        $decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'acme')->willReturn($apiProperty);
×
NEW
65
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
NEW
66
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'acme');
×
NEW
67
        $this->assertEquals([], $apiProperty->getSchema());
×
68
    }
69

70
    public function testWithCustomOpenApiContext(): void
71
    {
72
        $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
×
73
        $apiProperty = new ApiProperty(
×
NEW
74
            nativeType: Type::nullable(Type::enum(IntEnumAsIdentifier::class)), // @phpstan-ignore-line
×
75
            openapiContext: ['type' => 'object', 'properties' => ['alpha' => ['type' => 'integer']]],
×
76
        );
×
77
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
78
        $decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'acme')->willReturn($apiProperty);
×
79
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
80
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'acme');
×
81
        $this->assertEquals([], $apiProperty->getSchema());
×
82
    }
83

84
    #[IgnoreDeprecations]
85
    public function testWithCustomOpenApiContextWithoutTypeDefinitionLegacy(): void
86
    {
NEW
87
        $this->expectUserDeprecationMessage('Since api_platform/metadata 4.2: The "builtinTypes" argument of "ApiPlatform\Metadata\ApiProperty" is deprecated, use "nativeType" instead.');
×
NEW
88
        $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
×
NEW
89
        $apiProperty = new ApiProperty(
×
NEW
90
            openapiContext: ['description' => 'My description'],
×
NEW
91
            builtinTypes: [new LegacyType(builtinType: 'bool')],
×
NEW
92
        );
×
NEW
93
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
NEW
94
        $decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'foo')->willReturn($apiProperty);
×
NEW
95
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
NEW
96
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'foo');
×
NEW
97
        $this->assertEquals([
×
NEW
98
            'type' => 'boolean',
×
NEW
99
        ], $apiProperty->getSchema());
×
100

NEW
101
        $apiProperty = new ApiProperty(
×
NEW
102
            openapiContext: ['iris' => 'https://schema.org/Date'],
×
NEW
103
            builtinTypes: [new LegacyType(builtinType: 'object', class: \DateTimeImmutable::class)],
×
NEW
104
        );
×
NEW
105
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
NEW
106
        $decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'bar')->willReturn($apiProperty);
×
NEW
107
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
NEW
108
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'bar');
×
NEW
109
        $this->assertEquals([
×
NEW
110
            'type' => 'string',
×
NEW
111
            'format' => 'date-time',
×
NEW
112
        ], $apiProperty->getSchema());
×
113
    }
114

115
    public function testWithCustomOpenApiContextWithoutTypeDefinition(): void
116
    {
117
        $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
×
118
        $apiProperty = new ApiProperty(
×
119
            openapiContext: ['description' => 'My description'],
×
NEW
120
            nativeType: Type::bool(),
×
121
        );
×
122
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
123
        $decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'foo')->willReturn($apiProperty);
×
124
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
125
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'foo');
×
126
        $this->assertEquals([
×
127
            'type' => 'boolean',
×
128
        ], $apiProperty->getSchema());
×
129

130
        $apiProperty = new ApiProperty(
×
131
            openapiContext: ['iris' => 'https://schema.org/Date'],
×
NEW
132
            nativeType: Type::object(\DateTimeImmutable::class),
×
133
        );
×
134
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
135
        $decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'bar')->willReturn($apiProperty);
×
136
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
137
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'bar');
×
138
        $this->assertEquals([
×
139
            'type' => 'string',
×
140
            'format' => 'date-time',
×
141
        ], $apiProperty->getSchema());
×
142
    }
143
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc