File tree 2 files changed +81
-2
lines changed
2 files changed +81
-2
lines changed Original file line number Diff line number Diff line change 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 \ObjectMetadataResolver ;
@@ -16,9 +17,35 @@ protected function getRule(): Rule
16
17
);
17
18
}
18
19
19
- public function testRule (): void
20
+ /**
21
+ * @dataProvider ruleProvider
22
+ */
23
+ public function testRule (string $ file , array $ expectedErrors ): void
20
24
{
21
- $ this ->analyse ([__DIR__ . '/data/EntityWithRelations.php ' ], []);
25
+ $ this ->analyse ([$ file ], $ expectedErrors );
26
+ }
27
+
28
+ public function ruleProvider (): Iterator
29
+ {
30
+ yield [__DIR__ . '/data/EntityWithRelations.php ' , []];
31
+ yield [__DIR__ . '/data/EntityWithBrokenOneToOneRelations.php ' , [
32
+ [
33
+ 'Property can contain PHPStan\Rules\Doctrine\ORM\AnotherEntity|null but database expects PHPStan\Rules\Doctrine\ORM\AnotherEntity. ' ,
34
+ 31 ,
35
+ ],
36
+ [
37
+ 'Database can contain PHPStan\Rules\Doctrine\ORM\AnotherEntity|null but property expects PHPStan\Rules\Doctrine\ORM\AnotherEntity. ' ,
38
+ 37 ,
39
+ ],
40
+ [
41
+ 'Database can contain PHPStan\Rules\Doctrine\ORM\AnotherEntity|null but property expects PHPStan\Rules\Doctrine\ORM\MyEntity|null. ' ,
42
+ 50 ,
43
+ ],
44
+ [
45
+ 'Property can contain PHPStan\Rules\Doctrine\ORM\MyEntity|null but database expects PHPStan\Rules\Doctrine\ORM\AnotherEntity|null. ' ,
46
+ 50 ,
47
+ ]
48
+ ]];
22
49
}
23
50
24
51
}
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types = 1 );
2
+
3
+ namespace PHPStan \Rules \Doctrine \ORM ;
4
+
5
+ use Doctrine \ORM \Mapping as ORM ;
6
+
7
+ /**
8
+ * @ORM\Entity()
9
+ */
10
+ class EntityWithBrokenOneToOneRelations
11
+ {
12
+
13
+ /**
14
+ * @ORM\Id()
15
+ * @ORM\Column(type="int")
16
+ * @var int
17
+ */
18
+ private $ id ;
19
+
20
+ /**
21
+ * @ORM\OneToOne(targetEntity="PHPStan\Rules\Doctrine\ORM\AnotherEntity")
22
+ * @var \PHPStan\Rules\Doctrine\ORM\AnotherEntity|null
23
+ */
24
+ private $ oneToOneNullableBoth ;
25
+
26
+ /**
27
+ * @ORM\OneToOne(targetEntity="PHPStan\Rules\Doctrine\ORM\AnotherEntity")
28
+ * @ORM\JoinColumn(nullable=false)
29
+ * @var \PHPStan\Rules\Doctrine\ORM\AnotherEntity|null
30
+ */
31
+ private $ oneToOneNullableProperty ;
32
+
33
+ /**
34
+ * @ORM\OneToOne(targetEntity="PHPStan\Rules\Doctrine\ORM\AnotherEntity")
35
+ * @var \PHPStan\Rules\Doctrine\ORM\AnotherEntity
36
+ */
37
+ private $ oneToOneNullableColumn ;
38
+
39
+ /**
40
+ * @ORM\OneToOne(targetEntity="PHPStan\Rules\Doctrine\ORM\AnotherEntity")
41
+ * @ORM\JoinColumn(nullable=false)
42
+ * @var \PHPStan\Rules\Doctrine\ORM\AnotherEntity
43
+ */
44
+ private $ oneToOneNonNullable ;
45
+
46
+ /**
47
+ * @ORM\OneToOne(targetEntity="PHPStan\Rules\Doctrine\ORM\AnotherEntity")
48
+ * @var \PHPStan\Rules\Doctrine\ORM\MyEntity|null
49
+ */
50
+ private $ oneToOneWrongClass ;
51
+
52
+ }
You can’t perform that action at this time.
0 commit comments