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

use Ferienpass\CmsBundle\Message\LoginLinkHelpRequested;
use Ferienpass\CmsBundle\NotificationHandler\LoginLinkHelp;
use Ferienpass\CoreBundle\Notification\LoginLinkHelpNotification;
use Ferienpass\CoreBundle\Notifier\Notifier;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Recipient\Recipient;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\Translation\TranslatorInterface;

final class LoginLinkHelpTest extends TestCase
{
    public function testSendsHelpMailToTheEnteredAddress(): void
    {
        $notifier = $this->createMock(Notifier::class);
        $notifier->expects(self::once())->method('send')
            ->with(
                self::isInstanceOf(LoginLinkHelpNotification::class),
                self::callback(static fn (Recipient $r): bool => 'unknown@example.com' === $r->getEmail()),
            );

        $handler = new LoginLinkHelp(
            $notifier,
            new LoginLinkHelpNotification(),
            $this->createMock(TranslatorInterface::class),
        );
        $handler(new LoginLinkHelpRequested('unknown@example.com'), Uuid::v7());
    }

    public function testDoesNothingWhenEmailIsEmpty(): void
    {
        $notifier = $this->createMock(Notifier::class);
        $notifier->expects(self::never())->method('send');

        $handler = new LoginLinkHelp(
            $notifier,
            new LoginLinkHelpNotification(),
            $this->createMock(TranslatorInterface::class),
        );
        $handler(new LoginLinkHelpRequested(''), Uuid::v7());
    }
}
