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

api-platform / core / 14980015570

12 May 2025 06:41PM UTC coverage: 26.309% (+2.6%) from 23.685%
14980015570

Pull #7140

github

web-flow
Merge 1e6b14143 into 202c60fcb
Pull Request #7140: Fix: PHPize HTTP cache headers

0 of 1 new or added line in 1 file covered. (0.0%)

4614 existing lines in 185 files now uncovered.

13550 of 51504 relevant lines covered (26.31%)

71.73 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
    {
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);
×
UNCOV
37
        $decorated->expects($this->once())->method('create')->with(DummyWithEnum::class, 'intEnumAsIdentifier')->willReturn($apiProperty);
×
UNCOV
38
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
UNCOV
39
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithEnum::class, 'intEnumAsIdentifier');
×
UNCOV
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);
×
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');
×
UNCOV
51
        $this->assertEquals(['type' => ['integer', 'null'], 'enum' => [1, 2, null]], $apiProperty->getSchema());
×
52
    }
53

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');
×
UNCOV
67
        $this->assertEquals([], $apiProperty->getSchema());
×
68
    }
69

70
    public function testWithCustomOpenApiContext(): void
71
    {
72
        $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
×
73
        $apiProperty = new ApiProperty(
×
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);
×
UNCOV
80
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'acme');
×
UNCOV
81
        $this->assertEquals([], $apiProperty->getSchema());
×
82
    }
83

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

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

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

UNCOV
130
        $apiProperty = new ApiProperty(
×
UNCOV
131
            openapiContext: ['iris' => 'https://schema.org/Date'],
×
UNCOV
132
            nativeType: Type::object(\DateTimeImmutable::class),
×
UNCOV
133
        );
×
UNCOV
134
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
UNCOV
135
        $decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'bar')->willReturn($apiProperty);
×
UNCOV
136
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
UNCOV
137
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'bar');
×
UNCOV
138
        $this->assertEquals([
×
UNCOV
139
            'type' => 'string',
×
UNCOV
140
            'format' => 'date-time',
×
UNCOV
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