Skip to content

Commit

Permalink
MNT Add more robust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Feb 13, 2023
1 parent 05c975e commit a46acd2
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/DynamoDbSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,41 @@

namespace SilverStripe\DynamoDb\Tests;

use ReflectionProperty;
use SilverStripe\Core\Environment;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\DynamoDb\Model\DynamoDbSession;

class DynamoDbSessionTest extends SapphireTest
{

public function testGetReturnsNullWhenNotConfigured()
{
// Ensure the session table is null for this test
$origValue = Environment::getEnv('AWS_DYNAMODB_SESSION_TABLE');
Environment::setEnv('AWS_DYNAMODB_SESSION_TABLE', null);

$this->assertNull(DynamoDbSession::get());

Environment::setEnv('AWS_DYNAMODB_SESSION_TABLE', $origValue);
}

public function testGetReturnsSessionWhenConfigured()
{
// Ensure the session table is not null for this test
$origValue = Environment::getEnv('AWS_DYNAMODB_SESSION_TABLE');
Environment::setEnv('AWS_DYNAMODB_SESSION_TABLE', 'sessiontable');
$session = DynamoDbSession::get();

// Check there is a session
$this->assertInstanceOf(DynamoDbSession::class, $session);

$reflectionTable = new ReflectionProperty($session, 'table');
$reflectionTable->setAccessible(true);

// Check the session set the correct table name
$this->assertSame('sessiontable', $reflectionTable->getValue($session));

Environment::setEnv('AWS_DYNAMODB_SESSION_TABLE', $origValue);
}

public function testGetSessionHandler()
Expand Down

0 comments on commit a46acd2

Please sign in to comment.