<?php

declare(strict_types=1);

namespace Ferienpass\AdminBundle\Tests\Form\Filter;

use Doctrine\ORM\QueryBuilder;
use Ferienpass\AdminBundle\Form\Filter\Attendance\PayableFilter;
use Ferienpass\AdminBundle\Form\Filter\Attendance\StatusFilter as AttendanceStatusFilter;
use Ferienpass\AdminBundle\Form\Filter\Attendance\UnpaidFilter;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

final class OtherFilterTypesTest extends TestCase
{
    // ---- Attendance/StatusFilter ----

    public function testAttendanceStatusFilterGetParent(): void
    {
        $translator = $this->createMock(TranslatorInterface::class);
        self::assertSame(ChoiceType::class, (new AttendanceStatusFilter($translator))->getParent());
    }

    public function testAttendanceStatusFilterApplyDoesNothingWhenEmpty(): void
    {
        $form = $this->createMock(FormInterface::class);
        $form->method('isEmpty')->willReturn(true);

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

        $translator = $this->createMock(TranslatorInterface::class);
        (new AttendanceStatusFilter($translator))->apply($qb, $form);
    }

    // ---- PayableFilter ----

    public function testPayableFilterGetParent(): void
    {
        self::assertSame(CheckboxType::class, (new PayableFilter())->getParent());
    }

    public function testPayableFilterApplyDoesNothingWhenFalse(): void
    {
        $form = $this->createMock(FormInterface::class);
        $form->method('getData')->willReturn(false);

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

        (new PayableFilter())->apply($qb, $form);
    }

    // ---- UnpaidFilter ----

    public function testUnpaidFilterGetParent(): void
    {
        self::assertSame(CheckboxType::class, (new UnpaidFilter())->getParent());
    }

    public function testUnpaidFilterApplyDoesNothingWhenFalse(): void
    {
        $form = $this->createMock(FormInterface::class);
        $form->method('getData')->willReturn(false);

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

        (new UnpaidFilter())->apply($qb, $form);
    }
}
