<?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\CmsBundle\Tests\Application\ExclusionReasons;

use Contao\CoreBundle\OptIn\OptInInterface;
use Doctrine\DBAL\Connection;
use Ferienpass\CmsBundle\Application\ExclusionReasonEvent;
use Ferienpass\CmsBundle\Application\ExclusionReasons\UnconfirmedListener;
use Ferienpass\CoreBundle\ApplicationSystem\ApplicationSystemInterface;
use Ferienpass\CoreBundle\Entity\Offer\OfferInterface;
use Ferienpass\CoreBundle\Entity\Participant\ParticipantInterface;
use Ferienpass\CoreBundle\Entity\User;
use PHPUnit\Framework\TestCase;

final class UnconfirmedListenerTest extends TestCase
{
    public function testReturnsEarlyWhenParticipantHasUser(): void
    {
        $connection = $this->createMock(Connection::class);
        $connection->expects(self::never())->method('executeQuery');

        $optIn = $this->createMock(OptInInterface::class);

        $participant = $this->createMock(ParticipantInterface::class);
        $participant->method('getUser')->willReturn(new User());

        $event = new ExclusionReasonEvent(
            $this->createMock(OfferInterface::class),
            $participant,
            $this->createMock(ApplicationSystemInterface::class)
        );

        $listener = new UnconfirmedListener($connection, $optIn);
        $listener($event);

        $this->addToAssertionCount(1);
    }
}
