22
33namespace PHPStan \Rules \Doctrine \ORM ;
44
5+ use Iterator ;
56use PHPStan \Rules \Rule ;
67use PHPStan \Testing \RuleTestCase ;
78use PHPStan \Type \Doctrine \DescriptorRegistry ;
@@ -31,31 +32,30 @@ protected function getRule(): Rule
3132
3233 public function testRule (): void
3334 {
34- require_once __DIR__ . '/data/MyBrokenSuperclass.php ' ;
3535 $ this ->analyse ([__DIR__ . '/data/MyBrokenEntity.php ' ], [
3636 [
37- 'Database can contain string but property expects int. ' ,
38- 17 ,
37+ 'Database can contain string but property expects int|null . ' ,
38+ 19 ,
3939 ],
4040 [
4141 'Database can contain string|null but property expects string. ' ,
42- 23 ,
42+ 25 ,
4343 ],
4444 [
4545 'Property can contain string|null but database expects string. ' ,
46- 29 ,
46+ 31 ,
4747 ],
4848 [
4949 'Database can contain DateTime but property expects DateTimeImmutable. ' ,
50- 35 ,
50+ 37 ,
5151 ],
5252 [
5353 'Database can contain DateTimeImmutable but property expects DateTime. ' ,
54- 41 ,
54+ 43 ,
5555 ],
5656 [
5757 'Property can contain DateTime but database expects DateTimeImmutable. ' ,
58- 41 ,
58+ 43 ,
5959 ],
6060 ]);
6161 }
@@ -70,4 +70,28 @@ public function testSuperclass(): void
7070 ]);
7171 }
7272
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+
7397}
0 commit comments