<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Tests\Facade;

use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\QueryBuilder;
use Ferienpass\CoreBundle\Facade\PaymentsFacade;
use Ferienpass\CoreBundle\Repository\AttendanceRepository;
use PHPUnit\Framework\TestCase;

final class PaymentsFacadeTest extends TestCase
{
    public function testConstructWithRepository(): void
    {
        $repo = $this->createStub(AttendanceRepository::class);
        $facade = new PaymentsFacade($repo);

        self::assertInstanceOf(PaymentsFacade::class, $facade);
    }

    public function testAddWhereLogicAppliesCorrectConditions(): void
    {
        $qb = $this->createMock(QueryBuilder::class);
        // paid, payable and the season's usePayments.
        $qb->expects(self::exactly(3))
            ->method('andWhere')
            ->willReturnSelf();
        $qb->expects(self::exactly(2))
            ->method('leftJoin')
            ->willReturnSelf();

        PaymentsFacade::addWhereLogic($qb);
    }

    public function testAddCriteriaAppliesPaidAndPayableConditions(): void
    {
        $criteria = new Criteria();
        PaymentsFacade::addCriteria($criteria);

        // Criteria should now have a where expression
        self::assertNotNull($criteria->getWhereExpression());
    }
}
