|
29 | 29 | use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded;
|
30 | 30 | use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\EnumInt;
|
31 | 31 | use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\EnumString;
|
32 |
| -use Symfony\Component\PropertyInfo\Type; |
| 32 | +use Symfony\Component\TypeInfo\Type; |
33 | 33 |
|
34 | 34 | /**
|
35 | 35 | * @author Kévin Dunglas <[email protected]>
|
@@ -106,134 +106,70 @@ public function testTestGetPropertiesWithEmbedded()
|
106 | 106 | }
|
107 | 107 |
|
108 | 108 | /**
|
109 |
| - * @dataProvider typesProvider |
| 109 | + * @dataProvider typeProvider |
110 | 110 | */
|
111 |
| - public function testExtract(string $property, array $type = null) |
| 111 | + public function testExtract(string $property, ?Type $type) |
112 | 112 | {
|
113 |
| - $this->assertEquals($type, $this->createExtractor()->getTypes(DoctrineDummy::class, $property, [])); |
| 113 | + $this->assertEquals($type, $this->createExtractor()->getType(DoctrineDummy::class, $property, [])); |
114 | 114 | }
|
115 | 115 |
|
116 | 116 | public function testExtractWithEmbedded()
|
117 | 117 | {
|
118 |
| - $expectedTypes = [new Type( |
119 |
| - Type::BUILTIN_TYPE_OBJECT, |
120 |
| - false, |
121 |
| - DoctrineEmbeddable::class |
122 |
| - )]; |
123 |
| - |
124 |
| - $actualTypes = $this->createExtractor()->getTypes( |
125 |
| - DoctrineWithEmbedded::class, |
126 |
| - 'embedded', |
127 |
| - [] |
| 118 | + $this->assertEquals( |
| 119 | + Type::object(DoctrineEmbeddable::class), |
| 120 | + $this->createExtractor()->getType(DoctrineWithEmbedded::class, 'embedded'), |
128 | 121 | );
|
129 |
| - |
130 |
| - $this->assertEquals($expectedTypes, $actualTypes); |
131 | 122 | }
|
132 | 123 |
|
133 | 124 | public function testExtractEnum()
|
134 | 125 | {
|
135 |
| - $this->assertEquals([new Type(Type::BUILTIN_TYPE_OBJECT, false, EnumString::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumString', [])); |
136 |
| - $this->assertEquals([new Type(Type::BUILTIN_TYPE_OBJECT, false, EnumInt::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumInt', [])); |
137 |
| - $this->assertNull($this->createExtractor()->getTypes(DoctrineEnum::class, 'enumStringArray', [])); |
138 |
| - $this->assertEquals([new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, EnumInt::class))], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumIntArray', [])); |
139 |
| - $this->assertNull($this->createExtractor()->getTypes(DoctrineEnum::class, 'enumCustom', [])); |
| 126 | + $this->assertEquals(Type::enum(EnumString::class), $this->createExtractor()->getType(DoctrineEnum::class, 'enumString')); |
| 127 | + $this->assertEquals(Type::enum(EnumInt::class), $this->createExtractor()->getType(DoctrineEnum::class, 'enumInt')); |
| 128 | + $this->assertNull($this->createExtractor()->getType(DoctrineEnum::class, 'enumStringArray')); |
| 129 | + $this->assertEquals(Type::list(Type::enum(EnumInt::class)), $this->createExtractor()->getType(DoctrineEnum::class, 'enumIntArray')); |
| 130 | + $this->assertNull($this->createExtractor()->getType(DoctrineEnum::class, 'enumCustom')); |
140 | 131 | }
|
141 | 132 |
|
142 |
| - public static function typesProvider(): array |
| 133 | + /** |
| 134 | + * @return iterable<array{0: string, 1: ?Type}> |
| 135 | + */ |
| 136 | + public static function typeProvider(): iterable |
143 | 137 | {
|
144 |
| - return [ |
145 |
| - ['id', [new Type(Type::BUILTIN_TYPE_INT)]], |
146 |
| - ['guid', [new Type(Type::BUILTIN_TYPE_STRING)]], |
147 |
| - ['bigint', [new Type(Type::BUILTIN_TYPE_STRING)]], |
148 |
| - ['time', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')]], |
149 |
| - ['timeImmutable', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTimeImmutable')]], |
150 |
| - ['dateInterval', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateInterval')]], |
151 |
| - ['float', [new Type(Type::BUILTIN_TYPE_FLOAT)]], |
152 |
| - ['decimal', [new Type(Type::BUILTIN_TYPE_STRING)]], |
153 |
| - ['bool', [new Type(Type::BUILTIN_TYPE_BOOL)]], |
154 |
| - ['binary', [new Type(Type::BUILTIN_TYPE_RESOURCE)]], |
155 |
| - ['jsonArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)]], |
156 |
| - ['foo', [new Type(Type::BUILTIN_TYPE_OBJECT, true, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')]], |
157 |
| - ['bar', [new Type( |
158 |
| - Type::BUILTIN_TYPE_OBJECT, |
159 |
| - false, |
160 |
| - 'Doctrine\Common\Collections\Collection', |
161 |
| - true, |
162 |
| - new Type(Type::BUILTIN_TYPE_INT), |
163 |
| - new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation') |
164 |
| - )]], |
165 |
| - ['indexedRguid', [new Type( |
166 |
| - Type::BUILTIN_TYPE_OBJECT, |
167 |
| - false, |
168 |
| - 'Doctrine\Common\Collections\Collection', |
169 |
| - true, |
170 |
| - new Type(Type::BUILTIN_TYPE_STRING), |
171 |
| - new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation') |
172 |
| - )]], |
173 |
| - ['indexedBar', [new Type( |
174 |
| - Type::BUILTIN_TYPE_OBJECT, |
175 |
| - false, |
176 |
| - 'Doctrine\Common\Collections\Collection', |
177 |
| - true, |
178 |
| - new Type(Type::BUILTIN_TYPE_STRING), |
179 |
| - new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation') |
180 |
| - )]], |
181 |
| - ['indexedFoo', [new Type( |
182 |
| - Type::BUILTIN_TYPE_OBJECT, |
183 |
| - false, |
184 |
| - 'Doctrine\Common\Collections\Collection', |
185 |
| - true, |
186 |
| - new Type(Type::BUILTIN_TYPE_STRING), |
187 |
| - new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation') |
188 |
| - )]], |
189 |
| - ['indexedBaz', [new Type( |
190 |
| - Type::BUILTIN_TYPE_OBJECT, |
191 |
| - false, |
192 |
| - Collection::class, |
193 |
| - true, |
194 |
| - new Type(Type::BUILTIN_TYPE_INT), |
195 |
| - new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class) |
196 |
| - )]], |
197 |
| - ['simpleArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]], |
198 |
| - ['customFoo', null], |
199 |
| - ['notMapped', null], |
200 |
| - ['indexedByDt', [new Type( |
201 |
| - Type::BUILTIN_TYPE_OBJECT, |
202 |
| - false, |
203 |
| - Collection::class, |
204 |
| - true, |
205 |
| - new Type(Type::BUILTIN_TYPE_OBJECT), |
206 |
| - new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class) |
207 |
| - )]], |
208 |
| - ['indexedByCustomType', null], |
209 |
| - ['indexedBuz', [new Type( |
210 |
| - Type::BUILTIN_TYPE_OBJECT, |
211 |
| - false, |
212 |
| - Collection::class, |
213 |
| - true, |
214 |
| - new Type(Type::BUILTIN_TYPE_STRING), |
215 |
| - new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class) |
216 |
| - )]], |
217 |
| - ['dummyGeneratedValueList', [new Type( |
218 |
| - Type::BUILTIN_TYPE_OBJECT, |
219 |
| - false, |
220 |
| - 'Doctrine\Common\Collections\Collection', |
221 |
| - true, |
222 |
| - new Type(Type::BUILTIN_TYPE_INT), |
223 |
| - new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class) |
224 |
| - )]], |
225 |
| - ['json', null], |
226 |
| - ]; |
| 138 | + yield ['id', Type::int()]; |
| 139 | + yield ['guid', Type::string()]; |
| 140 | + yield ['bigint', Type::string()]; |
| 141 | + yield ['time', Type::object(\DateTime::class)]; |
| 142 | + yield ['timeImmutable', Type::object(\DateTimeImmutable::class)]; |
| 143 | + yield ['dateInterval', Type::object(\DateInterval::class)]; |
| 144 | + yield ['float', Type::float()]; |
| 145 | + yield ['decimal', Type::string()]; |
| 146 | + yield ['bool', Type::bool()]; |
| 147 | + yield ['binary', Type::resource()]; |
| 148 | + yield ['jsonArray', Type::array()]; |
| 149 | + yield ['foo', Type::nullable(Type::object(DoctrineRelation::class))]; |
| 150 | + yield ['bar', Type::collection(Type::object(Collection::class), Type::object(DoctrineRelation::class), Type::int())]; |
| 151 | + yield ['indexedRguid', Type::collection(Type::object(Collection::class), Type::object(DoctrineRelation::class), Type::string())]; |
| 152 | + yield ['indexedBar', Type::collection(Type::object(Collection::class), Type::object(DoctrineRelation::class), Type::string())]; |
| 153 | + yield ['indexedFoo', Type::collection(Type::object(Collection::class), Type::object(DoctrineRelation::class), Type::string())]; |
| 154 | + yield ['indexedBaz', Type::collection(Type::object(Collection::class), Type::object(DoctrineRelation::class), Type::int())]; |
| 155 | + yield ['simpleArray', Type::list(Type::string())]; |
| 156 | + yield ['customFoo', null]; |
| 157 | + yield ['notMapped', null]; |
| 158 | + yield ['indexedByDt', Type::collection(Type::object(Collection::class), Type::object(DoctrineRelation::class), Type::object())]; |
| 159 | + yield ['indexedByCustomType', null]; |
| 160 | + yield ['indexedBuz', Type::collection(Type::object(Collection::class), Type::object(DoctrineRelation::class), Type::string())]; |
| 161 | + yield ['dummyGeneratedValueList', Type::collection(Type::object(Collection::class), Type::object(DoctrineRelation::class), Type::int())]; |
| 162 | + yield ['json', null]; |
227 | 163 | }
|
228 | 164 |
|
229 | 165 | public function testGetPropertiesCatchException()
|
230 | 166 | {
|
231 | 167 | $this->assertNull($this->createExtractor()->getProperties('Not\Exist'));
|
232 | 168 | }
|
233 | 169 |
|
234 |
| - public function testGetTypesCatchException() |
| 170 | + public function testGetTypeCatchException() |
235 | 171 | {
|
236 |
| - $this->assertNull($this->createExtractor()->getTypes('Not\Exist', 'baz')); |
| 172 | + $this->assertNull($this->createExtractor()->getType('Not\Exist', 'baz')); |
237 | 173 | }
|
238 | 174 |
|
239 | 175 | public function testGeneratedValueNotWritable()
|
|
0 commit comments