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

api-platform / core / 13203378522

07 Feb 2025 03:56PM UTC coverage: 8.501% (+0.7%) from 7.837%
13203378522

push

github

soyuka
Merge 4.1

111 of 490 new or added lines in 51 files covered. (22.65%)

5590 existing lines in 163 files now uncovered.

13345 of 156987 relevant lines covered (8.5%)

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\TestCase;
24
use Symfony\Component\PropertyInfo\Type;
25

26
class SchemaPropertyMetadataFactoryTest extends TestCase
27
{
28
    public function testEnum(): void
29
    {
30
        $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
×
31
        $apiProperty = new ApiProperty(builtinTypes: [new Type(builtinType: 'object', nullable: true, class: IntEnumAsIdentifier::class)]);
×
32
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
33
        $decorated->expects($this->once())->method('create')->with(DummyWithEnum::class, 'intEnumAsIdentifier')->willReturn($apiProperty);
×
34
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
35
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithEnum::class, 'intEnumAsIdentifier');
×
36
        $this->assertEquals(['type' => ['integer', 'null'], 'enum' => [1, 2, null]], $apiProperty->getSchema());
×
37
    }
38

39
    public function testWithCustomOpenApiContext(): void
40
    {
41
        $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
×
42
        $apiProperty = new ApiProperty(
×
43
            builtinTypes: [new Type(builtinType: 'object', nullable: true, class: IntEnumAsIdentifier::class)],
×
44
            openapiContext: ['type' => 'object', 'properties' => ['alpha' => ['type' => 'integer']]],
×
45
        );
×
46
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
47
        $decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'acme')->willReturn($apiProperty);
×
48
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
49
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'acme');
×
50
        $this->assertEquals([], $apiProperty->getSchema());
×
51
    }
52

53
    public function testWithCustomOpenApiContextWithoutTypeDefinition(): void
54
    {
UNCOV
55
        $resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
×
UNCOV
56
        $apiProperty = new ApiProperty(
×
UNCOV
57
            openapiContext: ['description' => 'My description'],
×
UNCOV
58
            builtinTypes: [new Type(builtinType: 'bool')],
×
UNCOV
59
        );
×
UNCOV
60
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
UNCOV
61
        $decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'foo')->willReturn($apiProperty);
×
UNCOV
62
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
UNCOV
63
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'foo');
×
UNCOV
64
        $this->assertEquals([
×
UNCOV
65
            'type' => 'boolean',
×
UNCOV
66
        ], $apiProperty->getSchema());
×
67

UNCOV
68
        $apiProperty = new ApiProperty(
×
UNCOV
69
            openapiContext: ['iris' => 'https://schema.org/Date'],
×
UNCOV
70
            builtinTypes: [new Type(builtinType: 'object', class: \DateTimeImmutable::class)],
×
UNCOV
71
        );
×
UNCOV
72
        $decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
×
UNCOV
73
        $decorated->expects($this->once())->method('create')->with(DummyWithCustomOpenApiContext::class, 'bar')->willReturn($apiProperty);
×
UNCOV
74
        $schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
×
UNCOV
75
        $apiProperty = $schemaPropertyMetadataFactory->create(DummyWithCustomOpenApiContext::class, 'bar');
×
UNCOV
76
        $this->assertEquals([
×
UNCOV
77
            'type' => 'string',
×
UNCOV
78
            'format' => 'date-time',
×
UNCOV
79
        ], $apiProperty->getSchema());
×
80
    }
81
}
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