<?php

declare(strict_types=1);

namespace Apexl\Tests\User\UnitTests;

use apexl\Io\interfaces\GlobalDataInterface;
use apexl\Io\modules\user\entities\userEntity;
use apexl\Io\modules\user\services\CurrentUserFactory;
use apexl\Io\TestInfrastructure\UnitTest;
use PHPUnit\Framework\Attributes\Test;
use function apexl\Io\container;

final class CurrentUserFactoryTest extends UnitTest
{
    #[Test]
    public function getCurrentUser(): void
    {
        $globalData = container()->make(GlobalDataInterface::class);

        /** @noinspection PhpUnhandledExceptionInspection */
        $factory = container()->make(CurrentUserFactory::class, [
            'globalData' => $globalData,
        ]);

        $this->assertNull($factory->get());

        $userName = 'TestUser';
        $user = new userEntity();
        $user->first_name = $userName;

        $globalData->addData('entities', data: ['user' => ['entity' => $user]]);

        $this->assertSame($userName, $factory->get()->first_name);

    }
}