| @@ 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 | * @test |
|
| @@ 387-410 (lines=24) @@ | ||
| 384 | /** |
|
| 385 | * @test |
|
| 386 | */ |
|
| 387 | public function shouldRejectNonExistingFactory() |
|
| 388 | { |
|
| 389 | $controller = new GenericEntityCreateController( |
|
| 390 | $this->controllerHelper, |
|
| 391 | $this->argumentBuilder, |
|
| 392 | $this->container, |
|
| 393 | [ |
|
| 394 | 'entity-class' => SampleEntity::class, |
|
| 395 | 'factory' => '@some_factory_service::serialize' |
|
| 396 | ] |
|
| 397 | ); |
|
| 398 | ||
| 399 | $this->container->expects($this->once())->method('get')->with( |
|
| 400 | $this->equalTo('some_factory_service') |
|
| 401 | )->willReturn(null); |
|
| 402 | ||
| 403 | /** @var Request $request */ |
|
| 404 | $request = $this->createMock(Request::class); |
|
| 405 | ||
| 406 | $this->expectException(InvalidArgumentException::class); |
|
| 407 | $this->expectExceptionMessage("Did not find service 'some_factory_service'!"); |
|
| 408 | ||
| 409 | $controller->createEntity($request); |
|
| 410 | } |
|
| 411 | ||
| 412 | /** |
|
| 413 | * @test |
|
| @@ 438-463 (lines=26) @@ | ||
| 435 | /** |
|
| 436 | * @test |
|
| 437 | */ |
|
| 438 | public function shouldRejectNonExistingFactoryMethod() |
|
| 439 | { |
|
| 440 | $controller = new GenericEntityCreateController( |
|
| 441 | $this->controllerHelper, |
|
| 442 | $this->argumentBuilder, |
|
| 443 | $this->container, |
|
| 444 | [ |
|
| 445 | 'entity-class' => SampleEntity::class, |
|
| 446 | 'factory' => '@some_factory_service::MethodDoesNotExist' |
|
| 447 | ] |
|
| 448 | ); |
|
| 449 | ||
| 450 | /** @var Serializable $factoryMock */ |
|
| 451 | $factoryMock = $this->createMock(Serializable::class); |
|
| 452 | ||
| 453 | $this->container->expects($this->once())->method('get')->with( |
|
| 454 | $this->equalTo('some_factory_service') |
|
| 455 | )->willReturn($factoryMock); |
|
| 456 | ||
| 457 | /** @var Request $request */ |
|
| 458 | $request = $this->createMock(Request::class); |
|
| 459 | ||
| 460 | $this->expectException(ReflectionException::class); |
|
| 461 | ||
| 462 | $controller->createEntity($request); |
|
| 463 | } |
|
| 464 | ||
| 465 | /** |
|
| 466 | * @test |
|