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