File tree Expand file tree Collapse file tree 4 files changed +71
-19
lines changed
tests/DoctrineIntegration/ORM Expand file tree Collapse file tree 4 files changed +71
-19
lines changed Original file line number Diff line number Diff line change @@ -14,14 +14,20 @@ class EntityManagerTypeInferenceTest extends TypeInferenceTestCase
14
14
*/
15
15
public function dataFileAsserts (): iterable
16
16
{
17
+ $ ormVersion = InstalledVersions::getVersion ('doctrine/orm ' );
18
+ $ hasOrm2 = $ ormVersion !== null && strpos ($ ormVersion , '2. ' ) === 0 ;
19
+ if ($ hasOrm2 ) {
20
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/entityManager-orm2.php ' );
21
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/entityManagerMergeReturn.php ' );
22
+ }
17
23
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/entityManagerDynamicReturn.php ' );
18
- yield from $ this -> gatherAssertTypes ( __DIR__ . ' /data/entityManagerMergeReturn.php ' );
24
+
19
25
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/customRepositoryUsage.php ' );
20
26
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/queryBuilder.php ' );
21
27
22
- $ version = InstalledVersions::getVersion ('doctrine/dbal ' );
23
- $ hasDbal3 = $ version !== null && strpos ($ version , '3. ' ) === 0 ;
24
- $ hasDbal4 = $ version !== null && strpos ($ version , '4. ' ) === 0 ;
28
+ $ dbalVersion = InstalledVersions::getVersion ('doctrine/dbal ' );
29
+ $ hasDbal3 = $ dbalVersion !== null && strpos ($ dbalVersion , '3. ' ) === 0 ;
30
+ $ hasDbal4 = $ dbalVersion !== null && strpos ($ dbalVersion , '4. ' ) === 0 ;
25
31
26
32
if ($ hasDbal4 ) {
27
33
// nothing to test
Original file line number Diff line number Diff line change @@ -14,8 +14,14 @@ class EntityManagerWithoutObjectManagerLoaderTypeInferenceTest extends TypeInfer
14
14
*/
15
15
public function dataFileAsserts (): iterable
16
16
{
17
+ $ ormVersion = InstalledVersions::getVersion ('doctrine/orm ' );
18
+ $ hasOrm2 = $ ormVersion !== null && strpos ($ ormVersion , '2. ' ) === 0 ;
19
+ if ($ hasOrm2 ) {
20
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/entityManager-orm2.php ' );
21
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/entityManagerMergeReturn.php ' );
22
+ }
23
+
17
24
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/entityManagerDynamicReturn.php ' );
18
- yield from $ this ->gatherAssertTypes (__DIR__ . '/data/entityManagerMergeReturn.php ' );
19
25
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/customRepositoryUsage.php ' );
20
26
21
27
$ version = InstalledVersions::getVersion ('doctrine/dbal ' );
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace PHPStan \DoctrineIntegration \ORM \EntityManagerOrm2 ;
4
+
5
+ use Doctrine \ORM \EntityManagerInterface ;
6
+ use Doctrine \ORM \Mapping as ORM ;
7
+ use RuntimeException ;
8
+ use function PHPStan \Testing \assertType ;
9
+
10
+ class Example
11
+ {
12
+ /**
13
+ * @var EntityManagerInterface
14
+ */
15
+ private $ entityManager ;
16
+
17
+ public function __construct (EntityManagerInterface $ entityManager )
18
+ {
19
+ $ this ->entityManager = $ entityManager ;
20
+ }
21
+
22
+ public function getPartialReferenceDynamicType (): void
23
+ {
24
+ $ test = $ this ->entityManager ->getPartialReference (MyEntity::class, 1 );
25
+
26
+ if ($ test === null ) {
27
+ throw new RuntimeException ('Sorry, but no... ' );
28
+ }
29
+
30
+ assertType (MyEntity::class, $ test );
31
+
32
+ $ test ->doSomething ();
33
+ $ test ->doSomethingElse ();
34
+ }
35
+ }
36
+
37
+ /**
38
+ * @ORM\Entity()
39
+ */
40
+ class MyEntity
41
+ {
42
+ /**
43
+ * @ORM\Id()
44
+ * @ORM\GeneratedValue()
45
+ * @ORM\Column(type="integer")
46
+ *
47
+ * @var int
48
+ */
49
+ private $ id ;
50
+
51
+ public function doSomething (): void
52
+ {
53
+ }
54
+ }
Original file line number Diff line number Diff line change @@ -45,20 +45,6 @@ public function getReferenceDynamicType(): void
45
45
$ test ->doSomethingElse ();
46
46
}
47
47
48
- public function getPartialReferenceDynamicType (): void
49
- {
50
- $ test = $ this ->entityManager ->getPartialReference (MyEntity::class, 1 );
51
-
52
- if ($ test === null ) {
53
- throw new RuntimeException ('Sorry, but no... ' );
54
- }
55
-
56
- assertType (MyEntity::class, $ test );
57
-
58
- $ test ->doSomething ();
59
- $ test ->doSomethingElse ();
60
- }
61
-
62
48
/**
63
49
* @param class-string $entityName
64
50
*/
You can’t perform that action at this time.
0 commit comments