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\ValueResolver; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Addiks\RDMBundle\ValueResolver\CallDefinitionExecuter; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
16
|
|
|
use Addiks\RDMBundle\ValueResolver\ValueResolverInterface; |
17
|
|
|
use Addiks\RDMBundle\Mapping\CallDefinitionInterface; |
18
|
|
|
use Addiks\RDMBundle\Tests\Hydration\EntityExample; |
19
|
|
|
use Addiks\RDMBundle\Tests\ValueObjectExample; |
20
|
|
|
use Addiks\RDMBundle\Tests\Hydration\ServiceExample; |
21
|
|
|
use Addiks\RDMBundle\Mapping\MappingInterface; |
22
|
|
|
|
23
|
|
|
final class CallDefinitionExecuterTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var CallDefinitionExecuter |
28
|
|
|
*/ |
29
|
|
|
private $callDefinitionExecuter; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var ContainerInterface |
33
|
|
|
*/ |
34
|
|
|
private $container; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var ValueResolverInterface |
38
|
|
|
*/ |
39
|
|
|
private $argumentResolver; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var null|ValueObjectExample |
43
|
|
|
*/ |
44
|
|
|
private static $valueObjectToCreate; |
45
|
|
|
|
46
|
|
|
public function setUp() |
47
|
|
|
{ |
48
|
|
|
$this->container = $this->createMock(ContainerInterface::class); |
|
|
|
|
49
|
|
|
$this->argumentResolver = $this->createMock(ValueResolverInterface::class); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$this->callDefinitionExecuter = new CallDefinitionExecuter( |
52
|
|
|
$this->container, |
|
|
|
|
53
|
|
|
$this->argumentResolver |
|
|
|
|
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @test |
59
|
|
|
*/ |
60
|
|
View Code Duplication |
public function shouldExecuteCallDefinitionOnEntity() |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
/** @var CallDefinitionInterface $callDefinition */ |
63
|
|
|
$callDefinition = $this->createMock(CallDefinitionInterface::class); |
64
|
|
|
|
65
|
|
|
/** @var EntityExample $entity */ |
66
|
|
|
$entity = $this->createMock(EntityExample::class); |
67
|
|
|
|
68
|
|
|
/** @var array<string> $dataFromAdditionalColumns */ |
69
|
|
|
$dataFromAdditionalColumns = array( |
70
|
|
|
'lorem' => 'ipsum', |
71
|
|
|
'dolor' => 'sit amet' |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$callDefinition->method('getObjectReference')->willReturn('self'); |
|
|
|
|
75
|
|
|
$callDefinition->method('getRoutineName')->willReturn('getBoo'); |
|
|
|
|
76
|
|
|
$callDefinition->method('getArgumentMappings')->willReturn([]); |
|
|
|
|
77
|
|
|
|
78
|
|
|
/** @var ValueObjectExample $expectedResult */ |
79
|
|
|
$expectedResult = $this->createMock(ValueObjectExample::class); |
80
|
|
|
|
81
|
|
|
$entity->method('getBoo')->willReturn($expectedResult); |
|
|
|
|
82
|
|
|
|
83
|
|
|
/** @var mixed $actualResult */ |
84
|
|
|
$actualResult = $this->callDefinitionExecuter->executeCallDefinition( |
85
|
|
|
$callDefinition, |
86
|
|
|
$entity, |
87
|
|
|
$dataFromAdditionalColumns |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$this->assertSame($expectedResult, $actualResult); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @test |
95
|
|
|
*/ |
96
|
|
View Code Duplication |
public function shouldExecuteCallDefinitionOnStaticEntity() |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
/** @var CallDefinitionInterface $callDefinition */ |
99
|
|
|
$callDefinition = $this->createMock(CallDefinitionInterface::class); |
100
|
|
|
|
101
|
|
|
/** @var EntityExample $entity */ |
102
|
|
|
$entity = $this->createMock(EntityExample::class); |
103
|
|
|
|
104
|
|
|
/** @var array<string> $dataFromAdditionalColumns */ |
105
|
|
|
$dataFromAdditionalColumns = array( |
106
|
|
|
'lorem' => 'ipsum', |
107
|
|
|
'dolor' => 'sit amet' |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$callDefinition->method('getObjectReference')->willReturn(__CLASS__); |
|
|
|
|
111
|
|
|
$callDefinition->method('getRoutineName')->willReturn('createValueObject'); |
|
|
|
|
112
|
|
|
$callDefinition->method('getArgumentMappings')->willReturn([]); |
|
|
|
|
113
|
|
|
|
114
|
|
|
/** @var ValueObjectExample $expectedResult */ |
115
|
|
|
$expectedResult = $this->createMock(ValueObjectExample::class); |
116
|
|
|
|
117
|
|
|
self::$valueObjectToCreate = $expectedResult; |
118
|
|
|
|
119
|
|
|
/** @var mixed $actualResult */ |
120
|
|
|
$actualResult = $this->callDefinitionExecuter->executeCallDefinition( |
121
|
|
|
$callDefinition, |
122
|
|
|
$entity, |
123
|
|
|
$dataFromAdditionalColumns |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
$this->assertSame($expectedResult, $actualResult); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public static function createValueObject() |
130
|
|
|
{ |
131
|
|
|
return self::$valueObjectToCreate; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @test |
136
|
|
|
*/ |
137
|
|
|
public function shouldExecuteCallDefinitionOnService() |
138
|
|
|
{ |
139
|
|
|
/** @var CallDefinitionInterface $callDefinition */ |
140
|
|
|
$callDefinition = $this->createMock(CallDefinitionInterface::class); |
141
|
|
|
|
142
|
|
|
/** @var EntityExample $entity */ |
143
|
|
|
$entity = $this->createMock(EntityExample::class); |
144
|
|
|
|
145
|
|
|
/** @var ValueObjectExample $expectedResult */ |
146
|
|
|
$expectedResult = $this->createMock(ValueObjectExample::class); |
147
|
|
|
|
148
|
|
|
/** @var ServiceExample $factoryService */ |
149
|
|
|
$factoryService = $this->createMock(ServiceExample::class); |
150
|
|
|
|
151
|
|
|
/** @var array<string> $dataFromAdditionalColumns */ |
152
|
|
|
$dataFromAdditionalColumns = array( |
153
|
|
|
'lorem' => 'ipsum', |
154
|
|
|
'dolor' => 'sit amet' |
155
|
|
|
); |
156
|
|
|
|
157
|
|
|
/** @var MappingInterface $argumentMapping */ |
158
|
|
|
$argumentMapping = $this->createMock(MappingInterface::class); |
159
|
|
|
|
160
|
|
|
$callDefinition->method('getObjectReference')->willReturn('@foo_service'); |
|
|
|
|
161
|
|
|
$callDefinition->method('getRoutineName')->willReturn('getLorem'); |
|
|
|
|
162
|
|
|
$callDefinition->method('getArgumentMappings')->willReturn([$argumentMapping]); |
|
|
|
|
163
|
|
|
|
164
|
|
|
$this->argumentResolver->method('resolveValue')->will($this->returnValueMap([ |
|
|
|
|
165
|
|
|
[$argumentMapping, $entity, $dataFromAdditionalColumns, 'foo'], |
166
|
|
|
])); |
167
|
|
|
|
168
|
|
|
$factoryService->method('getLorem')->will($this->returnValueMap([ |
|
|
|
|
169
|
|
|
['foo', $expectedResult], |
170
|
|
|
])); |
171
|
|
|
|
172
|
|
|
$this->container->method('get')->will($this->returnValueMap([ |
|
|
|
|
173
|
|
|
['foo_service', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $factoryService], |
174
|
|
|
])); |
175
|
|
|
|
176
|
|
|
/** @var mixed $actualResult */ |
177
|
|
|
$actualResult = $this->callDefinitionExecuter->executeCallDefinition( |
178
|
|
|
$callDefinition, |
179
|
|
|
$entity, |
180
|
|
|
$dataFromAdditionalColumns |
181
|
|
|
); |
182
|
|
|
|
183
|
|
|
$this->assertSame($expectedResult, $actualResult); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
} |
187
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..