@@ 116-157 (lines=42) @@ | ||
113 | /** |
|
114 | * @test |
|
115 | */ |
|
116 | public function shouldCallService() |
|
117 | { |
|
118 | /** @var Request $request */ |
|
119 | $request = $this->createMock(Request::class); |
|
120 | ||
121 | /** @var SampleService $service */ |
|
122 | $service = $this->createMock(SampleService::class); |
|
123 | ||
124 | $service->expects($this->once())->method('doFoo')->with( |
|
125 | $this->equalTo('lorem'), |
|
126 | $this->equalTo('ipsum') |
|
127 | ); |
|
128 | ||
129 | $this->container->expects($this->once())->method('get')->with( |
|
130 | $this->equalTo('some_service') |
|
131 | )->willReturn($service); |
|
132 | ||
133 | $this->argumentCompiler->expects($this->once())->method('buildCallArguments')->with( |
|
134 | $this->equalTo(new ReflectionMethod($service, 'doFoo')), |
|
135 | $this->equalTo(['lorem' => 'ipsum']), |
|
136 | $this->identicalTo($request) |
|
137 | )->willReturn(['lorem', 'ipsum']); |
|
138 | ||
139 | /** @var string $expectedResponseContent */ |
|
140 | $expectedResponseContent = "Service call completed"; |
|
141 | ||
142 | $controller = new GenericServiceInvokeController( |
|
143 | $this->controllerHelper, |
|
144 | $this->argumentCompiler, |
|
145 | $this->container, |
|
146 | [ |
|
147 | 'service' => 'some_service', |
|
148 | 'method' => 'doFoo', |
|
149 | 'arguments' => ['lorem' => 'ipsum'] |
|
150 | ] |
|
151 | ); |
|
152 | ||
153 | /** @var Response $actualResponse */ |
|
154 | $actualResponse = $controller->callService($request); |
|
155 | ||
156 | $this->assertEquals($expectedResponseContent, $actualResponse->getContent()); |
|
157 | } |
|
158 | ||
159 | /** |
|
160 | * @test |
|
@@ 223-266 (lines=44) @@ | ||
220 | /** |
|
221 | * @test |
|
222 | */ |
|
223 | public function shouldBeCallableByInvokingController() |
|
224 | { |
|
225 | /** @var Request $request */ |
|
226 | $request = $this->createMock(Request::class); |
|
227 | ||
228 | /** @var SampleService $service */ |
|
229 | $service = $this->createMock(SampleService::class); |
|
230 | ||
231 | $service->expects($this->once())->method('doFoo')->with( |
|
232 | $this->equalTo('lorem'), |
|
233 | $this->equalTo('ipsum') |
|
234 | ); |
|
235 | ||
236 | $this->container->expects($this->once())->method('get')->with( |
|
237 | $this->equalTo('some_service') |
|
238 | )->willReturn($service); |
|
239 | ||
240 | $this->argumentCompiler->expects($this->once())->method('buildCallArguments')->with( |
|
241 | $this->equalTo(new ReflectionMethod($service, 'doFoo')), |
|
242 | $this->equalTo(['lorem' => 'ipsum']), |
|
243 | $this->identicalTo($request) |
|
244 | )->willReturn(['lorem', 'ipsum']); |
|
245 | ||
246 | /** @var string $expectedResponseContent */ |
|
247 | $expectedResponseContent = "Service call completed"; |
|
248 | ||
249 | $controller = new GenericServiceInvokeController( |
|
250 | $this->controllerHelper, |
|
251 | $this->argumentCompiler, |
|
252 | $this->container, |
|
253 | [ |
|
254 | 'service' => 'some_service', |
|
255 | 'method' => 'doFoo', |
|
256 | 'arguments' => ['lorem' => 'ipsum'] |
|
257 | ] |
|
258 | ); |
|
259 | ||
260 | $this->controllerHelper->method('getCurrentRequest')->willReturn($request); |
|
261 | ||
262 | /** @var Response $actualResponse */ |
|
263 | $actualResponse = $controller(); |
|
264 | ||
265 | $this->assertEquals($expectedResponseContent, $actualResponse->getContent()); |
|
266 | } |
|
267 | ||
268 | /** |
|
269 | * @test |