-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAbstractRepositoryTest.php
More file actions
97 lines (82 loc) · 2.68 KB
/
Copy pathAbstractRepositoryTest.php
File metadata and controls
97 lines (82 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php declare(strict_types=1);
namespace App\Tests\Unit\Repository;
use App\Exception\EntityDoesNotExistException;
use App\Repository\AbstractRepository;
use App\Tests\Shared\Dummy\Entity\Dummy;
use App\Tests\Shared\Dummy\Repository\DummyRepository;
use App\Tests\Shared\Unit\TestCase;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Symfony\Bridge\Doctrine\ManagerRegistry;
class AbstractRepositoryTest extends TestCase
{
/**
* @dataProvider classNameProvider
* @param string $repositoryClass
* @param string $expectedEntityClass
*/
public function testRepositoryIntoEntityClassConverter(string $repositoryClass, string $expectedEntityClass)
{
// Arrange
$abstract = $this->getMockBuilder(AbstractRepository::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
// Act
$entityClass = $abstract->repositoryIntoEntityClassConverter($repositoryClass);
// Assert
$this->assertSame($expectedEntityClass, $entityClass);
}
public function classNameProvider()
{
return [
[
'DummyRepository',
'Dummy',
],
[
'Repository\\DummyRepository',
'Entity\\Dummy',
],
[
'My\\Class\\Name\\Repository\\DummyRepository',
'My\\Class\\Name\\Entity\\Dummy',
]
];
}
/**
* @depends testRepositoryIntoEntityClassConverter
*/
public function testRepositoryClassWithEntity()
{
// Arrange
$abstract = new DummyRepository($this->registry(Dummy::class));
// Act
$className = $abstract->getClassName();
// Assert
$this->assertSame(Dummy::class, $className);
}
/**
* @depends testRepositoryIntoEntityClassConverter
*/
public function testRepositoryClassWithoutEntity()
{
$this->expectException(EntityDoesNotExistException::class);
// Act
new class($this->registry()) extends AbstractRepository
{
};
}
/**
* @param string|null $entityClass
* @return ManagerRegistry
*/
private function registry(?string $entityClass = null): ManagerRegistry
{
$classMetadata = new ClassMetadata($entityClass);
$manager = $this->prophesize(EntityManagerInterface::class);
$manager->getClassMetadata($entityClass)->willReturn($classMetadata);
$registry = $this->prophesize(ManagerRegistry::class);
$registry->getManagerForClass($entityClass)->willReturn($manager->reveal());
return $registry->reveal();
}
}