Rised CodeCoverage of ActionService to 100%

This commit is contained in:
Kevin Frantz 2019-01-27 16:06:17 +01:00
parent 707df1b951
commit 2b1a3ad969
3 changed files with 64 additions and 15 deletions

View File

@ -10,7 +10,6 @@ use App\Domain\FormManagement\EntityFormBuilderServiceInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use App\Repository\RepositoryInterface; use App\Repository\RepositoryInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use App\Entity\EntityInterface;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
/** /**
@ -84,9 +83,11 @@ final class ActionService implements ActionServiceInterface
/** /**
* @return FormBuilderInterface * @return FormBuilderInterface
*/ */
public function getForm(EntityInterface $entity): FormBuilderInterface public function getForm(): FormBuilderInterface
{ {
$this->entityFormBuilderService->create($entity); $entity = $this->requestedAction->getRequestedEntity()->getEntity();
return $this->entityFormBuilderService->create($entity);
} }
/** /**

View File

@ -6,7 +6,6 @@ use App\Domain\RequestManagement\Action\RequestedActionInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use App\Repository\RepositoryInterface; use App\Repository\RepositoryInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use App\Entity\EntityInterface;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
/** /**
@ -37,11 +36,9 @@ interface ActionServiceInterface
public function getRepository(): RepositoryInterface; public function getRepository(): RepositoryInterface;
/** /**
* @param EntityInterface $entity
*
* @return FormBuilderInterface * @return FormBuilderInterface
*/ */
public function getForm(EntityInterface $entity): FormBuilderInterface; public function getForm(): FormBuilderInterface;
/** /**
* @return EntityManagerInterface * @return EntityManagerInterface

View File

@ -11,6 +11,12 @@ use App\Domain\FormManagement\EntityFormBuilderServiceInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface; use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
use App\Domain\ActionManagement\ActionServiceInterface; use App\Domain\ActionManagement\ActionServiceInterface;
use App\Repository\RepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use PHPUnit\Framework\MockObject\MockObject;
use App\Entity\EntityInterface;
use Symfony\Component\Form\FormBuilderInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -18,27 +24,27 @@ use App\Domain\ActionManagement\ActionServiceInterface;
class ActionServiceTest extends TestCase class ActionServiceTest extends TestCase
{ {
/** /**
* @var RequestedActionInterface * @var RequestedActionInterface|MockObject
*/ */
private $requestedAction; private $requestedAction;
/** /**
* @var SecureRequestedRightCheckerInterface * @var SecureRequestedRightCheckerInterface|MockObject
*/ */
private $secureRequestedRightChecker; private $secureRequestedRightChecker;
/** /**
* @var EntityFormBuilderServiceInterface * @var EntityFormBuilderServiceInterface|MockObject
*/ */
private $entityFormBuilderService; private $entityFormBuilderService;
/** /**
* @var RequestStack * @var RequestStack|MockObject
*/ */
private $requestStack; private $requestStack;
/** /**
* @var LayerRepositoryFactoryServiceInterface * @var LayerRepositoryFactoryServiceInterface|MockObject
*/ */
private $layerRepositoryFactoryService; private $layerRepositoryFactoryService;
@ -48,13 +54,29 @@ class ActionServiceTest extends TestCase
private $actionService; private $actionService;
/** /**
* @var EntityManagerInterface * @var EntityManagerInterface|MockObject
*/ */
private $entityManager; private $entityManager;
/**
* @var RequestedEntityInterface|MockObject
*/
private $requestedEntity;
/**
* @var EntityInterface|MockObject
*/
private $entity;
public function setUp(): void public function setUp(): void
{ {
$this->entity = $this->createMock(EntityInterface::class);
$this->requestedEntity = $this->createMock(RequestedEntityInterface::class);
$this->requestedEntity->method('getEntity')->willReturn($this->entity);
$this->requestedAction = $this->createMock(RequestedActionInterface::class); $this->requestedAction = $this->createMock(RequestedActionInterface::class);
$this->requestedAction->method('getRequestedEntity')->willReturn($this->requestedEntity);
$this->secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class); $this->secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class);
$this->entityFormBuilderService = $this->createMock(EntityFormBuilderServiceInterface::class); $this->entityFormBuilderService = $this->createMock(EntityFormBuilderServiceInterface::class);
$this->requestStack = $this->createMock(RequestStack::class); $this->requestStack = $this->createMock(RequestStack::class);
@ -63,14 +85,43 @@ class ActionServiceTest extends TestCase
$this->actionService = new ActionService($this->requestedAction, $this->secureRequestedRightChecker, $this->requestStack, $this->layerRepositoryFactoryService, $this->entityFormBuilderService, $this->entityManager); $this->actionService = new ActionService($this->requestedAction, $this->secureRequestedRightChecker, $this->requestStack, $this->layerRepositoryFactoryService, $this->entityFormBuilderService, $this->entityManager);
} }
public function testIsRequestedActionSecure() public function testIsRequestedActionSecure(): void
{ {
$this->secureRequestedRightChecker->method('check')->willReturn(true); $this->secureRequestedRightChecker->method('check')->willReturn(true);
$this->assertTrue($this->actionService->isRequestedActionSecure()); $this->assertTrue($this->actionService->isRequestedActionSecure());
} }
public function testRequestedActionGetter() public function testRequestedActionGetter(): void
{ {
$this->assertInstanceOf(RequestedActionInterface::class, $this->actionService->getRequestedAction()); $this->assertInstanceOf(RequestedActionInterface::class, $this->actionService->getRequestedAction());
} }
public function testGetEntityManager(): void
{
$this->assertEquals($this->entityManager, $this->actionService->getEntityManager());
}
public function testGetRepository(): void
{
$repository = $this->createMock(RepositoryInterface::class);
$this->layerRepositoryFactoryService->method('getRepository')->willReturn($repository);
$result = $this->actionService->getRepository();
$this->assertEquals($repository, $result);
}
public function testGetRequest(): void
{
$request = $this->createMock(Request::class);
$this->requestStack->method('getCurrentRequest')->willReturn($request);
$result = $this->actionService->getRequest();
$this->assertEquals($request, $result);
}
public function testGetForm(): void
{
$form = $this->createMock(FormBuilderInterface::class);
$this->entityFormBuilderService->method('create')->willReturn($form);
$result = $this->actionService->getForm();
$this->assertEquals($form, $result);
}
} }