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 ;
2525use PHPStan \Type \Doctrine \Descriptors \ReflectionDescriptor ;
2626use PHPStan \Type \Doctrine \Descriptors \SimpleArrayType ;
2727use PHPStan \Type \Doctrine \Descriptors \StringType ;
28+ use PHPStan \Type \Doctrine \Descriptors \Symfony \UuidTypeDescriptor as SymfonyUuidTypeDescriptor ;
29+ use PHPStan \Type \Doctrine \Descriptors \Symfony \UlidTypeDescriptor as SymfonyUlidTypeDescriptor ;
2830use PHPStan \Type \Doctrine \ObjectMetadataResolver ;
2931use function array_unshift ;
3032use function class_exists ;
@@ -41,16 +43,51 @@ class EntityColumnRuleTest extends RuleTestCase
4143
4244 private ?string $ objectManagerLoader = null ;
4345
46+ private bool $ useSymfonyUuid = false ;
47+
4448 protected function getRule (): Rule
4549 {
50+ $ descriptors = [
51+ new ArrayType (),
52+ new BigIntType (),
53+ new BinaryType (),
54+ new DateTimeImmutableType (),
55+ new DateTimeType (),
56+ new DateType (),
57+ new DecimalType (new DriverDetector ()),
58+ new JsonType (),
59+ new IntegerType (),
60+ new StringType (),
61+ new SimpleArrayType (),
62+ new EnumType (),
63+ new ReflectionDescriptor (CarbonImmutableType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
64+ new ReflectionDescriptor (CarbonType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
65+ new ReflectionDescriptor (CustomType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
66+ new ReflectionDescriptor (CustomNumericType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
67+ ];
68+
4669 if (!Type::hasType (CustomType::NAME )) {
4770 Type::addType (CustomType::NAME , CustomType::class);
4871 }
4972 if (!Type::hasType (CustomNumericType::NAME )) {
5073 Type::addType (CustomNumericType::NAME , CustomNumericType::class);
5174 }
52- if (!Type::hasType (FakeTestingUuidType::NAME )) {
53- Type::addType (FakeTestingUuidType::NAME , FakeTestingUuidType::class);
75+ if ($ this ->useSymfonyUuid ) {
76+ if (!Type::hasType (FakeTestingSymfonyUuidType::NAME )) {
77+ Type::addType (FakeTestingSymfonyUuidType::NAME , FakeTestingSymfonyUuidType::class);
78+ }
79+ $ descriptors [] = new SymfonyUuidTypeDescriptor (FakeTestingSymfonyUuidType::class);
80+
81+ if (!Type::hasType (FakeTestingSymfonyUlidType::NAME )) {
82+ Type::addType (FakeTestingSymfonyUlidType::NAME , FakeTestingSymfonyUlidType::class);
83+ }
84+ $ descriptors [] = new SymfonyUlidTypeDescriptor (FakeTestingSymfonyUlidType::class);
85+ } else {
86+ if (!Type::hasType (FakeTestingRamseyUuidType::NAME )) {
87+ Type::addType (FakeTestingRamseyUuidType::NAME , FakeTestingRamseyUuidType::class);
88+ }
89+
90+ $ descriptors [] = new RamseyUuidTypeDescriptor (FakeTestingRamseyUuidType::class);
5491 }
5592 if (!Type::hasType ('carbon ' )) {
5693 Type::addType ('carbon ' , CarbonType::class);
@@ -64,25 +101,7 @@ protected function getRule(): Rule
64101
65102 return new EntityColumnRule (
66103 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- ]),
104+ new DefaultDescriptorRegistry ($ descriptors ),
86105 $ this ->createReflectionProvider (),
87106 true ,
88107 $ this ->allowNullablePropertyForRequiredField ,
@@ -461,6 +480,27 @@ public function testBug677(?string $objectManagerLoader): void
461480 $ this ->analyse ([__DIR__ . '/data/bug-677.php ' ], []);
462481 }
463482
483+ /**
484+ * @dataProvider dataObjectManagerLoader
485+ */
486+ public function testSymfonyUuid (?string $ objectManagerLoader ): void
487+ {
488+ $ this ->allowNullablePropertyForRequiredField = true ;
489+ $ this ->objectManagerLoader = $ objectManagerLoader ;
490+ $ this ->useSymfonyUuid = true ;
491+
492+ $ this ->analyse ([__DIR__ . '/data/EntityWithSymfonyUid.php ' ], [
493+ [
494+ 'Property PHPStan\Rules\Doctrine\ORM\EntityWithSymfonyUid::$uuidInvalidType type mapping mismatch: database can contain Symfony\Component\Uid\Uuid but property expects string. ' ,
495+ 32 ,
496+ ],
497+ [
498+ 'Property PHPStan\Rules\Doctrine\ORM\EntityWithSymfonyUid::$ulidInvalidType type mapping mismatch: database can contain Symfony\Component\Uid\Ulid but property expects string. ' ,
499+ 44 ,
500+ ],
501+ ]);
502+ }
503+
464504 /**
465505 * @dataProvider dataObjectManagerLoader
466506 */
0 commit comments