Code Duplication    Length = 23-26 lines in 3 locations

tests/unit/Controllers/API/GenericEntityListingControllerTest.php 1 location

@@ 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

tests/unit/Controllers/API/GenericEntityCreateControllerTest.php 2 locations

@@ 376-399 (lines=24) @@
373
    /**
374
     * @test
375
     */
376
    public function shouldRejectNonExistingFactory()
377
    {
378
        $controller = new GenericEntityCreateController(
379
            $this->controllerHelper,
380
            $this->argumentBuilder,
381
            $this->container,
382
            [
383
                'entity-class' => SampleEntity::class,
384
                'factory' => '@some_factory_service::serialize'
385
            ]
386
        );
387
388
        $this->container->expects($this->once())->method('get')->with(
389
            $this->equalTo('some_factory_service')
390
        )->willReturn(null);
391
392
        /** @var Request $request */
393
        $request = $this->createMock(Request::class);
394
395
        $this->expectException(InvalidArgumentException::class);
396
        $this->expectExceptionMessage("Did not find service 'some_factory_service'!");
397
398
        $controller->createEntity($request);
399
    }
400
401
    /**
402
     * @test
@@ 427-452 (lines=26) @@
424
    /**
425
     * @test
426
     */
427
    public function shouldRejectNonExistingFactoryMethod()
428
    {
429
        $controller = new GenericEntityCreateController(
430
            $this->controllerHelper,
431
            $this->argumentBuilder,
432
            $this->container,
433
            [
434
                'entity-class' => SampleEntity::class,
435
                'factory' => '@some_factory_service::MethodDoesNotExist'
436
            ]
437
        );
438
439
        /** @var Serializable $factoryMock */
440
        $factoryMock = $this->createMock(Serializable::class);
441
442
        $this->container->expects($this->once())->method('get')->with(
443
            $this->equalTo('some_factory_service')
444
        )->willReturn($factoryMock);
445
446
        /** @var Request $request */
447
        $request = $this->createMock(Request::class);
448
449
        $this->expectException(ReflectionException::class);
450
451
        $controller->createEntity($request);
452
    }
453
454
    /**
455
     * @test