‪TYPO3CMS  10.4
LockFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪LockFactoryTest extends UnitTestCase
31 {
35  protected ‪$mockFactory;
36 
40  protected ‪$strategiesConfigBackup = [];
41 
45  protected function ‪setUp(): void
46  {
47  parent::setUp();
48  $this->mockFactory = $this->getAccessibleMock(LockFactory::class, ['dummy']);
49 
50  // backup global configuration
51  if (isset(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking']['strategies'])) {
52  $this->strategiesConfigBackup = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking']['strategies'];
53  } else {
54  $this->strategiesConfigBackup = [];
55  }
56  }
57 
58  protected function ‪tearDown(): void
59  {
60  // restore global configuration
61  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking']['strategies'] = ‪$this->strategiesConfigBackup;
62 
63  parent::tearDown();
64  }
65 
70  {
71  $this->mockFactory->addLockingStrategy(DummyLock::class);
72  self::assertArrayHasKey(DummyLock::class, $this->mockFactory->_get('lockingStrategy'));
73  }
74 
79  {
80  $this->expectException(\InvalidArgumentException::class);
81  $this->expectExceptionCode(1425990198);
82 
83  $this->mockFactory->addLockingStrategy(\stdClass::class);
84  }
85 
89  public function ‪getLockerReturnsExpectedClass()
90  {
91  $this->mockFactory->_set('lockingStrategy', [FileLockStrategy::class => true, DummyLock::class => true]);
92  $locker = $this->mockFactory->createLocker(
93  'id',
95  );
96  self::assertInstanceOf(FileLockStrategy::class, $locker);
97  }
98 
103  {
104  $this->mockFactory->_set('lockingStrategy', [SemaphoreLockStrategy::class => true, DummyLock::class => true]);
105  $locker = $this->mockFactory->createLocker('id');
106  self::assertInstanceOf(DummyLock::class, $locker);
107  }
108 
113  {
114  $lowestValue = min([
118  ]) - 1;
119  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking']['strategies'][FileLockStrategy::class]['priority'] = $lowestValue;
120  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking']['strategies'][SemaphoreLockStrategy::class]['priority'] = $lowestValue;
121  $locker = $this->mockFactory->createLocker('id');
122  self::assertInstanceOf(SimpleLockStrategy::class, $locker);
123 
124  unset(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking']['strategies'][FileLockStrategy::class]['priority']);
125  unset(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking']['strategies'][SemaphoreLockStrategy::class]['priority']);
126  }
127 
132  {
133  $this->expectException(LockCreateException::class);
134  $this->expectExceptionCode(1425990190);
135 
136  $this->mockFactory->createLocker('id', 32);
137  }
138 }
‪TYPO3\CMS\Core\Locking\SemaphoreLockStrategy\DEFAULT_PRIORITY
‪const DEFAULT_PRIORITY
Definition: SemaphoreLockStrategy.php:32
‪TYPO3\CMS\Core\Tests\Unit\Locking\LockFactoryTest\getLockerThrowsExceptionIfNoMatchFound
‪getLockerThrowsExceptionIfNoMatchFound()
Definition: LockFactoryTest.php:129
‪TYPO3\CMS\Core\Tests\Unit\Locking\LockFactoryTest\setUp
‪setUp()
Definition: LockFactoryTest.php:43
‪TYPO3\CMS\Core\Locking\FileLockStrategy\DEFAULT_PRIORITY
‪const DEFAULT_PRIORITY
Definition: FileLockStrategy.php:33
‪TYPO3\CMS\Core\Locking\LockingStrategyInterface
Definition: LockingStrategyInterface.php:26
‪TYPO3\CMS\Core\Locking\LockingStrategyInterface\LOCK_CAPABILITY_EXCLUSIVE
‪const LOCK_CAPABILITY_EXCLUSIVE
Definition: LockingStrategyInterface.php:30
‪TYPO3\CMS\Core\Tests\Unit\Locking\LockFactoryTest\tearDown
‪tearDown()
Definition: LockFactoryTest.php:56
‪TYPO3\CMS\Core\Locking\SemaphoreLockStrategy
Definition: SemaphoreLockStrategy.php:28
‪TYPO3\CMS\Core\Tests\Unit\Locking\LockFactoryTest\$mockFactory
‪LockFactory PHPUnit Framework MockObject MockObject TYPO3 TestingFramework Core AccessibleObjectInterface $mockFactory
Definition: LockFactoryTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\Locking\LockFactoryTest
Definition: LockFactoryTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Locking\LockFactoryTest\getLockerReturnsClassWithHighestPriority
‪getLockerReturnsClassWithHighestPriority()
Definition: LockFactoryTest.php:100
‪TYPO3\CMS\Core\Locking\LockingStrategyInterface\LOCK_CAPABILITY_SHARED
‪const LOCK_CAPABILITY_SHARED
Definition: LockingStrategyInterface.php:35
‪TYPO3\CMS\Core\Tests\Unit\Locking\LockFactoryTest\$strategiesConfigBackup
‪array $strategiesConfigBackup
Definition: LockFactoryTest.php:38
‪TYPO3\CMS\Core\Tests\Unit\Locking\LockFactoryTest\addLockingStrategyAddsTheClassNameToTheInternalArray
‪addLockingStrategyAddsTheClassNameToTheInternalArray()
Definition: LockFactoryTest.php:67
‪TYPO3\CMS\Core\Tests\Unit\Locking
Definition: FileLockStrategyTest.php:16
‪TYPO3\CMS\Core\Locking\SimpleLockStrategy
Definition: SimpleLockStrategy.php:28
‪TYPO3\CMS\Core\Tests\Unit\Locking\LockFactoryTest\addLockingStrategyThrowsExceptionIfInterfaceIsNotImplemented
‪addLockingStrategyThrowsExceptionIfInterfaceIsNotImplemented()
Definition: LockFactoryTest.php:76
‪TYPO3\CMS\Core\Locking\Exception\LockCreateException
Definition: LockCreateException.php:24
‪TYPO3\CMS\Core\Tests\Unit\Locking\Fixtures\DummyLock
Definition: DummyLock.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Locking\LockFactory
Definition: LockFactory.php:25
‪TYPO3\CMS\Core\Locking\SimpleLockStrategy\DEFAULT_PRIORITY
‪const DEFAULT_PRIORITY
Definition: SimpleLockStrategy.php:32
‪TYPO3\CMS\Core\Tests\Unit\Locking\LockFactoryTest\setPriorityGetLockerReturnsClassWithHighestPriority
‪setPriorityGetLockerReturnsClassWithHighestPriority()
Definition: LockFactoryTest.php:110
‪TYPO3\CMS\Core\Locking\FileLockStrategy
Definition: FileLockStrategy.php:29
‪TYPO3\CMS\Core\Tests\Unit\Locking\LockFactoryTest\getLockerReturnsExpectedClass
‪getLockerReturnsExpectedClass()
Definition: LockFactoryTest.php:87