‪TYPO3CMS  11.5
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;
21 use Prophecy\PhpUnit\ProphecyTrait;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪SessionManagerTest extends UnitTestCase
32 {
33  use ProphecyTrait;
34 
39  {
40  $subject = new ‪SessionManager();
41  self::assertInstanceOf(DatabaseSessionBackend::class, $subject->getSessionBackend('BE'));
42  }
43 
48  {
49  $backendProphecy = $this->prophesize(SessionBackendInterface::class);
50  $backendRevelation = $backendProphecy->reveal();
51  $backendClassName = get_class($backendRevelation);
52  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['myidentifier'] = [
53  'backend' => $backendClassName,
54  'options' => [],
55  ];
56  $backendProphecy->initialize(Argument::cetera())->shouldBeCalled();
57  $backendProphecy->validateConfiguration(Argument::cetera())->shouldBeCalled();
58  GeneralUtility::addInstance($backendClassName, $backendRevelation);
59  $subject = new ‪SessionManager();
60  self::assertInstanceOf($backendClassName, $subject->getSessionBackend('myidentifier'));
61  }
62 
67  {
68  $this->expectException(\InvalidArgumentException::class);
69  $this->expectExceptionCode(1482234750);
70  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['myNewIdentifier'] = 'I am not an array';
71  $subject = new ‪SessionManager();
72  $subject->getSessionBackend('myNewidentifier');
73  }
74 
79  {
80  $this->expectException(\InvalidArgumentException::class);
81  $this->expectExceptionCode(1482235035);
82  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['myidentifier'] = [
83  'backend' => \stdClass::class,
84  'options' => [],
85  ];
86  (new ‪SessionManager())->getSessionBackend('myidentifier');
87  }
88 }
‪TYPO3\CMS\Core\Tests\Unit\Session
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendThrowsExceptionIfBackendDoesNotImplementInterface
‪getSessionBackendThrowsExceptionIfBackendDoesNotImplementInterface()
Definition: SessionManagerTest.php:77
‪TYPO3\CMS\Core\Session\SessionManager
Definition: SessionManager.php:39
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendReturnsExpectedSessionBackendBasedOnConfiguration
‪getSessionBackendReturnsExpectedSessionBackendBasedOnConfiguration()
Definition: SessionManagerTest.php:46
‪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:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest
Definition: SessionManagerTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendUsesDefaultBackendFromConfiguration
‪getSessionBackendUsesDefaultBackendFromConfiguration()
Definition: SessionManagerTest.php:37
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendThrowsExceptionForMissingConfiguration
‪getSessionBackendThrowsExceptionForMissingConfiguration()
Definition: SessionManagerTest.php:65