1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2017 Gerrit Addiks. |
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
7
|
|
|
* @license GPL-3.0 |
8
|
|
|
* @author Gerrit Addiks <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Addiks\RDMBundle\Tests\DataLoader; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Addiks\RDMBundle\DataLoader\DataLoaderLazyLoadProxy; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
16
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
17
|
|
|
use Addiks\RDMBundle\Tests\Hydration\EntityExample; |
18
|
|
|
use Addiks\RDMBundle\DataLoader\DataLoaderInterface; |
19
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
20
|
|
|
|
21
|
|
|
final class DataLoaderLazyLoadProxyTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var DataLoaderLazyLoadProxy |
26
|
|
|
*/ |
27
|
|
|
private $dataLoaderProxy; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var DataLoaderInterface |
31
|
|
|
*/ |
32
|
|
|
private $innerDataLoader; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var ContainerInterface |
36
|
|
|
*/ |
37
|
|
|
private $container; |
38
|
|
|
|
39
|
|
View Code Duplication |
public function setUp() |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$this->container = $this->createMock(ContainerInterface::class); |
|
|
|
|
42
|
|
|
$this->innerDataLoader = $this->createMock(DataLoaderInterface::class); |
|
|
|
|
43
|
|
|
|
44
|
|
|
$this->container->method('get')->will($this->returnValueMap([ |
45
|
|
|
["some_service", ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->innerDataLoader], |
46
|
|
|
])); |
47
|
|
|
|
48
|
|
|
$this->dataLoaderProxy = new DataLoaderLazyLoadProxy($this->container, "some_service"); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @test |
53
|
|
|
*/ |
54
|
|
|
public function shouldForwardLoadOperation() |
55
|
|
|
{ |
56
|
|
|
/** @var EntityExample $entity */ |
57
|
|
|
$entity = $this->createMock(EntityExample::class); |
58
|
|
|
|
59
|
|
|
/** @var EntityManagerInterface $entityManager */ |
60
|
|
|
$entityManager = $this->createMock(EntityManagerInterface::class); |
61
|
|
|
|
62
|
|
|
$this->innerDataLoader->expects($this->once())->method('loadDBALDataForEntity')->with( |
|
|
|
|
63
|
|
|
$this->equalTo($entity), |
64
|
|
|
$this->equalTo($entityManager) |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$this->dataLoaderProxy->loadDBALDataForEntity($entity, $entityManager); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @test |
72
|
|
|
*/ |
73
|
|
|
public function shouldForwardStoreOperation() |
74
|
|
|
{ |
75
|
|
|
/** @var EntityExample $entity */ |
76
|
|
|
$entity = $this->createMock(EntityExample::class); |
77
|
|
|
|
78
|
|
|
/** @var EntityManagerInterface $entityManager */ |
79
|
|
|
$entityManager = $this->createMock(EntityManagerInterface::class); |
80
|
|
|
|
81
|
|
|
$this->innerDataLoader->expects($this->once())->method('storeDBALDataForEntity')->with( |
|
|
|
|
82
|
|
|
$this->equalTo($entity), |
83
|
|
|
$this->equalTo($entityManager) |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
$this->dataLoaderProxy->storeDBALDataForEntity($entity, $entityManager); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @test |
91
|
|
|
*/ |
92
|
|
|
public function shouldForwardRemoveOperation() |
93
|
|
|
{ |
94
|
|
|
/** @var EntityExample $entity */ |
95
|
|
|
$entity = $this->createMock(EntityExample::class); |
96
|
|
|
|
97
|
|
|
/** @var EntityManagerInterface $entityManager */ |
98
|
|
|
$entityManager = $this->createMock(EntityManagerInterface::class); |
99
|
|
|
|
100
|
|
|
$this->innerDataLoader->expects($this->once())->method('removeDBALDataForEntity')->with( |
|
|
|
|
101
|
|
|
$this->equalTo($entity), |
102
|
|
|
$this->equalTo($entityManager) |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$this->dataLoaderProxy->removeDBALDataForEntity($entity, $entityManager); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @test |
110
|
|
|
*/ |
111
|
|
|
public function shouldForwardPrepareOperation() |
112
|
|
|
{ |
113
|
|
|
/** @var EntityManagerInterface $entityManager */ |
114
|
|
|
$entityManager = $this->createMock(EntityManagerInterface::class); |
115
|
|
|
|
116
|
|
|
/** @var ClassMetadata $classMetadata */ |
117
|
|
|
$classMetadata = $this->createMock(ClassMetadata::class); |
118
|
|
|
|
119
|
|
|
$this->innerDataLoader->expects($this->once())->method('prepareOnMetadataLoad')->with( |
|
|
|
|
120
|
|
|
$this->equalTo($entityManager), |
121
|
|
|
$this->equalTo($classMetadata) |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
$this->dataLoaderProxy->prepareOnMetadataLoad($entityManager, $classMetadata); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.