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

api-platform / core / 15928092811

27 Jun 2025 01:58PM UTC coverage: 21.793% (-0.2%) from 22.016%
15928092811

push

github

web-flow
chore: bump phpstan version (#7239)

8 of 29 new or added lines in 14 files covered. (27.59%)

126 existing lines in 12 files now uncovered.

11375 of 52196 relevant lines covered (21.79%)

10.71 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 [
×
NEW
53
            Type::generic(Type::object(\stdClass::class), Type::string(), Type::int()),
×
NEW
54
            [new LegacyType('object', false, 'stdClass', false, [new LegacyType('string')], new LegacyType('int'))],
×
55
        ];
×
NEW
56
        yield [Type::nullable(Type::int()), [new LegacyType('int', true)]];
×
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
    {
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
    {
81
        yield [null, null];
×
82
        yield [null, Type::mixed()];
×
83
        yield [null, Type::never()];
×
84
        yield [[new LegacyType('null')], Type::null()];
×
85
        yield [[new LegacyType('null')], Type::void()];
×
86
        yield [[new LegacyType('int')], Type::int()];
×
87
        yield [[new LegacyType('object', false, \stdClass::class)], Type::object(\stdClass::class)];
×
88
        yield [
×
89
            [new LegacyType('object', false, \Traversable::class, true, null, new LegacyType('int'))],
×
90
            Type::generic(Type::object(\Traversable::class), Type::int()),
×
91
        ];
×
92
        yield [
×
93
            [new LegacyType('array', false, null, true, new LegacyType('int'), new LegacyType('string'))],
×
94
            Type::generic(Type::builtin(TypeIdentifier::ARRAY), Type::int(), Type::string()), // @phpstan-ignore-line
×
95
        ];
×
96
        yield [
×
97
            [new LegacyType('array', false, null, true, new LegacyType('int'), new LegacyType('string'))],
×
98
            Type::collection(Type::builtin(TypeIdentifier::ARRAY), Type::string(), Type::int()), // @phpstan-ignore-line
×
99
        ];
×
NEW
100
        yield [[new LegacyType('int', true)], Type::nullable(Type::int())];
×
101
        yield [[new LegacyType('int'), new LegacyType('string')], Type::union(Type::int(), Type::string())];
×
102
        yield [
×
103
            [new LegacyType('int', true), new LegacyType('string', true)],
×
104
            Type::union(Type::int(), Type::string(), Type::null()),
×
105
        ];
×
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