<?php

declare(strict_types=1);

namespace Ferienpass\AdminBundle\Tests\List;

use Doctrine\ORM\QueryBuilder;
use Ferienpass\AdminBundle\List\ListCriteriaApplier;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\Form\FormFactoryInterface;

final class ListCriteriaApplierTest extends TestCase
{
    public function testApplyDoesNothingWithNoQueryNoFilterType(): void
    {
        $formFactory = $this->createMock(FormFactoryInterface::class);
        $formFactory->expects(self::never())->method('create');

        $filters = $this->createMock(ServiceLocator::class);
        $filters->expects(self::never())->method('get');

        $qb = $this->createMock(QueryBuilder::class);
        $qb->expects(self::never())->method('andWhere');

        $applier = new ListCriteriaApplier($formFactory, $filters);
        $applier->apply($qb, null, [], null, null);
    }

    public function testApplySkipsFilterWhenTypeNotInLocator(): void
    {
        $formFactory = $this->createMock(FormFactoryInterface::class);
        $formFactory->expects(self::never())->method('create');

        $filters = $this->createMock(ServiceLocator::class);
        $filters->method('has')->with('unknown_filter')->willReturn(false);
        $filters->expects(self::never())->method('get');

        $qb = $this->createMock(QueryBuilder::class);
        $qb->expects(self::never())->method('andWhere');

        $applier = new ListCriteriaApplier($formFactory, $filters);
        $applier->apply($qb, 'unknown_filter', [], null, null);
    }
}
