59 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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);
 | 
						|
    }
 | 
						|
}
 |