<?php

declare(strict_types=1);

namespace Ferienpass\CoreBundle\Tests\EventListener;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Ferienpass\CoreBundle\Entity\Attendance;
use Ferienpass\CoreBundle\EventListener\Doctrine\Attendance\AttendanceLogListener;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security;

final class AttendanceLogListenerTest extends TestCase
{
    public function testPreUpdateReturnsEarlyWhenStatusFieldNotChanged(): void
    {
        $security = $this->createMock(Security::class);
        $security->expects(self::never())->method('getUser');

        $attendance = $this->createMock(Attendance::class);
        $attendance->expects(self::never())->method('getActivity');

        $changeSet = ['name' => ['old_name', 'new_name']];
        $args = new PreUpdateEventArgs($attendance, $this->createMock(EntityManagerInterface::class), $changeSet);

        $listener = new AttendanceLogListener($security);
        $listener->preUpdate($attendance, $args);
    }

    public function testPreUpdateReturnsEarlyWhenNewStatusIsNull(): void
    {
        $security = $this->createMock(Security::class);
        $security->expects(self::never())->method('getUser');

        $attendance = $this->createMock(Attendance::class);
        $attendance->expects(self::never())->method('getActivity');

        $changeSet = ['status' => ['old_status', null]];
        $args = new PreUpdateEventArgs($attendance, $this->createMock(EntityManagerInterface::class), $changeSet);

        $listener = new AttendanceLogListener($security);
        $listener->preUpdate($attendance, $args);
    }
}
