| @@ 354-376 (lines=23) @@ | ||
| 351 | /** |
|
| 352 | * @test |
|
| 353 | */ |
|
| 354 | public function shouldRejectNonExistingFactory() |
|
| 355 | { |
|
| 356 | $controller = new GenericEntityCreateController( |
|
| 357 | $this->controllerHelper, |
|
| 358 | $this->argumentBuilder, |
|
| 359 | $this->container, |
|
| 360 | [ |
|
| 361 | 'entity-class' => SampleEntity::class, |
|
| 362 | 'factory' => '@some_factory_service::serialize' |
|
| 363 | ] |
|
| 364 | ); |
|
| 365 | ||
| 366 | $this->container->expects($this->once())->method('get')->with( |
|
| 367 | $this->equalTo('some_factory_service') |
|
| 368 | )->willReturn(null); |
|
| 369 | ||
| 370 | /** @var Request $request */ |
|
| 371 | $request = $this->createMock(Request::class); |
|
| 372 | ||
| 373 | $this->expectException(InvalidArgumentException::class); |
|
| 374 | ||
| 375 | $controller->createEntity($request); |
|
| 376 | } |
|
| 377 | ||
| 378 | /** |
|
| 379 | * @test |
|
| @@ 404-429 (lines=26) @@ | ||
| 401 | /** |
|
| 402 | * @test |
|
| 403 | */ |
|
| 404 | public function shouldRejectNonExistingFactoryMethod() |
|
| 405 | { |
|
| 406 | $controller = new GenericEntityCreateController( |
|
| 407 | $this->controllerHelper, |
|
| 408 | $this->argumentBuilder, |
|
| 409 | $this->container, |
|
| 410 | [ |
|
| 411 | 'entity-class' => SampleEntity::class, |
|
| 412 | 'factory' => '@some_factory_service::MethodDoesNotExist' |
|
| 413 | ] |
|
| 414 | ); |
|
| 415 | ||
| 416 | /** @var Serializable $factoryMock */ |
|
| 417 | $factoryMock = $this->createMock(Serializable::class); |
|
| 418 | ||
| 419 | $this->container->expects($this->once())->method('get')->with( |
|
| 420 | $this->equalTo('some_factory_service') |
|
| 421 | )->willReturn($factoryMock); |
|
| 422 | ||
| 423 | /** @var Request $request */ |
|
| 424 | $request = $this->createMock(Request::class); |
|
| 425 | ||
| 426 | $this->expectException(InvalidArgumentException::class); |
|
| 427 | ||
| 428 | $controller->createEntity($request); |
|
| 429 | } |
|
| 430 | ||
| 431 | /** |
|
| 432 | * @test |
|
| @@ 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 | ||