‪TYPO3CMS  ‪main
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 PHPUnit\Framework\Attributes\Test;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
27 final class ‪SessionManagerTest extends UnitTestCase
28 {
29  #[Test]
31  {
32  $subject = new ‪SessionManager();
33  self::assertInstanceOf(DatabaseSessionBackend::class, $subject->getSessionBackend('BE'));
34  }
35 
36  #[Test]
38  {
39  $backendMock = $this->createMock(SessionBackendInterface::class);
40  $backendClassName = get_class($backendMock);
41  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['myidentifier'] = [
42  'backend' => $backendClassName,
43  'options' => [],
44  ];
45  $backendMock->expects(self::atLeastOnce())->method('initialize')->with(self::anything());
46  $backendMock->expects(self::atLeastOnce())->method('validateConfiguration');
47  GeneralUtility::addInstance($backendClassName, $backendMock);
48  $subject = new ‪SessionManager();
49  self::assertInstanceOf($backendClassName, $subject->getSessionBackend('myidentifier'));
50  }
51 
52  #[Test]
54  {
55  $this->expectException(\InvalidArgumentException::class);
56  $this->expectExceptionCode(1482234750);
57  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['myNewIdentifier'] = 'I am not an array';
58  $subject = new ‪SessionManager();
59  $subject->getSessionBackend('myNewidentifier');
60  }
61 
62  #[Test]
64  {
65  $this->expectException(\InvalidArgumentException::class);
66  $this->expectExceptionCode(1482235035);
67  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['myidentifier'] = [
68  'backend' => \stdClass::class,
69  'options' => [],
70  ];
71  (new ‪SessionManager())->getSessionBackend('myidentifier');
72  }
73 }
‪TYPO3\CMS\Core\Tests\Unit\Session
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendThrowsExceptionIfBackendDoesNotImplementInterface
‪getSessionBackendThrowsExceptionIfBackendDoesNotImplementInterface()
Definition: SessionManagerTest.php:63
‪TYPO3\CMS\Core\Session\SessionManager
Definition: SessionManager.php:41
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendReturnsExpectedSessionBackendBasedOnConfiguration
‪getSessionBackendReturnsExpectedSessionBackendBasedOnConfiguration()
Definition: SessionManagerTest.php:37
‪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:52
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest
Definition: SessionManagerTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendUsesDefaultBackendFromConfiguration
‪getSessionBackendUsesDefaultBackendFromConfiguration()
Definition: SessionManagerTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Session\SessionManagerTest\getSessionBackendThrowsExceptionForMissingConfiguration
‪getSessionBackendThrowsExceptionForMissingConfiguration()
Definition: SessionManagerTest.php:53