<?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\Cron;

use Contao\CoreBundle\Cron\Cron;
use Doctrine\ORM\EntityManagerInterface;
use Ferienpass\CoreBundle\Cron\NotifyApplicationsClosed;
use Ferienpass\CoreBundle\Cron\NotifyOfferComplete;
use Ferienpass\CoreBundle\Cron\RefetchPmPaymentTransactionStatuses;
use Ferienpass\CoreBundle\Cron\TruncatePayments;
use Ferienpass\CoreBundle\Cron\TruncateUnactivatedUsers;
use Ferienpass\CoreBundle\Repository\OfferRepositoryInterface;
use Ferienpass\CoreBundle\Repository\PaymentRepository;
use Ferienpass\CoreBundle\Repository\UserRepository;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Workflow\WorkflowInterface;

final class CronScopeWebTest extends TestCase
{
    public function testTruncateUnactivatedUsersReturnsEarlyOnWebScope(): void
    {
        $users = $this->createMock(UserRepository::class);
        $users->expects(self::never())->method('createQueryBuilder');

        $cron = new TruncateUnactivatedUsers($users);
        $cron(Cron::SCOPE_WEB);
    }

    public function testNotifyApplicationsClosedReturnsEarlyOnWebScope(): void
    {
        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects(self::never())->method('dispatch');

        $cron = new NotifyApplicationsClosed($this->createMock(OfferRepositoryInterface::class), $bus);
        $cron(Cron::SCOPE_WEB);
    }

    public function testNotifyOfferCompleteReturnsEarlyOnWebScope(): void
    {
        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects(self::never())->method('dispatch');

        $cron = new NotifyOfferComplete($this->createMock(OfferRepositoryInterface::class), $bus, $this->createMock(WorkflowInterface::class));
        $cron(Cron::SCOPE_WEB);
    }

    public function testTruncatePaymentsReturnsEarlyOnWebScope(): void
    {
        $payments = $this->createMock(PaymentRepository::class);
        $payments->expects(self::never())->method('createQueryBuilder');

        $em = $this->createMock(EntityManagerInterface::class);
        $em->expects(self::never())->method('flush');

        $cron = new TruncatePayments($payments, $this->createMock(WorkflowInterface::class), $em);
        $cron(Cron::SCOPE_WEB);
    }

    public function testRefetchPmPaymentTransactionStatusesReturnsEarlyOnWebScope(): void
    {
        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects(self::never())->method('dispatch');

        $em = $this->createMock(EntityManagerInterface::class);
        $payments = $this->createMock(PaymentRepository::class);
        $payments->expects(self::never())->method('createQueryBuilder');

        $cron = new RefetchPmPaymentTransactionStatuses($em, $bus, $payments);
        $cron(Cron::SCOPE_WEB);
    }
}
