|
|
|
|
@ -4,53 +4,53 @@ use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
|
|
use BradyMcD\TAATP\Session\Base as BaseSession;
|
|
|
|
|
|
|
|
|
|
/** @SuppressWarnings(PHPMD.ShortVariable)*/
|
|
|
|
|
final class SessionTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
public function testSessionIsLive(): void
|
|
|
|
|
private static $session;
|
|
|
|
|
|
|
|
|
|
private static $k1;
|
|
|
|
|
private static $v1;
|
|
|
|
|
private static $v2;
|
|
|
|
|
|
|
|
|
|
public static function setUpBeforeClass(): void
|
|
|
|
|
{
|
|
|
|
|
$session = new BaseSession();
|
|
|
|
|
self::$session = new BaseSession();
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($session->live());
|
|
|
|
|
self::$k1 = 'testKey';
|
|
|
|
|
self::$v1 = 'some important data';
|
|
|
|
|
self::$v2 = 'some other more or less important data';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testPreservesValues(): void
|
|
|
|
|
public function testSessionIsLive(): void
|
|
|
|
|
{
|
|
|
|
|
$key = "testVar";
|
|
|
|
|
$value = "someData";
|
|
|
|
|
|
|
|
|
|
$session = new BaseSession();
|
|
|
|
|
$this->assertTrue(self::$session->live());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$session->tryStore($key, $value);
|
|
|
|
|
public function testValueOneStored(): void
|
|
|
|
|
{
|
|
|
|
|
self::$session->store(self::$k1, self::$v1);
|
|
|
|
|
|
|
|
|
|
$this->assertSame($session->get($key), $value);
|
|
|
|
|
$this->assertSame(self::$session->get(self::$k1), self::$v1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testTryStoreNeverOverwrites(): void
|
|
|
|
|
public function testValueOneRetrieved(): void
|
|
|
|
|
{
|
|
|
|
|
$key = "test";
|
|
|
|
|
$value1 = "someImportantData";
|
|
|
|
|
$value2 = "DataArrivingLate";
|
|
|
|
|
|
|
|
|
|
$session = new BaseSession();
|
|
|
|
|
$this->assertSame(self::$session->get(self::$k1), self::$v1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($session->tryStore($key, $value1));
|
|
|
|
|
$this->assertTrue(!$session->tryStore($key, $value2));
|
|
|
|
|
public function testTryStoreDoesntOverwrite(): void
|
|
|
|
|
{
|
|
|
|
|
$this->assertFalse(self::$session->tryStore(self::$k1, self::$v2));
|
|
|
|
|
|
|
|
|
|
$this->assertSame($session->get($key), $value1);
|
|
|
|
|
$this->assertSame(self::$session->get(self::$k1), self::$v1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testStoreOverwrites(): void
|
|
|
|
|
{
|
|
|
|
|
$key = "test";
|
|
|
|
|
$value1 = "initialData";
|
|
|
|
|
$value2 = "overwriteData";
|
|
|
|
|
|
|
|
|
|
$session = new BaseSession();
|
|
|
|
|
|
|
|
|
|
$session->store($key, $value1);
|
|
|
|
|
$session->store($key, $value2);
|
|
|
|
|
self::$session->store(self::$k1, self::$v2);
|
|
|
|
|
|
|
|
|
|
$this->assertSame($session->get($key), $value2);
|
|
|
|
|
$this->assertSame(self::$session->get(self::$k1), self::$v2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
|