File: PropertyInfoCacheExtractorTest.php

package info (click to toggle)
symfony 7.3.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 147,804 kB
  • sloc: php: 1,506,509; xml: 6,816; javascript: 1,043; sh: 586; makefile: 241; pascal: 70
file content (171 lines) | stat: -rw-r--r-- 6,805 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\PropertyInfo\Tests;

use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoCacheExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
use Symfony\Component\TypeInfo\Type;

/**
 * @author Kévin Dunglas <dunglas@gmail.com>
 */
class PropertyInfoCacheExtractorTest extends AbstractPropertyInfoExtractorTest
{
    use ExpectUserDeprecationMessageTrait;

    protected function setUp(): void
    {
        parent::setUp();

        $this->propertyInfo = new PropertyInfoCacheExtractor($this->propertyInfo, new ArrayAdapter());
    }

    public function testGetShortDescription()
    {
        parent::testGetShortDescription();
        parent::testGetShortDescription();
    }

    public function testGetLongDescription()
    {
        parent::testGetLongDescription();
        parent::testGetLongDescription();
    }

    public function testGetType()
    {
        parent::testGetType();
        parent::testGetType();
    }

    #[\PHPUnit\Framework\Attributes\Group('legacy')]
    public function testGetTypes()
    {
        $this->expectUserDeprecationMessage('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\PropertyInfoCacheExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\PropertyInfoCacheExtractor::getType()" instead.');

        parent::testGetTypes();
        parent::testGetTypes();
    }

    public function testIsReadable()
    {
        parent::testIsReadable();
        parent::testIsReadable();
    }

    public function testIsWritable()
    {
        parent::testIsWritable();
        parent::testIsWritable();
    }

    public function testGetProperties()
    {
        parent::testGetProperties();
        parent::testGetProperties();
    }

    public function testIsInitializable()
    {
        parent::testIsInitializable();
        parent::testIsInitializable();
    }

    #[\PHPUnit\Framework\Attributes\DataProvider('provideNestedExtractorWithoutGetTypeImplementationData')]
    #[\PHPUnit\Framework\Attributes\Group('legacy')]
    public function testNestedExtractorWithoutGetTypeImplementation(string $property, ?Type $expectedType)
    {
        $propertyInfoCacheExtractor = new PropertyInfoCacheExtractor(new class implements PropertyInfoExtractorInterface {
            private PropertyTypeExtractorInterface $propertyTypeExtractor;

            public function __construct()
            {
                $this->propertyTypeExtractor = new PhpDocExtractor();
            }

            public function getTypes(string $class, string $property, array $context = []): ?array
            {
                return $this->propertyTypeExtractor->getTypes($class, $property, $context);
            }

            public function isReadable(string $class, string $property, array $context = []): ?bool
            {
                return null;
            }

            public function isWritable(string $class, string $property, array $context = []): ?bool
            {
                return null;
            }

            public function getShortDescription(string $class, string $property, array $context = []): ?string
            {
                return null;
            }

            public function getLongDescription(string $class, string $property, array $context = []): ?string
            {
                return null;
            }

            public function getProperties(string $class, array $context = []): ?array
            {
                return null;
            }
        }, new ArrayAdapter());

        if (null === $expectedType) {
            $this->assertNull($propertyInfoCacheExtractor->getType(Dummy::class, $property));
        } else {
            $this->assertEquals($expectedType, $propertyInfoCacheExtractor->getType(Dummy::class, $property));
        }
    }

    public static function provideNestedExtractorWithoutGetTypeImplementationData()
    {
        yield ['bar', Type::string()];
        yield ['baz', Type::int()];
        yield ['bal', Type::object(\DateTimeImmutable::class)];
        yield ['parent', Type::object(ParentDummy::class)];
        yield ['collection', Type::array(Type::object(\DateTimeImmutable::class), Type::int())];
        yield ['nestedCollection', Type::array(Type::array(Type::string(), Type::int()), Type::int())];
        yield ['mixedCollection', Type::array()];
        yield ['B', Type::object(ParentDummy::class)];
        yield ['Id', Type::int()];
        yield ['Guid', Type::string()];
        yield ['g', Type::nullable(Type::array())];
        yield ['h', Type::nullable(Type::string())];
        yield ['i', Type::nullable(Type::union(Type::string(), Type::int()))];
        yield ['j', Type::nullable(Type::object(\DateTimeImmutable::class))];
        yield ['nullableCollectionOfNonNullableElements', Type::nullable(Type::array(Type::int(), Type::int()))];
        yield ['nonNullableCollectionOfNullableElements', Type::array(Type::nullable(Type::int()), Type::int())];
        yield ['nullableCollectionOfMultipleNonNullableElementTypes', Type::nullable(Type::array(Type::union(Type::int(), Type::string()), Type::int()))];
        yield ['xTotals', Type::array()];
        yield ['YT', Type::string()];
        yield ['emptyVar', null];
        yield ['iteratorCollection', Type::collection(Type::object(\Iterator::class), Type::string(), Type::union(Type::string(), Type::int()))];
        yield ['iteratorCollectionWithKey', Type::collection(Type::object(\Iterator::class), Type::string(), Type::int())];
        yield ['nestedIterators', Type::collection(Type::object(\Iterator::class), Type::collection(Type::object(\Iterator::class), Type::string(), Type::int()), Type::int())];
        yield ['arrayWithKeys', Type::array(Type::string(), Type::string())];
        yield ['arrayWithKeysAndComplexValue', Type::array(Type::nullable(Type::array(Type::nullable(Type::string()), Type::int())), Type::string())];
        yield ['arrayOfMixed', Type::array(Type::mixed(), Type::string())];
        yield ['noDocBlock', null];
        yield ['listOfStrings', Type::array(Type::string(), Type::int())];
        yield ['parentAnnotation', Type::object(ParentDummy::class)];
    }
}