2019-01-29 21:01:01 +01:00
|
|
|
<?php
|
|
|
|
|
2019-05-30 16:20:42 +02:00
|
|
|
namespace tests\Unit\Domain\Map;
|
2019-01-29 21:01:01 +01:00
|
|
|
|
2020-04-02 21:13:35 +02:00
|
|
|
use Infinito\DBAL\Types\ActionType;
|
|
|
|
use Infinito\Domain\Map\ActionHttpMethodMap;
|
2019-01-29 21:01:01 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author kevinfrantz
|
|
|
|
*/
|
|
|
|
class ActionHttpMethodTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param array|string[] $subset
|
|
|
|
* @param array $haystack|string[]
|
|
|
|
*/
|
|
|
|
private function assertSubsetInArray(array $subset, array $haystack, bool $expectedResult)
|
|
|
|
{
|
|
|
|
foreach ($subset as $value) {
|
|
|
|
$this->assertEquals($expectedResult, in_array($value, $haystack));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateActionTrue(): void
|
|
|
|
{
|
2019-02-19 19:36:02 +01:00
|
|
|
$subset = [Request::METHOD_POST, Request::METHOD_HEAD];
|
2019-01-29 21:01:01 +01:00
|
|
|
$action = ActionType::CREATE;
|
|
|
|
$haystack = ActionHttpMethodMap::getHttpMethods($action);
|
|
|
|
$this->assertSubsetInArray($subset, $haystack, true);
|
|
|
|
$this->assertEquals(2, count($haystack));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateActionFalse(): void
|
|
|
|
{
|
2019-02-19 19:36:02 +01:00
|
|
|
$subset = [Request::METHOD_POST, Request::METHOD_HEAD];
|
2019-01-29 21:01:01 +01:00
|
|
|
$action = 'wrong value';
|
|
|
|
$haystack = ActionHttpMethodMap::getHttpMethods($action);
|
|
|
|
$this->assertSubsetInArray($subset, $haystack, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPostMethodTrue(): void
|
|
|
|
{
|
|
|
|
$subset = [ActionType::READ];
|
|
|
|
$httpMethod = Request::METHOD_GET;
|
|
|
|
$haystack = ActionHttpMethodMap::getActions($httpMethod);
|
|
|
|
$this->assertSubsetInArray($subset, $haystack, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPostMethodFalse(): void
|
|
|
|
{
|
|
|
|
$subset = [ActionType::READ];
|
|
|
|
$httpMethod = 'wrong value';
|
|
|
|
$haystack = ActionHttpMethodMap::getActions($httpMethod);
|
|
|
|
$this->assertSubsetInArray($subset, $haystack, false);
|
|
|
|
}
|
|
|
|
}
|