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

use Ferienpass\CoreBundle\RemoteEvent\PmPaymentWebhookConsumer;
use Ferienpass\CoreBundle\Webhook\PmPaymentNotifyEvent;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\RemoteEvent\RemoteEvent;

final class PmPaymentWebhookConsumerTest extends TestCase
{
    public function testConsumeDoesNothingForNonPmPaymentEvent(): void
    {
        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects(self::never())->method('dispatch');

        $consumer = new PmPaymentWebhookConsumer($bus);
        $consumer->consume(new RemoteEvent('other', 'id123', []));
    }

    public function testConsumeDispatchesMessageForPmPaymentEvent(): void
    {
        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects(self::once())->method('dispatch')->willReturn(new Envelope(new \stdClass()));

        $consumer = new PmPaymentWebhookConsumer($bus);
        $consumer->consume(new PmPaymentNotifyEvent('TX-001', 1, ['ags' => 'AGS1', 'txid' => 'TX-001', 'status' => 1]));
    }
}
