Skip to content

Commit 74ba5ac

Browse files
committed
Add integration test for entity manager dynamic return
1 parent a0314b1 commit 74ba5ac

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ includes:
22
- vendor/phpstan/phpstan-strict-rules/rules.neon
33
- vendor/phpstan/phpstan-phpunit/extension.neon
44
- vendor/phpstan/phpstan-phpunit/rules.neon
5+
6+
parameters:
7+
excludes_analyse:
8+
- */tests/*/data/*
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\DoctrineIntegration\ORM;
4+
5+
use PHPStan\Testing\LevelsTestCase;
6+
7+
final class EntityManagerIntegrationTest extends LevelsTestCase
8+
{
9+
10+
/**
11+
* @return string[][]
12+
*/
13+
public function dataTopics(): array
14+
{
15+
return [['entityManagerDynamicReturn']];
16+
}
17+
18+
public function getDataPath(): string
19+
{
20+
return __DIR__ . '/data';
21+
}
22+
23+
public function getPhpStanExecutablePath(): string
24+
{
25+
return __DIR__ . '/../../../vendor/bin/phpstan';
26+
}
27+
28+
public function getPhpStanConfigPath(): ?string
29+
{
30+
return __DIR__ . '/phpstan.neon';
31+
}
32+
33+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\DoctrineIntegration\ORM\EntityManagerDynamicReturn;
4+
5+
use Doctrine\ORM\EntityManagerInterface;
6+
use RuntimeException;
7+
8+
class Example
9+
{
10+
/**
11+
* @var EntityManagerInterface
12+
*/
13+
private $entityManager;
14+
15+
public function __construct(EntityManagerInterface $entityManager)
16+
{
17+
$this->entityManager = $entityManager;
18+
}
19+
20+
public function findDynamicType(): void
21+
{
22+
$test = $this->entityManager->find(MyEntity::class, 1);
23+
24+
if ($test === null) {
25+
throw new RuntimeException('Sorry, but no...');
26+
}
27+
28+
$test->doSomething();
29+
}
30+
31+
public function getReferenceDynamicType(): void
32+
{
33+
$test = $this->entityManager->getReference(MyEntity::class, 1);
34+
$test->doSomething();
35+
}
36+
37+
public function getPartialReferenceDynamicType(): void
38+
{
39+
$test = $this->entityManager->getPartialReference(MyEntity::class, 1);
40+
$test->doSomething();
41+
}
42+
}
43+
44+
/**
45+
* @ORM\Entity()
46+
*/
47+
class MyEntity
48+
{
49+
public function doSomething(): void
50+
{
51+
}
52+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
includes:
2+
- ../../../extension.neon

0 commit comments

Comments
 (0)