infinito/application/symfony/tests/Unit/Domain/Parameter/ValidGetParameterServiceTest.php

87 lines
2.9 KiB
PHP
Raw Normal View History

2019-03-28 23:51:24 +01:00
<?php
namespace tests\Unit\Domain\Parameter;
2019-03-28 23:51:24 +01:00
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Infinito\Domain\Parameter\Parameter\VersionParameter;
use Infinito\Domain\Parameter\ParameterFactory;
use Infinito\Domain\Parameter\ValidGetParametersService;
2019-03-28 23:51:24 +01:00
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Infinito\Domain\Parameter\ValidGetParameterServiceInterface;
use Infinito\Domain\Parameter\Parameter\ViewParameter;
2019-03-29 00:29:03 +01:00
use Infinito\DBAL\Types\ActionType;
2019-04-15 01:37:17 +02:00
use Infinito\Exception\Collection\NotSetElementException;
use Infinito\Exception\Core\NotImplementedCoreException;
2019-03-28 23:51:24 +01:00
/**
* This class is a bit messed up because it is an recycled class of an other unit.
*
* @author kevinfrantz
*/
class ValidGetParameterServiceTest extends KernelTestCase
{
/**
* @var Request
*/
private $currentRequest;
/**
* @var RequestStack
*/
private $requestStack;
/**
2019-03-29 00:29:03 +01:00
* @var ValidGetParameterServiceInterface
2019-03-28 23:51:24 +01:00
*/
private $validGetParameterService;
public function setUp(): void
{
$this->currentRequest = new Request();
$this->requestStack = $this->createMock(RequestStack::class);
$this->requestStack->method('getCurrentRequest')->willReturn($this->currentRequest);
$parameterFactory = new ParameterFactory();
self::bootKernel();
$validator = self::$container->get(ValidatorInterface::class);
$this->validGetParameterService = new ValidGetParametersService($this->requestStack, $parameterFactory, $validator);
}
2019-03-29 00:29:03 +01:00
/**
* @todo Move this tests to the functional test section
*/
2019-03-28 23:51:24 +01:00
public function testHasAndGetParameter(): void
{
$parameterFactory = new ParameterFactory();
foreach ($parameterFactory->getAllParameters()->getKeys() as $key) {
$this->assertFalse($this->validGetParameterService->hasParameter($key));
switch ($key) {
case VersionParameter::getKey():
$value = 1;
break;
2019-03-29 00:29:03 +01:00
case ViewParameter::getKey():
$value = ActionType::EXECUTE;
break;
2019-03-28 23:51:24 +01:00
default:
$value = true;
}
$this->currentRequest->query->set($key, $value);
$this->assertTrue($this->validGetParameterService->hasParameter($key));
$this->assertEquals($value, $this->validGetParameterService->getParameter($key));
}
2019-04-15 01:37:17 +02:00
}
public function testNotImplementedException(): void
{
$this->expectException(NotImplementedCoreException::class);
2019-03-28 23:51:24 +01:00
$this->validGetParameterService->getParameter('12312312asdas');
}
2019-04-15 01:37:17 +02:00
public function testNotSetParameterException(): void
2019-03-28 23:51:24 +01:00
{
2019-04-15 01:37:17 +02:00
$this->expectException(NotSetElementException::class);
2019-03-28 23:51:24 +01:00
$this->validGetParameterService->getParameter(VersionParameter::getKey());
}
}