infinito/application/symfony/tests/Integration/Domain/ParameterManagement/ValidGetParameterServiceTest.php

88 lines
2.8 KiB
PHP
Raw Normal View History

<?php
2019-03-28 23:51:24 +01:00
namespace tests\Integration\Domain\ParameterManagement;
use Infinito\Domain\ParameterManagement\ParameterFactory;
use Infinito\Domain\ParameterManagement\ValidGetParametersService;
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;
use Infinito\Exception\Validation\GetParameterInvalidException;
use Infinito\Exception\Collection\NotSetElementException;
/**
* @author kevinfrantz
*/
class ValidGetParameterServiceTest extends KernelTestCase
{
/**
* @var Request
*/
private $currentRequest;
/**
* @var RequestStack
*/
private $requestStack;
/**
* @var ValidGetParameterServiceInterface
*/
private $validGetParameterService;
/**
* @var ParameterFactoryInterface
*/
private $parameterFactory;
2019-03-28 21:20:21 +01:00
/**
* @var ValidatorInterface
*/
private $validator;
2019-03-28 21:20:21 +01:00
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);
}
2019-03-28 21:20:21 +01:00
public function testVersionCorrectType(): void
{
$key = VersionParameter::getKey();
$value = 123;
$this->currentRequest->query->set($key, $value);
$result = $this->validGetParameterService->getParameter($key);
$this->assertEquals($value, $result);
}
public function testVersionWrongType(): void
{
$versionKey = VersionParameter::getKey();
$this->currentRequest->query->set($versionKey, 'adasdas');
$this->expectException(GetParameterInvalidException::class);
$this->validGetParameterService->getParameter($versionKey);
2019-03-28 21:20:21 +01:00
}
public function testConstructor(): void
{
$this->currentRequest->query->set('asdwgwe', 'adasa');
$this->expectException(GetParameterInvalidException::class);
new ValidGetParametersService($this->requestStack, $this->parameterFactory, $this->validator);
}
public function testSetParameterException(): void
{
$this->expectException(NotSetElementException::class);
$this->validGetParameterService->getParameter(VersionParameter::getKey());
}
}