|
@@ 116-159 (lines=44) @@
|
| 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->controllerHelper->expects($this->once())->method('flushORM'); |
| 134 |
|
|
| 135 |
|
$this->argumentCompiler->expects($this->once())->method('buildCallArguments')->with( |
| 136 |
|
$this->equalTo(new ReflectionMethod($service, 'doFoo')), |
| 137 |
|
$this->equalTo(['lorem' => 'ipsum']), |
| 138 |
|
$this->identicalTo($request) |
| 139 |
|
)->willReturn(['lorem', 'ipsum']); |
| 140 |
|
|
| 141 |
|
/** @var string $expectedResponseContent */ |
| 142 |
|
$expectedResponseContent = "Service call completed"; |
| 143 |
|
|
| 144 |
|
$controller = new GenericServiceInvokeController( |
| 145 |
|
$this->controllerHelper, |
| 146 |
|
$this->argumentCompiler, |
| 147 |
|
$this->container, |
| 148 |
|
[ |
| 149 |
|
'service' => 'some_service', |
| 150 |
|
'method' => 'doFoo', |
| 151 |
|
'arguments' => ['lorem' => 'ipsum'] |
| 152 |
|
] |
| 153 |
|
); |
| 154 |
|
|
| 155 |
|
/** @var Response $actualResponse */ |
| 156 |
|
$actualResponse = $controller->callService($request); |
| 157 |
|
|
| 158 |
|
$this->assertEquals($expectedResponseContent, $actualResponse->getContent()); |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
/** |
| 162 |
|
* @test |
|
@@ 268-311 (lines=44) @@
|
| 265 |
|
/** |
| 266 |
|
* @test |
| 267 |
|
*/ |
| 268 |
|
public function shouldBeCallableByInvokingController() |
| 269 |
|
{ |
| 270 |
|
/** @var Request $request */ |
| 271 |
|
$request = $this->createMock(Request::class); |
| 272 |
|
|
| 273 |
|
/** @var SampleService $service */ |
| 274 |
|
$service = $this->createMock(SampleService::class); |
| 275 |
|
|
| 276 |
|
$service->expects($this->once())->method('doFoo')->with( |
| 277 |
|
$this->equalTo('lorem'), |
| 278 |
|
$this->equalTo('ipsum') |
| 279 |
|
); |
| 280 |
|
|
| 281 |
|
$this->container->expects($this->once())->method('get')->with( |
| 282 |
|
$this->equalTo('some_service') |
| 283 |
|
)->willReturn($service); |
| 284 |
|
|
| 285 |
|
$this->argumentCompiler->expects($this->once())->method('buildCallArguments')->with( |
| 286 |
|
$this->equalTo(new ReflectionMethod($service, 'doFoo')), |
| 287 |
|
$this->equalTo(['lorem' => 'ipsum']), |
| 288 |
|
$this->identicalTo($request) |
| 289 |
|
)->willReturn(['lorem', 'ipsum']); |
| 290 |
|
|
| 291 |
|
/** @var string $expectedResponseContent */ |
| 292 |
|
$expectedResponseContent = "Service call completed"; |
| 293 |
|
|
| 294 |
|
$controller = new GenericServiceInvokeController( |
| 295 |
|
$this->controllerHelper, |
| 296 |
|
$this->argumentCompiler, |
| 297 |
|
$this->container, |
| 298 |
|
[ |
| 299 |
|
'service' => 'some_service', |
| 300 |
|
'method' => 'doFoo', |
| 301 |
|
'arguments' => ['lorem' => 'ipsum'] |
| 302 |
|
] |
| 303 |
|
); |
| 304 |
|
|
| 305 |
|
$this->controllerHelper->method('getCurrentRequest')->willReturn($request); |
| 306 |
|
|
| 307 |
|
/** @var Response $actualResponse */ |
| 308 |
|
$actualResponse = $controller(); |
| 309 |
|
|
| 310 |
|
$this->assertEquals($expectedResponseContent, $actualResponse->getContent()); |
| 311 |
|
} |
| 312 |
|
|
| 313 |
|
/** |
| 314 |
|
* @test |