infinito/application/symfony/tests/Integration/Domain/Parameter/ValidGetParameterServiceIntegrationTest.php

96 lines
3.2 KiB
PHP
Raw Permalink Normal View History

<?php
namespace tests\Integration\Domain\Parameter;
2020-04-02 21:13:35 +02:00
use Infinito\Domain\Parameter\Parameter\VersionParameter;
use Infinito\Domain\Parameter\ParameterFactory;
2020-04-02 21:13:35 +02:00
use Infinito\Domain\Parameter\ParameterFactoryInterface;
use Infinito\Domain\Parameter\ValidGetParameterServiceInterface;
use Infinito\Domain\Parameter\ValidGetParametersService;
2020-04-02 21:13:35 +02:00
use Infinito\Exception\Collection\NotSetElementException;
use Infinito\Exception\Core\NotImplementedCoreException;
use Infinito\Exception\Validation\GetParameterInvalidException;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* @author kevinfrantz
*/
2019-04-15 01:37:17 +02:00
class ValidGetParameterServiceIntegrationTest 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
}
2019-04-15 01:37:17 +02:00
public function testConstructorInvalid(): void
{
2019-04-15 01:37:17 +02:00
$this->currentRequest->query->set(VersionParameter::getKey(), 'adasa');
$this->expectException(GetParameterInvalidException::class);
new ValidGetParametersService($this->requestStack, $this->parameterFactory, $this->validator);
}
2019-04-15 01:37:17 +02:00
public function testConstructorNotImplemented(): void
{
$this->currentRequest->query->set('asdwgwe', 'adasa');
$this->expectException(NotImplementedCoreException::class);
new ValidGetParametersService($this->requestStack, $this->parameterFactory, $this->validator);
}
public function testSetParameterException(): void
{
$this->expectException(NotSetElementException::class);
$this->validGetParameterService->getParameter(VersionParameter::getKey());
}
}