engelsystem/tests/Unit/Models/SessionTest.php

44 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2023-09-17 14:55:02 +02:00
<?php
declare(strict_types=1);
namespace Engelsystem\Test\Unit\Models;
use Engelsystem\Helpers\Carbon;
use Engelsystem\Models\Session;
2023-09-17 15:03:56 +02:00
use Engelsystem\Models\User\User;
2023-09-17 14:55:02 +02:00
/**
* This class provides tests for the Session model
*/
class SessionTest extends ModelTest
{
/**
* Tests that a Session can be created and loaded
*
* @covers \Engelsystem\Models\Session
*/
public function testCreate(): void
{
2023-09-17 15:03:56 +02:00
$user = User::factory()->create();
2023-09-17 14:55:02 +02:00
Session::create([
'id' => 'foo',
'payload' => 'lorem ipsum',
2023-09-17 15:03:56 +02:00
'user_id' => $user->id,
2023-09-17 14:55:02 +02:00
'last_activity' => Carbon::now(),
]);
Session::create([
'id' => 'bar',
'last_activity' => Carbon::now(),
]);
$session = Session::find('foo');
$this->assertNotNull($session);
$this->assertEquals('lorem ipsum', $session->payload);
2023-09-17 15:03:56 +02:00
$this->assertInstanceOf(User::class, $session->user);
$session = Session::find('bar');
$this->assertNull($session->user);
2023-09-17 14:55:02 +02:00
}
}