Add unit tests for SessionManager
This commit is contained in:
parent
fb6e98bb5c
commit
b9c84aeb27
1 changed files with 49 additions and 0 deletions
49
tests/Socialbox/Managers/SessionManagerTest.php
Normal file
49
tests/Socialbox/Managers/SessionManagerTest.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Socialbox\Managers;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Socialbox\Classes\Cryptography;
|
||||||
|
use Socialbox\Classes\Utilities;
|
||||||
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
use Socialbox\Objects\SessionRecord;
|
||||||
|
|
||||||
|
class SessionManagerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCreateSessionWithEmptyPublicKey(): void
|
||||||
|
{
|
||||||
|
$publicKey = '';
|
||||||
|
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
SessionManager::createSession($publicKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateSession(): void
|
||||||
|
{
|
||||||
|
$keyPair = Cryptography::generateKeyPair();
|
||||||
|
$uuid = SessionManager::createSession($keyPair->getPublicKey());
|
||||||
|
|
||||||
|
$this->assertTrue(SessionManager::sessionExists($uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetSessionWithInvalidUuid(): void
|
||||||
|
{
|
||||||
|
$uuid = 'invalid_uuid';
|
||||||
|
|
||||||
|
$this->expectException(DatabaseOperationException::class);
|
||||||
|
SessionManager::getSession($uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetSessionWithValidUuid(): void
|
||||||
|
{
|
||||||
|
$keyPair = Cryptography::generateKeyPair();
|
||||||
|
$uuid = SessionManager::createSession($keyPair->getPublicKey());
|
||||||
|
|
||||||
|
$session = SessionManager::getSession($uuid);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(SessionRecord::class, $session);
|
||||||
|
$this->assertEquals($uuid, $session->getUuid());
|
||||||
|
$this->assertEquals($keyPair->getPublicKey(), Utilities::base64encode($session->getPublicKey()));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue