‪TYPO3CMS  10.4
SessionManagerTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use Prophecy\Argument;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪SessionManagerTest extends UnitTestCase
31 {
36  {
37  $subject = new ‪SessionManager();
38  self::assertInstanceOf(DatabaseSessionBackend::class, $subject->getSessionBackend('BE'));
39  }
40 
45  {
46  $backendProphecy = $this->prophesize(SessionBackendInterface::class);
47  $backendRevelation = $backendProphecy->reveal();
48  $backendClassName = get_class($backendRevelation);
49  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['myidentifier'] = [
50  'backend' => $backendClassName,
51  'options' => []
52  ];
53  $backendProphecy->initialize(Argument::cetera())->shouldBeCalled();
54  $backendProphecy->validateConfiguration(Argument::cetera())->shouldBeCalled();
55  GeneralUtility::addInstance($backendClassName, $backendRevelation);
56  $subject = new ‪SessionManager();
57  self::assertInstanceOf($backendClassName, $subject->getSessionBackend('myidentifier'));
58  }
59 
64  {
65  $this->expectException(\InvalidArgumentException::class);
66  $this->expectExceptionCode(1482234750);
67  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['myNewIdentifier'] = 'I am not an array';
68  $subject = new ‪SessionManager();
69  $subject->getSessionBackend('myNewidentifier');
70  }
71 
76  {
77  $this->expectException(\InvalidArgumentException::class);
78  $this->expectExceptionCode(1482235035);
79  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['myidentifier'] = [
80  'backend' => \stdClass::class,
81  'options' => []
82  ];
83  (new ‪SessionManager())->getSessionBackend('myidentifier');
84  }
85 }
‪TYPO3\CMS\Core\Tests\Unit\Session
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendThrowsExceptionIfBackendDoesNotImplementInterface
‪getSessionBackendThrowsExceptionIfBackendDoesNotImplementInterface()
Definition: SessionManagerTest.php:75
‪TYPO3\CMS\Core\Session\SessionManager
Definition: SessionManager.php:39
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendReturnsExpectedSessionBackendBasedOnConfiguration
‪getSessionBackendReturnsExpectedSessionBackendBasedOnConfiguration()
Definition: SessionManagerTest.php:44
‪TYPO3\CMS\Core\Session\Backend\SessionBackendInterface
Definition: SessionBackendInterface.php:28
‪TYPO3\CMS\Core\Session\Backend\DatabaseSessionBackend
Definition: DatabaseSessionBackend.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest
Definition: SessionManagerTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendUsesDefaultBackendFromConfiguration
‪getSessionBackendUsesDefaultBackendFromConfiguration()
Definition: SessionManagerTest.php:35
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendThrowsExceptionForMissingConfiguration
‪getSessionBackendThrowsExceptionForMissingConfiguration()
Definition: SessionManagerTest.php:63