mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2024-12-04 23:17:19 +01:00
Implemented view parameter
This commit is contained in:
parent
4114586b26
commit
fe84aaf92c
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\ParameterManagement\Parameter;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class ViewParameter extends AbstractParameter
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
* @Assert\Choice(callback={"Infinito\DBAL\Types\ActionType","getValues"})
|
||||
*/
|
||||
protected $value = null;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Integration\Domain\ParameterManagement\Parameter;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Infinito\Domain\ParameterManagement\Parameter\ViewParameter;
|
||||
use Infinito\DBAL\Types\ActionType;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class ViewParameterIntegrationTest extends KernelTestCase
|
||||
{
|
||||
public function testValidation()
|
||||
{
|
||||
self::bootKernel();
|
||||
$validator = self::$container->get(ValidatorInterface::class);
|
||||
$viewParameter = new ViewParameter();
|
||||
foreach (ActionType::getValues() as $value) {
|
||||
$this->assertNull($viewParameter->setValue($value));
|
||||
$this->assertEquals($value, $viewParameter->getValue());
|
||||
$errors = $validator->validate($viewParameter)->count();
|
||||
$this->assertEquals(0, $errors);
|
||||
}
|
||||
$viewParameter->setValue('abc');
|
||||
$errors = $validator->validate($viewParameter)->count();
|
||||
$this->assertGreaterThan(0, $errors);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\ParameterManagement\Parameter;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Domain\ParameterManagement\Parameter\ViewParameter;
|
||||
use Infinito\DBAL\Types\ActionType;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class ViewParameterTest extends TestCase
|
||||
{
|
||||
public function testKey(): void
|
||||
{
|
||||
$key = ViewParameter::getKey();
|
||||
$this->assertEquals('view', $key);
|
||||
$viewParameter = new ViewParameter();
|
||||
$this->assertEquals($key, $viewParameter::getKey());
|
||||
}
|
||||
|
||||
public function testAccessors(): void
|
||||
{
|
||||
$viewParameter = new ViewParameter();
|
||||
foreach (ActionType::getValues() as $value) {
|
||||
$this->assertNull($viewParameter->setValue($value));
|
||||
$this->assertEquals($value, $viewParameter->getValue());
|
||||
}
|
||||
}
|
||||
}
|
@ -4,13 +4,15 @@ namespace tests\Unit\Domain\ParameterManagement;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Infinito\Domain\ParameterManagement\OptionalGetParameterServiceInterface;
|
||||
use Infinito\Exception\NotDefinedException;
|
||||
use Infinito\Domain\ParameterManagement\Parameter\VersionParameter;
|
||||
use Infinito\Domain\ParameterManagement\ParameterFactory;
|
||||
use Infinito\Domain\ParameterManagement\ValidGetParametersService;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Infinito\Domain\ParameterManagement\ValidGetParameterServiceInterface;
|
||||
use Infinito\Domain\ParameterManagement\Parameter\ViewParameter;
|
||||
use Infinito\DBAL\Types\ActionType;
|
||||
|
||||
/**
|
||||
* This class is a bit messed up because it is an recycled class of an other unit.
|
||||
@ -30,7 +32,7 @@ class ValidGetParameterServiceTest extends KernelTestCase
|
||||
private $requestStack;
|
||||
|
||||
/**
|
||||
* @var OptionalGetParameterServiceInterface
|
||||
* @var ValidGetParameterServiceInterface
|
||||
*/
|
||||
private $validGetParameterService;
|
||||
|
||||
@ -45,6 +47,9 @@ class ValidGetParameterServiceTest extends KernelTestCase
|
||||
$this->validGetParameterService = new ValidGetParametersService($this->requestStack, $parameterFactory, $validator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Move this tests to the functional test section
|
||||
*/
|
||||
public function testHasAndGetParameter(): void
|
||||
{
|
||||
$parameterFactory = new ParameterFactory();
|
||||
@ -54,6 +59,9 @@ class ValidGetParameterServiceTest extends KernelTestCase
|
||||
case VersionParameter::getKey():
|
||||
$value = 1;
|
||||
break;
|
||||
case ViewParameter::getKey():
|
||||
$value = ActionType::EXECUTE;
|
||||
break;
|
||||
default:
|
||||
$value = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user