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

api-platform / core / 19171073905

07 Nov 2025 02:17PM UTC coverage: 0.0% (-24.3%) from 24.303%
19171073905

push

github

web-flow
feat(symfony): allow symfony makers namespace configuration (#7497)

0 of 19 new or added lines in 6 files covered. (0.0%)

14716 existing lines in 467 files now uncovered.

0 of 56762 relevant lines covered (0.0%)

0.0 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\DummyWithMixed;
20
use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithUnionTypeProperty;
21
use ApiPlatform\JsonSchema\Tests\Fixtures\Enum\IntEnumAsIdentifier;
22
use ApiPlatform\Metadata\ApiProperty;
23
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
24
use ApiPlatform\Metadata\ResourceClassResolverInterface;
25
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
26
use PHPUnit\Framework\TestCase;
27
use Symfony\Component\PropertyInfo\Type as LegacyType;
28
use Symfony\Component\TypeInfo\Type;
29

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

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

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

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

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

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

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

133
        $apiProperty =
×
134
            new ApiProperty(
×
135
                openapiContext: ['iris' => 'https://schema.org/Date'],
×
136
                nativeType: Type::object(\DateTimeImmutable::class),
×
137
            );
×
138
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
139
        $decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'bar')->willReturn($apiProperty);
×
140
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
141
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'bar');
×
142
        $this->assertEquals([
×
143
            'type' => 'string',
×
144
            'format' => 'date-time',
×
UNCOV
145
        ], $apiProperty->getSchema());
×
146
    }
147

148
    public function testUnionTypeAnyOfIsArray(): void
149
    {
150
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) { // @phpstan-ignore-line symfony/property-info 6.4 is still allowed and this may be true
×
UNCOV
151
            $this->markTestSkipped('This test only supports type-info component');
×
152
        }
153

154
        $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
×
155
        $apiProperty = new ApiProperty(nativeType: Type::union(Type::string(), Type::int()));
×
156
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
UNCOV
157
        $decorated->expects($this->once())->method('create')->with(DummyWithUnionTypeProperty::class, 'unionProperty')->willReturn($apiProperty);
×
158

159
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
UNCOV
160
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithUnionTypeProperty::class, 'unionProperty');
×
161

162
        $expectedSchema = [
×
163
            'anyOf' => [
×
164
                ['type' => 'integer'],
×
165
                ['type' => 'string'],
×
166
            ],
×
UNCOV
167
        ];
×
168

UNCOV
169
        $this->assertEquals($expectedSchema, $apiProperty->getSchema());
×
170
    }
171

172
    public function testMixed(): void
173
    {
UNCOV
174
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) { // @phpstan-ignore-line symfony/property-info 6.4 is still allowed and this may be true
×
UNCOV
175
            $this->markTestSkipped('This test only supports type-info component');
×
176
        }
177

UNCOV
178
        $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
×
UNCOV
179
        $apiProperty = new ApiProperty(nativeType: Type::mixed());
×
UNCOV
180
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
UNCOV
181
        $decorated->expects($this->once())->method('create')->with(DummyWithMixed::class, 'mixedProperty')->willReturn($apiProperty);
×
182

UNCOV
183
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
UNCOV
184
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithMixed::class, 'mixedProperty');
×
185

UNCOV
186
        $this->assertEquals([
×
UNCOV
187
            'type' => ['string', 'null'],
×
UNCOV
188
        ], $apiProperty->getSchema());
×
189

UNCOV
190
        $apiProperty = new ApiProperty(nativeType: Type::array(Type::mixed()));
×
UNCOV
191
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
UNCOV
192
        $decorated->expects($this->once())->method('create')->with(DummyWithMixed::class, 'mixedArrayProperty')->willReturn($apiProperty);
×
193

UNCOV
194
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
UNCOV
195
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithMixed::class, 'mixedArrayProperty');
×
196

UNCOV
197
        $this->assertEquals([
×
UNCOV
198
            'type' => 'array',
×
UNCOV
199
            'items' => [
×
UNCOV
200
                'type' => ['string', 'null'],
×
UNCOV
201
            ],
×
UNCOV
202
        ], $apiProperty->getSchema());
×
203
    }
204
}
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