| @@ 193-215 (lines=23) @@ | ||
| 190 | /** |
|
| 191 | * @test |
|
| 192 | */ |
|
| 193 | public function shouldCheckIfAccessIsGranted() |
|
| 194 | { |
|
| 195 | /** @var Request $request */ |
|
| 196 | $request = $this->createMock(Request::class); |
|
| 197 | ||
| 198 | $this->expectException(AccessDeniedException::class); |
|
| 199 | ||
| 200 | $this->controllerHelper->expects($this->once())->method('denyAccessUnlessGranted')->with( |
|
| 201 | $this->equalTo('some-attribute'), |
|
| 202 | $this->identicalTo($request) |
|
| 203 | )->will($this->returnCallback( |
|
| 204 | function () { |
|
| 205 | throw new AccessDeniedException('Lorem ipsum!'); |
|
| 206 | } |
|
| 207 | )); |
|
| 208 | ||
| 209 | $controller = new GenericEntityListingController($this->controllerHelper, $this->argumentCompiler, [ |
|
| 210 | 'entity-class' => SampleEntity::class, |
|
| 211 | 'authorization-attribute' => 'some-attribute', |
|
| 212 | ]); |
|
| 213 | ||
| 214 | $controller->listEntities($request); |
|
| 215 | } |
|
| 216 | ||
| 217 | } |
|
| 218 | ||
| @@ 337-360 (lines=24) @@ | ||
| 334 | /** |
|
| 335 | * @test |
|
| 336 | */ |
|
| 337 | public function shouldRejectNonExistingFactory() |
|
| 338 | { |
|
| 339 | $controller = new GenericEntityCreateController( |
|
| 340 | $this->controllerHelper, |
|
| 341 | $this->argumentBuilder, |
|
| 342 | $this->container, |
|
| 343 | [ |
|
| 344 | 'entity-class' => SampleEntity::class, |
|
| 345 | 'factory' => '@some_factory_service::serialize' |
|
| 346 | ] |
|
| 347 | ); |
|
| 348 | ||
| 349 | $this->container->expects($this->once())->method('get')->with( |
|
| 350 | $this->equalTo('some_factory_service') |
|
| 351 | )->willReturn(null); |
|
| 352 | ||
| 353 | /** @var Request $request */ |
|
| 354 | $request = $this->createMock(Request::class); |
|
| 355 | ||
| 356 | $this->expectException(InvalidArgumentException::class); |
|
| 357 | $this->expectExceptionMessage("Did not find service 'some_factory_service'!"); |
|
| 358 | ||
| 359 | $controller->createEntity($request); |
|
| 360 | } |
|
| 361 | ||
| 362 | /** |
|
| 363 | * @test |
|
| @@ 388-413 (lines=26) @@ | ||
| 385 | /** |
|
| 386 | * @test |
|
| 387 | */ |
|
| 388 | public function shouldRejectNonExistingFactoryMethod() |
|
| 389 | { |
|
| 390 | $controller = new GenericEntityCreateController( |
|
| 391 | $this->controllerHelper, |
|
| 392 | $this->argumentBuilder, |
|
| 393 | $this->container, |
|
| 394 | [ |
|
| 395 | 'entity-class' => SampleEntity::class, |
|
| 396 | 'factory' => '@some_factory_service::MethodDoesNotExist' |
|
| 397 | ] |
|
| 398 | ); |
|
| 399 | ||
| 400 | /** @var Serializable $factoryMock */ |
|
| 401 | $factoryMock = $this->createMock(Serializable::class); |
|
| 402 | ||
| 403 | $this->container->expects($this->once())->method('get')->with( |
|
| 404 | $this->equalTo('some_factory_service') |
|
| 405 | )->willReturn($factoryMock); |
|
| 406 | ||
| 407 | /** @var Request $request */ |
|
| 408 | $request = $this->createMock(Request::class); |
|
| 409 | ||
| 410 | $this->expectException(ReflectionException::class); |
|
| 411 | ||
| 412 | $controller->createEntity($request); |
|
| 413 | } |
|
| 414 | ||
| 415 | /** |
|
| 416 | * @test |
|