2121use PHPStan \Type \Doctrine \Descriptors \EnumType ;
2222use PHPStan \Type \Doctrine \Descriptors \IntegerType ;
2323use PHPStan \Type \Doctrine \Descriptors \JsonType ;
24- use PHPStan \Type \Doctrine \Descriptors \Ramsey \UuidTypeDescriptor ;
24+ use PHPStan \Type \Doctrine \Descriptors \Ramsey \UuidTypeDescriptor as RamseyUuidTypeDescriptor ;
25+ use PHPStan \Type \Doctrine \Descriptors \Symfony \UuidTypeDescriptor as SymfonyUuidTypeDescriptor ;
26+ use PHPStan \Type \Doctrine \Descriptors \Symfony \UlidTypeDescriptor as SymfonyUlidTypeDescriptor ;
2527use PHPStan \Type \Doctrine \Descriptors \ReflectionDescriptor ;
2628use PHPStan \Type \Doctrine \Descriptors \SimpleArrayType ;
2729use PHPStan \Type \Doctrine \Descriptors \StringType ;
2830use PHPStan \Type \Doctrine \ObjectMetadataResolver ;
31+
2932use function array_unshift ;
3033use function class_exists ;
3134use function strpos ;
@@ -41,16 +44,51 @@ class EntityColumnRuleTest extends RuleTestCase
4144
4245 private ?string $ objectManagerLoader = null ;
4346
47+ private bool $ useSymfonyUuid = false ;
48+
4449 protected function getRule (): Rule
4550 {
51+ $ descriptors = [
52+ new ArrayType (),
53+ new BigIntType (),
54+ new BinaryType (),
55+ new DateTimeImmutableType (),
56+ new DateTimeType (),
57+ new DateType (),
58+ new DecimalType (new DriverDetector ()),
59+ new JsonType (),
60+ new IntegerType (),
61+ new StringType (),
62+ new SimpleArrayType (),
63+ new EnumType (),
64+ new ReflectionDescriptor (CarbonImmutableType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
65+ new ReflectionDescriptor (CarbonType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
66+ new ReflectionDescriptor (CustomType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
67+ new ReflectionDescriptor (CustomNumericType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
68+ ];
69+
4670 if (!Type::hasType (CustomType::NAME )) {
4771 Type::addType (CustomType::NAME , CustomType::class);
4872 }
4973 if (!Type::hasType (CustomNumericType::NAME )) {
5074 Type::addType (CustomNumericType::NAME , CustomNumericType::class);
5175 }
52- if (!Type::hasType (FakeTestingUuidType::NAME )) {
53- Type::addType (FakeTestingUuidType::NAME , FakeTestingUuidType::class);
76+ if ($ this ->useSymfonyUuid ) {
77+ if (!Type::hasType (FakeTestingSymfonyUuidType::NAME )) {
78+ Type::addType (FakeTestingSymfonyUuidType::NAME , FakeTestingSymfonyUuidType::class);
79+ }
80+ $ descriptors [] = new SymfonyUuidTypeDescriptor (FakeTestingSymfonyUuidType::class);
81+
82+ if (!Type::hasType (FakeTestingSymfonyUlidType::NAME )) {
83+ Type::addType (FakeTestingSymfonyUlidType::NAME , FakeTestingSymfonyUlidType::class);
84+ }
85+ $ descriptors [] = new SymfonyUlidTypeDescriptor (FakeTestingSymfonyUlidType::class);
86+ } else {
87+ if (!Type::hasType (FakeTestingRamseyUuidType::NAME )) {
88+ Type::addType (FakeTestingRamseyUuidType::NAME , FakeTestingRamseyUuidType::class);
89+ }
90+
91+ $ descriptors [] = new RamseyUuidTypeDescriptor (FakeTestingRamseyUuidType::class);
5492 }
5593 if (!Type::hasType ('carbon ' )) {
5694 Type::addType ('carbon ' , CarbonType::class);
@@ -64,25 +102,7 @@ protected function getRule(): Rule
64102
65103 return new EntityColumnRule (
66104 new ObjectMetadataResolver ($ this ->objectManagerLoader , __DIR__ . '/../../../../tmp ' ),
67- new DefaultDescriptorRegistry ([
68- new ArrayType (),
69- new BigIntType (),
70- new BinaryType (),
71- new DateTimeImmutableType (),
72- new DateTimeType (),
73- new DateType (),
74- new DecimalType (new DriverDetector ()),
75- new JsonType (),
76- new IntegerType (),
77- new StringType (),
78- new SimpleArrayType (),
79- new UuidTypeDescriptor (FakeTestingUuidType::class),
80- new EnumType (),
81- new ReflectionDescriptor (CarbonImmutableType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
82- new ReflectionDescriptor (CarbonType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
83- new ReflectionDescriptor (CustomType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
84- new ReflectionDescriptor (CustomNumericType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
85- ]),
105+ new DefaultDescriptorRegistry ($ descriptors ),
86106 $ this ->createReflectionProvider (),
87107 true ,
88108 $ this ->allowNullablePropertyForRequiredField ,
@@ -461,6 +481,18 @@ public function testBug677(?string $objectManagerLoader): void
461481 $ this ->analyse ([__DIR__ . '/data/bug-677.php ' ], []);
462482 }
463483
484+ /**
485+ * @dataProvider dataObjectManagerLoader
486+ */
487+ public function testSymfonyUuid (?string $ objectManagerLoader ): void
488+ {
489+ $ this ->allowNullablePropertyForRequiredField = true ;
490+ $ this ->objectManagerLoader = $ objectManagerLoader ;
491+ $ this ->useSymfonyUuid = true ;
492+
493+ $ this ->analyse ([__DIR__ . '/data/EntityWithSymfonyUid.php ' ], []);
494+ }
495+
464496 /**
465497 * @dataProvider dataObjectManagerLoader
466498 */
0 commit comments