taktik-nette
This commit is contained in:
64
tests/Unit/UI/DTO/FilterDTOTest.php
Normal file
64
tests/Unit/UI/DTO/FilterDTOTest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\UI\DTO\FilterDTO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FilterDTOTest extends TestCase
|
||||
{
|
||||
public function testCreateFromInvalidDataWithAcceptedFilters(): void
|
||||
{
|
||||
$data = [
|
||||
'name' => 'John',
|
||||
'age' => 30,
|
||||
'invalid_key' => 'should not be included',
|
||||
];
|
||||
|
||||
$acceptFilters = ['name', 'age'];
|
||||
|
||||
$filterDTO = FilterDTO::createFromData($data, $acceptFilters);
|
||||
|
||||
$this->assertInstanceOf(FilterDTO::class, $filterDTO);
|
||||
$this->assertSame(
|
||||
[
|
||||
'name' => 'John',
|
||||
'age' => 30,
|
||||
],
|
||||
$filterDTO->filters
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateFromInvalidDataWithNoAcceptedFilters(): void
|
||||
{
|
||||
$data = [
|
||||
'name' => 'John',
|
||||
'age' => 30,
|
||||
'invalid_key' => 'should not be included',
|
||||
];
|
||||
|
||||
$acceptFilters = [];
|
||||
|
||||
$filterDTO = FilterDTO::createFromData($data, $acceptFilters);
|
||||
|
||||
$this->assertInstanceOf(FilterDTO::class, $filterDTO);
|
||||
$this->assertSame([], $filterDTO->filters);
|
||||
}
|
||||
|
||||
public function testCreateFromInvalidDataWithoutMatchingKeys(): void
|
||||
{
|
||||
$data = [
|
||||
'invalid_key1' => 'value1',
|
||||
'invalid_key2' => 'value2',
|
||||
];
|
||||
|
||||
$acceptFilters = ['name', 'age'];
|
||||
|
||||
$filterDTO = FilterDTO::createFromData($data, $acceptFilters);
|
||||
|
||||
$this->assertInstanceOf(FilterDTO::class, $filterDTO);
|
||||
$this->assertSame([], $filterDTO->filters);
|
||||
}
|
||||
}
|
||||
58
tests/Unit/UI/DTO/OrderDTOTest.php
Normal file
58
tests/Unit/UI/DTO/OrderDTOTest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\UI\DTO\OrderDirection;
|
||||
use App\UI\DTO\OrderDTO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class OrderDTOTest extends TestCase
|
||||
{
|
||||
public function testCreateOrReturnNullFromInvalidDataWithValidInputs(): void
|
||||
{
|
||||
$acceptFilters = ['name', 'created_at'];
|
||||
$order = 'name';
|
||||
$direction = 'ASC';
|
||||
|
||||
$orderDTO = OrderDTO::createOrReturnNullFromData($order, $direction, $acceptFilters);
|
||||
|
||||
$this->assertInstanceOf(OrderDTO::class, $orderDTO);
|
||||
$this->assertSame($order, $orderDTO->column);
|
||||
$this->assertSame(OrderDirection::ASC, $orderDTO->direction);
|
||||
}
|
||||
|
||||
public function testCreateOrReturnNullFromInvalidDataWithInvalidOrder(): void
|
||||
{
|
||||
$acceptFilters = ['name', 'created_at'];
|
||||
$order = 'invalid_column';
|
||||
$direction = 'ASC';
|
||||
|
||||
$orderDTO = OrderDTO::createOrReturnNullFromData($order, $direction, $acceptFilters);
|
||||
|
||||
$this->assertNull($orderDTO);
|
||||
}
|
||||
|
||||
public function testCreateOrReturnNullFromInvalidDataWithInvalidDirection(): void
|
||||
{
|
||||
$acceptFilters = ['name', 'created_at'];
|
||||
$order = 'name';
|
||||
$direction = 'INVALID_DIRECTION';
|
||||
|
||||
$orderDTO = OrderDTO::createOrReturnNullFromData($order, $direction, $acceptFilters);
|
||||
|
||||
$this->assertNull($orderDTO);
|
||||
}
|
||||
|
||||
public function testCreateOrReturnNullFromInvalidDataWithEmptyFilters(): void
|
||||
{
|
||||
$acceptFilters = [];
|
||||
$order = 'name';
|
||||
$direction = 'ASC';
|
||||
|
||||
$orderDTO = OrderDTO::createOrReturnNullFromData($order, $direction, $acceptFilters);
|
||||
|
||||
$this->assertNull($orderDTO);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user