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

api-platform / core / 14500959057

16 Apr 2025 07:29PM UTC coverage: 8.532% (+0.3%) from 8.189%
14500959057

push

github

web-flow
feat: Use `Type` of `TypeInfo` instead of `PropertyInfo` (#6979)

Co-authored-by: soyuka <soyuka@users.noreply.github.com>

scopes: metadata, doctrine, json-schema

300 of 616 new or added lines in 25 files covered. (48.7%)

285 existing lines in 18 files now uncovered.

13513 of 158381 relevant lines covered (8.53%)

22.97 hits per line

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

0.0
/src/Metadata/Tests/Util/PropertyInfoToTypeInfoHelperTest.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
/*
15
 * This file is part of the Symfony package.
16
 *
17
 * (c) Fabien Potencier <fabien@symfony.com>
18
 *
19
 * For the full copyright and license information, please view the LICENSE
20
 * file that was distributed with this source code.
21
 */
22

23
namespace ApiPlatform\Metadata\Tests\Util;
24

25
use ApiPlatform\Metadata\Util\PropertyInfoToTypeInfoHelper;
26
use PHPUnit\Framework\TestCase;
27
use Symfony\Component\PropertyInfo\Type as LegacyType;
28
use Symfony\Component\TypeInfo\Type;
29
use Symfony\Component\TypeInfo\TypeIdentifier;
30

31
class PropertyInfoToTypeInfoHelperTest extends TestCase
32
{
33
    /**
34
     * @param list<LegacyType>|null $legacyTypes
35
     */
36
    #[\PHPUnit\Framework\Attributes\DataProvider('convertLegacyTypesToTypeDataProvider')]
37
    public function testConvertLegacyTypesToType(?Type $type, ?array $legacyTypes): void
38
    {
39
        $this->assertEquals($type, PropertyInfoToTypeInfoHelper::convertLegacyTypesToType($legacyTypes));
×
40
    }
41

42
    /**
43
     * @return iterable<array{0: ?Type, 1: list<LegacyType>|null}>
44
     */
45
    public static function convertLegacyTypesToTypeDataProvider(): iterable
46
    {
47
        yield [null, null];
×
48
        yield [Type::null(), [new LegacyType('null')]];
×
49
        // yield [Type::void(), [new LegacyType('void')]];
50
        yield [Type::int(), [new LegacyType('int')]];
×
51
        yield [Type::object(\stdClass::class), [new LegacyType('object', false, \stdClass::class)]];
×
52
        yield [
×
53
            Type::generic(Type::object('Foo'), Type::string(), Type::int()), // @phpstan-ignore-line
×
54
            [new LegacyType('object', false, 'Foo', false, [new LegacyType('string')], new LegacyType('int'))],
×
55
        ];
×
56
        yield [Type::nullable(Type::int()), [new LegacyType('int', true)]]; // @phpstan-ignore-line
×
57
        yield [Type::union(Type::int(), Type::string()), [new LegacyType('int'), new LegacyType('string')]];
×
58
        yield [
×
59
            Type::union(Type::int(), Type::string(), Type::null()),
×
60
            [new LegacyType('int', true), new LegacyType('string', true)],
×
61
        ];
×
62

63
        $type = Type::collection(Type::builtin(TypeIdentifier::ARRAY), Type::int(), Type::string()); // @phpstan-ignore-line
×
64
        yield [$type, [new LegacyType('array', false, null, true, [new LegacyType('string')], new LegacyType('int'))]];
×
65
    }
66

67
    /**
68
     * @param list<LegacyType>|null $legacyTypes
69
     */
70
    #[\PHPUnit\Framework\Attributes\DataProvider('convertTypeToLegacyTypesDataProvider')]
71
    public function testConvertTypeToLegacyTypes(?array $legacyTypes, ?Type $type): void
72
    {
NEW
73
        $this->assertEquals($legacyTypes, PropertyInfoToTypeInfoHelper::convertTypeToLegacyTypes($type));
×
74
    }
75

76
    /**
77
     * @return iterable<array{0: list<LegacyType>|null, 1: ?Type, 2?: bool}>
78
     */
79
    public static function convertTypeToLegacyTypesDataProvider(): iterable
80
    {
NEW
81
        yield [null, null];
×
NEW
82
        yield [null, Type::mixed()];
×
NEW
83
        yield [null, Type::never()];
×
NEW
84
        yield [[new LegacyType('null')], Type::null()];
×
NEW
85
        yield [[new LegacyType('null')], Type::void()];
×
NEW
86
        yield [[new LegacyType('int')], Type::int()];
×
NEW
87
        yield [[new LegacyType('object', false, \stdClass::class)], Type::object(\stdClass::class)];
×
NEW
88
        yield [
×
NEW
89
            [new LegacyType('object', false, \Traversable::class, true, null, new LegacyType('int'))],
×
NEW
90
            Type::generic(Type::object(\Traversable::class), Type::int()),
×
NEW
91
        ];
×
NEW
92
        yield [
×
NEW
93
            [new LegacyType('array', false, null, true, new LegacyType('int'), new LegacyType('string'))],
×
NEW
94
            Type::generic(Type::builtin(TypeIdentifier::ARRAY), Type::int(), Type::string()), // @phpstan-ignore-line
×
NEW
95
        ];
×
NEW
96
        yield [
×
NEW
97
            [new LegacyType('array', false, null, true, new LegacyType('int'), new LegacyType('string'))],
×
NEW
98
            Type::collection(Type::builtin(TypeIdentifier::ARRAY), Type::string(), Type::int()), // @phpstan-ignore-line
×
NEW
99
        ];
×
NEW
100
        yield [[new LegacyType('int', true)], Type::nullable(Type::int())]; // @phpstan-ignore-line
×
NEW
101
        yield [[new LegacyType('int'), new LegacyType('string')], Type::union(Type::int(), Type::string())];
×
NEW
102
        yield [
×
NEW
103
            [new LegacyType('int', true), new LegacyType('string', true)],
×
NEW
104
            Type::union(Type::int(), Type::string(), Type::null()),
×
NEW
105
        ];
×
NEW
106
        yield [[new LegacyType('object', false, \Stringable::class), new LegacyType('object', false, \Traversable::class)], Type::intersection(Type::object(\Traversable::class), Type::object(\Stringable::class))];
×
107
    }
108
}
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

© 2025 Coveralls, Inc