2
2
3
3
namespace PHPStan \Rules \Doctrine \ORM ;
4
4
5
+ use Iterator ;
5
6
use PHPStan \Rules \Rule ;
6
7
use PHPStan \Testing \RuleTestCase ;
7
8
use PHPStan \Type \Doctrine \DescriptorRegistry ;
@@ -31,31 +32,30 @@ protected function getRule(): Rule
31
32
32
33
public function testRule (): void
33
34
{
34
- require_once __DIR__ . '/data/MyBrokenSuperclass.php ' ;
35
35
$ this ->analyse ([__DIR__ . '/data/MyBrokenEntity.php ' ], [
36
36
[
37
- 'Database can contain string but property expects int. ' ,
38
- 17 ,
37
+ 'Database can contain string but property expects int|null . ' ,
38
+ 19 ,
39
39
],
40
40
[
41
41
'Database can contain string|null but property expects string. ' ,
42
- 23 ,
42
+ 25 ,
43
43
],
44
44
[
45
45
'Property can contain string|null but database expects string. ' ,
46
- 29 ,
46
+ 31 ,
47
47
],
48
48
[
49
49
'Database can contain DateTime but property expects DateTimeImmutable. ' ,
50
- 35 ,
50
+ 37 ,
51
51
],
52
52
[
53
53
'Database can contain DateTimeImmutable but property expects DateTime. ' ,
54
- 41 ,
54
+ 43 ,
55
55
],
56
56
[
57
57
'Property can contain DateTime but database expects DateTimeImmutable. ' ,
58
- 41 ,
58
+ 43 ,
59
59
],
60
60
]);
61
61
}
@@ -70,4 +70,28 @@ public function testSuperclass(): void
70
70
]);
71
71
}
72
72
73
+ /**
74
+ * @dataProvider generatedIdsProvider
75
+ */
76
+ public function testGeneratedIds (string $ file , array $ expectedErrors ): void
77
+ {
78
+ $ this ->analyse ([$ file ], $ expectedErrors );
79
+ }
80
+
81
+ public function generatedIdsProvider (): Iterator
82
+ {
83
+ yield 'not nullable ' => [__DIR__ . '/data/GeneratedIdEntity1.php ' , []];
84
+ yield 'nullable column ' => [
85
+ __DIR__ . '/data/GeneratedIdEntity2.php ' ,
86
+ [
87
+ [
88
+ 'Database can contain string|null but property expects string. ' ,
89
+ 19 ,
90
+ ],
91
+ ],
92
+ ];
93
+ yield 'nullable property ' => [__DIR__ . '/data/GeneratedIdEntity3.php ' , []];
94
+ yield 'nullable both ' => [__DIR__ . '/data/GeneratedIdEntity4.php ' , []];
95
+ }
96
+
73
97
}
0 commit comments