Skip to content

Commit 2e944bd

Browse files
committed
Add integration test for entity repository dynamic return
1 parent b3842be commit 2e944bd

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

tests/DoctrineIntegration/ORM/EntityManagerIntegrationTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ final class EntityManagerIntegrationTest extends LevelsTestCase
1212
*/
1313
public function dataTopics(): array
1414
{
15-
return [['entityManagerDynamicReturn']];
15+
return [
16+
['entityManagerDynamicReturn'],
17+
['entityRepositoryDynamicReturn'],
18+
];
1619
}
1720

1821
public function getDataPath(): string
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\DoctrineIntegration\ORM\EntityRepositoryDynamicReturn;
4+
5+
use Doctrine\ORM\EntityManagerInterface;
6+
use Doctrine\ORM\EntityRepository;
7+
use RuntimeException;
8+
9+
class Example
10+
{
11+
/**
12+
* @var EntityRepository
13+
*/
14+
private $repository;
15+
16+
public function __construct(EntityManagerInterface $entityManager)
17+
{
18+
$this->repository = $entityManager->getRepository(MyEntity::class);
19+
}
20+
21+
public function findDynamicType(): void
22+
{
23+
$test = $this->repository->find(1);
24+
25+
if ($test === null) {
26+
throw new RuntimeException('Sorry, but no...');
27+
}
28+
29+
$test->doSomething();
30+
}
31+
32+
public function findOneByDynamicType(): void
33+
{
34+
$test = $this->repository->findOneBy(['blah' => 'testing']);
35+
36+
if ($test === null) {
37+
throw new RuntimeException('Sorry, but no...');
38+
}
39+
40+
$test->doSomething();
41+
}
42+
43+
public function findAllDynamicType(): void
44+
{
45+
$items = $this->repository->findAll();
46+
47+
foreach ($items as $test) {
48+
$test->doSomething();
49+
}
50+
}
51+
52+
public function findByDynamicType(): void
53+
{
54+
$items = $this->repository->findBy(['blah' => 'testing']);
55+
56+
foreach ($items as $test) {
57+
$test->doSomething();
58+
}
59+
}
60+
}
61+
62+
/**
63+
* @ORM\Entity()
64+
*/
65+
class MyEntity
66+
{
67+
public function doSomething(): void
68+
{
69+
}
70+
}

0 commit comments

Comments
 (0)