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
+ use Rules \Doctrine \ORM \FakeTestingSymfonyUlidType ;
32
+ use Rules \Doctrine \ORM \FakeTestingSymfonyUuidType ;
33
+
29
34
use function array_unshift ;
30
35
use function class_exists ;
31
36
use function strpos ;
@@ -41,16 +46,51 @@ class EntityColumnRuleTest extends RuleTestCase
41
46
42
47
private ?string $ objectManagerLoader = null ;
43
48
49
+ private bool $ useSymfonyUuid = true ;
50
+
44
51
protected function getRule (): Rule
45
52
{
53
+ $ descriptors = [
54
+ new ArrayType (),
55
+ new BigIntType (),
56
+ new BinaryType (),
57
+ new DateTimeImmutableType (),
58
+ new DateTimeType (),
59
+ new DateType (),
60
+ new DecimalType (new DriverDetector ()),
61
+ new JsonType (),
62
+ new IntegerType (),
63
+ new StringType (),
64
+ new SimpleArrayType (),
65
+ new EnumType (),
66
+ new ReflectionDescriptor (CarbonImmutableType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
67
+ new ReflectionDescriptor (CarbonType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
68
+ new ReflectionDescriptor (CustomType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
69
+ new ReflectionDescriptor (CustomNumericType::class, $ this ->createReflectionProvider (), self ::getContainer ()),
70
+ ];
71
+
46
72
if (!Type::hasType (CustomType::NAME )) {
47
73
Type::addType (CustomType::NAME , CustomType::class);
48
74
}
49
75
if (!Type::hasType (CustomNumericType::NAME )) {
50
76
Type::addType (CustomNumericType::NAME , CustomNumericType::class);
51
77
}
52
- if (!Type::hasType (FakeTestingUuidType::NAME )) {
53
- Type::addType (FakeTestingUuidType::NAME , FakeTestingUuidType::class);
78
+ if ($ this ->useSymfonyUuid ) {
79
+ if (!Type::hasType (FakeTestingSymfonyUuidType::NAME )) {
80
+ Type::addType (FakeTestingSymfonyUuidType::NAME , FakeTestingSymfonyUuidType::class);
81
+ }
82
+ $ descriptors [] = new SymfonyUuidTypeDescriptor (FakeTestingSymfonyUuidType::class);
83
+
84
+ if (!Type::hasType (FakeTestingSymfonyUlidType::NAME )) {
85
+ Type::addType (FakeTestingSymfonyUlidType::NAME , FakeTestingSymfonyUlidType::class);
86
+ }
87
+ $ descriptors [] = new SymfonyUlidTypeDescriptor (FakeTestingSymfonyUlidType::class);
88
+ } else {
89
+ if (!Type::hasType (FakeTestingRamseyUuidType::NAME )) {
90
+ Type::addType (FakeTestingRamseyUuidType::NAME , FakeTestingRamseyUuidType::class);
91
+ }
92
+
93
+ $ descriptors [] = new RamseyUuidTypeDescriptor (FakeTestingRamseyUuidType::class);
54
94
}
55
95
if (!Type::hasType ('carbon ' )) {
56
96
Type::addType ('carbon ' , CarbonType::class);
@@ -64,25 +104,7 @@ protected function getRule(): Rule
64
104
65
105
return new EntityColumnRule (
66
106
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
- ]),
107
+ new DefaultDescriptorRegistry ($ descriptors ),
86
108
$ this ->createReflectionProvider (),
87
109
true ,
88
110
$ this ->allowNullablePropertyForRequiredField ,
@@ -461,6 +483,18 @@ public function testBug677(?string $objectManagerLoader): void
461
483
$ this ->analyse ([__DIR__ . '/data/bug-677.php ' ], []);
462
484
}
463
485
486
+ /**
487
+ * @dataProvider dataObjectManagerLoader
488
+ */
489
+ public function testSymfonyUuid (?string $ objectManagerLoader ): void
490
+ {
491
+ $ this ->allowNullablePropertyForRequiredField = true ;
492
+ $ this ->objectManagerLoader = $ objectManagerLoader ;
493
+ $ this ->useSymfonyUuid = true ;
494
+
495
+ $ this ->analyse ([__DIR__ . '/data/EntityWithSymfonyUid.php ' ], []);
496
+ }
497
+
464
498
/**
465
499
* @dataProvider dataObjectManagerLoader
466
500
*/
0 commit comments