mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-04-16 10:16:22 +02:00
In between commit optimation parameters
This commit is contained in:
parent
341ff5d5df
commit
2d7ef06ef6
@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use HaydenPierce\ClassFinder\ClassFinder;
|
use HaydenPierce\ClassFinder\ClassFinder;
|
||||||
use Infinito\Domain\ParameterManagement\Parameter\ParameterInterface;
|
use Infinito\Domain\ParameterManagement\Parameter\ParameterInterface;
|
||||||
|
use Infinito\Exception\NoValidChoiceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
@ -62,7 +63,11 @@ final class ParameterFactory implements ParameterFactoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getParameter(string $key): ParameterInterface
|
public function getParameter(string $key): ParameterInterface
|
||||||
{
|
{
|
||||||
return $this->parameters->get($key);
|
$parameter = $this->parameters->get($key);
|
||||||
|
if($parameter){
|
||||||
|
return $parameter;
|
||||||
|
}
|
||||||
|
throw new NoValidChoiceException("The parameter for key <<$key>> doesn't exist!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace tests\Unit\Domain\ParameterManagement;
|
||||||
|
|
||||||
|
use Infinito\Domain\ParameterManagement\OptionalGetParameterService;
|
||||||
|
use Infinito\Domain\ParameterManagement\OptionalGetParameterServiceInterface;
|
||||||
|
use Infinito\Domain\ParameterManagement\ParameterFactory;
|
||||||
|
use Infinito\Domain\ParameterManagement\ValidGetParametersService;
|
||||||
|
use Infinito\Exception\NotDefinedException;
|
||||||
|
use Infinito\Exception\UnvalidParameterException;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
use Infinito\Domain\ParameterManagement\ValidGetParameterServiceInterface;
|
||||||
|
use Infinito\Domain\ParameterManagement\Parameter\VersionParameter;
|
||||||
|
use Infinito\Domain\ParameterManagement\ParameterFactoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kevinfrantz
|
||||||
|
*/
|
||||||
|
class ValidGetParameterServiceTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Request
|
||||||
|
*/
|
||||||
|
private $currentRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var RequestStack
|
||||||
|
*/
|
||||||
|
private $requestStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var ValidGetParameterServiceInterface
|
||||||
|
*/
|
||||||
|
private $validGetParameterService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var ParameterFactoryInterface
|
||||||
|
*/
|
||||||
|
private $parameterFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var ValidatorInterface
|
||||||
|
*/
|
||||||
|
private $validator;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
$this->currentRequest = new Request();
|
||||||
|
$this->requestStack = $this->createMock(RequestStack::class);
|
||||||
|
$this->requestStack->method('getCurrentRequest')->willReturn($this->currentRequest);
|
||||||
|
$this->parameterFactory = new ParameterFactory();
|
||||||
|
$this->validator = self::$container->get(ValidatorInterface::class);
|
||||||
|
$this->validGetParameterService = new ValidGetParametersService($this->requestStack, $this->parameterFactory, $this->validator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConstructor(): void
|
||||||
|
{
|
||||||
|
$this->expectException(UnvalidParameterException::class);
|
||||||
|
$this->currentRequest->query->set('asdwgwe', 'adasa');
|
||||||
|
new ValidGetParametersService($this->requestStack, $this->parameterFactory, $this->validator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetParameterException(): void
|
||||||
|
{
|
||||||
|
$this->expectException(NotDefinedException::class);
|
||||||
|
$this->validGetParameterService->getParameter(VersionParameter::getKey());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user