diff --git a/tests/DynamoDbSessionTest.php b/tests/DynamoDbSessionTest.php index 7ecc254..20fa0a8 100644 --- a/tests/DynamoDbSessionTest.php +++ b/tests/DynamoDbSessionTest.php @@ -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()