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
1414 */
1515 public function dataFileAsserts (): iterable
1616 {
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+ }
1723 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/entityManagerDynamicReturn.php ' );
18- yield from $ this -> gatherAssertTypes ( __DIR__ . ' /data/entityManagerMergeReturn.php ' );
24+
1925 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/customRepositoryUsage.php ' );
2026 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/queryBuilder.php ' );
2127
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 ;
2531
2632 if ($ hasDbal4 ) {
2733 // nothing to test
Original file line number Diff line number Diff line change @@ -14,8 +14,14 @@ class EntityManagerWithoutObjectManagerLoaderTypeInferenceTest extends TypeInfer
1414 */
1515 public function dataFileAsserts (): iterable
1616 {
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+
1724 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/entityManagerDynamicReturn.php ' );
18- yield from $ this ->gatherAssertTypes (__DIR__ . '/data/entityManagerMergeReturn.php ' );
1925 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/customRepositoryUsage.php ' );
2026
2127 $ 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
4545 $ test ->doSomethingElse ();
4646 }
4747
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-
6248 /**
6349 * @param class-string $entityName
6450 */
You can’t perform that action at this time.
0 commit comments