21
21
use PHPStan \Type \Doctrine \Descriptors \EnumType ;
22
22
use PHPStan \Type \Doctrine \Descriptors \IntegerType ;
23
23
use PHPStan \Type \Doctrine \Descriptors \JsonType ;
24
- use PHPStan \Type \Doctrine \Descriptors \Ramsey \UuidTypeDescriptor ;
24
+ use PHPStan \Type \Doctrine \Descriptors \Ramsey \UuidTypeDescriptor as RamseyUuidTypeDescriptor ;
25
25
use PHPStan \Type \Doctrine \Descriptors \ReflectionDescriptor ;
26
26
use PHPStan \Type \Doctrine \Descriptors \SimpleArrayType ;
27
27
use PHPStan \Type \Doctrine \Descriptors \StringType ;
28
+ use PHPStan \Type \Doctrine \Descriptors \Symfony \UlidTypeDescriptor as SymfonyUlidTypeDescriptor ;
29
+ use PHPStan \Type \Doctrine \Descriptors \Symfony \UuidTypeDescriptor as SymfonyUuidTypeDescriptor ;
28
30
use PHPStan \Type \Doctrine \ObjectMetadataResolver ;
29
31
use function array_unshift ;
30
32
use function class_exists ;
@@ -41,16 +43,51 @@ class EntityColumnRuleTest extends RuleTestCase
41
43
42
44
private ?string $ objectManagerLoader = null ;
43
45
46
+ private bool $ useSymfonyUuid = false ;
47
+
44
48
protected function getRule (): Rule
45
49
{
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
+
46
69
if (!Type::hasType (CustomType::NAME )) {
47
70
Type::addType (CustomType::NAME , CustomType::class);
48
71
}
49
72
if (!Type::hasType (CustomNumericType::NAME )) {
50
73
Type::addType (CustomNumericType::NAME , CustomNumericType::class);
51
74
}
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);
54
91
}
55
92
if (!Type::hasType ('carbon ' )) {
56
93
Type::addType ('carbon ' , CarbonType::class);
@@ -64,25 +101,7 @@ protected function getRule(): Rule
64
101
65
102
return new EntityColumnRule (
66
103
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 ),
86
105
$ this ->createReflectionProvider (),
87
106
true ,
88
107
$ this ->allowNullablePropertyForRequiredField ,
@@ -461,6 +480,27 @@ public function testBug677(?string $objectManagerLoader): void
461
480
$ this ->analyse ([__DIR__ . '/data/bug-677.php ' ], []);
462
481
}
463
482
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
+
464
504
/**
465
505
* @dataProvider dataObjectManagerLoader
466
506
*/
0 commit comments