Skip to content

Commit 4facb3f

Browse files
committed
Add integration tests for ODM features as well
1 parent 10a9101 commit 4facb3f

File tree

5 files changed

+211
-0
lines changed

5 files changed

+211
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\DoctrineIntegration\ODM;
4+
5+
use PHPStan\Testing\LevelsTestCase;
6+
7+
final class DocumentManagerIntegrationTest extends LevelsTestCase
8+
{
9+
10+
/**
11+
* @return string[][]
12+
*/
13+
public function dataTopics(): array
14+
{
15+
return [
16+
['documentManagerDynamicReturn'],
17+
['documentRepositoryDynamicReturn'],
18+
['documentManagerMergeReturn'],
19+
];
20+
}
21+
22+
public function getDataPath(): string
23+
{
24+
return __DIR__ . '/data';
25+
}
26+
27+
public function getPhpStanExecutablePath(): string
28+
{
29+
return __DIR__ . '/../../../vendor/bin/phpstan';
30+
}
31+
32+
public function getPhpStanConfigPath(): ?string
33+
{
34+
return __DIR__ . '/phpstan.neon';
35+
}
36+
37+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\DoctrineIntegration\ODM\DocumentManagerDynamicReturn;
4+
5+
use Doctrine\ODM\MongoDB\DocumentManager;
6+
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
7+
use RuntimeException;
8+
9+
class Example
10+
{
11+
/**
12+
* @var DocumentManager
13+
*/
14+
private $documentManager;
15+
16+
public function __construct(DocumentManager $documentManager)
17+
{
18+
$this->documentManager = $documentManager;
19+
}
20+
21+
public function findDynamicType(): void
22+
{
23+
$test = $this->documentManager->find(MyDocument::class, 'blah-123');
24+
25+
if ($test === null) {
26+
throw new RuntimeException('Sorry, but no...');
27+
}
28+
29+
$test->doSomething();
30+
}
31+
32+
public function getReferenceDynamicType(): void
33+
{
34+
$test = $this->documentManager->getReference(MyDocument::class, 'blah-123');
35+
36+
if ($test === null) {
37+
throw new RuntimeException('Sorry, but no...');
38+
}
39+
40+
$test->doSomething();
41+
}
42+
43+
public function getPartialReferenceDynamicType(): void
44+
{
45+
$test = $this->documentManager->getPartialReference(MyDocument::class, 'blah-123');
46+
47+
if ($test === null) {
48+
throw new RuntimeException('Sorry, but no...');
49+
}
50+
51+
$test->doSomething();
52+
}
53+
}
54+
55+
/**
56+
* @Document()
57+
*/
58+
class MyDocument
59+
{
60+
public function doSomething(): void
61+
{
62+
}
63+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\DoctrineIntegration\ODM\DocumentManagerMergeReturn;
4+
5+
use Doctrine\ODM\MongoDB\DocumentManager;
6+
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
7+
8+
class Example
9+
{
10+
/**
11+
* @var DocumentManager
12+
*/
13+
private $documentManager;
14+
15+
public function __construct(DocumentManager $documentManager)
16+
{
17+
$this->documentManager = $documentManager;
18+
}
19+
20+
public function merge(): void
21+
{
22+
$test = $this->documentManager->merge(new MyDocument());
23+
$test->doSomething();
24+
}
25+
}
26+
27+
/**
28+
* @Document()
29+
*/
30+
class MyDocument
31+
{
32+
public function doSomething(): void
33+
{
34+
}
35+
}
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\ODM\EntityRepositoryDynamicReturn;
4+
5+
use Doctrine\ODM\MongoDB\DocumentManager;
6+
use Doctrine\ODM\MongoDB\DocumentRepository;
7+
use RuntimeException;
8+
9+
class Example
10+
{
11+
/**
12+
* @var DocumentRepository
13+
*/
14+
private $repository;
15+
16+
public function __construct(DocumentManager $documentManager)
17+
{
18+
$this->repository = $documentManager->getRepository(MyDocument::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 MyDocument
66+
{
67+
public function doSomething(): void
68+
{
69+
}
70+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
includes:
2+
- ../../../extension.neon
3+
4+
parameters:
5+
doctrine:
6+
repositoryClass: Doctrine\ODM\MongoDB\DocumentRepository

0 commit comments

Comments
 (0)