<?php declare(strict_types=1);

namespace Apexl\Tests\User\FeatureTests;

use apexl\Io\modules\user\entities\userEntity;
use apexl\Io\modules\user\exceptions\SessionException;
use apexl\Io\modules\user\interfaces\SessionManagerInterface;
use apexl\Io\services\GlobalData;
use apexl\Io\TestInfrastructure\FeatureTest;
use DI\DependencyException;
use DI\NotFoundException;
use function apexl\Io\container;

final class DatabaseSessionManagerTest extends FeatureTest
{
    /**
     * @throws SessionException
     * @throws NotFoundException
     * @throws DependencyException
     */
    public function create(): void
    {
        $globalData = container()->make(GlobalData::class);
        $sessionManager = container()->make(SessionManagerInterface::class, [
            'globalData' => $globalData
        ]);

        $sessionId = '1234';

        $this->assertNull($sessionManager->current());

        $user = userEntity::factory()->create();

        $sessionManager->create($user->id, $sessionId);

        $this->assertSame($sessionId, $sessionManager->current()->sessionId);

        $data = $this->faker->text();
        $sessionManager->addDataToCurrentSession([
            'data' => $data,
        ]);

        $this->assertSame($data, $sessionManager->current()->data['data']);

    }

}
