‪TYPO3CMS  9.5
SessionManagerTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Prophecy\Argument;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪SessionManagerTest extends UnitTestCase
29 {
34  {
35  $subject = new ‪SessionManager();
36  $this->assertInstanceOf(DatabaseSessionBackend::class, $subject->getSessionBackend('BE'));
37  }
38 
43  {
44  $backendProphecy = $this->prophesize(SessionBackendInterface::class);
45  $backendRevelation = $backendProphecy->reveal();
46  $backendClassName = get_class($backendRevelation);
47  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['myidentifier'] = [
48  'backend' => $backendClassName,
49  'options' => []
50  ];
51  $backendProphecy->initialize(Argument::cetera())->shouldBeCalled();
52  $backendProphecy->validateConfiguration(Argument::cetera())->shouldBeCalled();
53  GeneralUtility::addInstance($backendClassName, $backendRevelation);
54  $subject = new ‪SessionManager();
55  $this->assertInstanceOf($backendClassName, $subject->getSessionBackend('myidentifier'));
56  }
57 
62  {
63  $this->expectException(\InvalidArgumentException::class);
64  $this->expectExceptionCode(1482234750);
65  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['myNewIdentifier'] = 'I am not an array';
66  $subject = new ‪SessionManager();
67  $subject->getSessionBackend('myNewidentifier');
68  }
69 
74  {
75  $this->expectException(\InvalidArgumentException::class);
76  $this->expectExceptionCode(1482235035);
77  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['myidentifier'] = [
78  'backend' => \stdClass::class,
79  'options' => []
80  ];
81  (new ‪SessionManager())->getSessionBackend('myidentifier');
82  }
83 }
‪TYPO3\CMS\Core\Tests\Unit\Session
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendThrowsExceptionIfBackendDoesNotImplementInterface
‪getSessionBackendThrowsExceptionIfBackendDoesNotImplementInterface()
Definition: SessionManagerTest.php:73
‪TYPO3\CMS\Core\Session\SessionManager
Definition: SessionManager.php:37
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendReturnsExpectedSessionBackendBasedOnConfiguration
‪getSessionBackendReturnsExpectedSessionBackendBasedOnConfiguration()
Definition: SessionManagerTest.php:42
‪TYPO3\CMS\Core\Session\Backend\SessionBackendInterface
Definition: SessionBackendInterface.php:26
‪TYPO3\CMS\Core\Session\Backend\DatabaseSessionBackend
Definition: DatabaseSessionBackend.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest
Definition: SessionManagerTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendUsesDefaultBackendFromConfiguration
‪getSessionBackendUsesDefaultBackendFromConfiguration()
Definition: SessionManagerTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendThrowsExceptionForMissingConfiguration
‪getSessionBackendThrowsExceptionForMissingConfiguration()
Definition: SessionManagerTest.php:61