Skip to content
Snippets Groups Projects
Commit 15bca1a4 authored by Daniel Hürtgen's avatar Daniel Hürtgen
Browse files

[FEATURE] LockImplementation configuration added

parent 52f72484
Branches
Tags
No related merge requests found
......@@ -2,9 +2,11 @@
namespace Higidi\Lock\Configuration;
use Higidi\Lock\Configuration\Exception\InvalidLockImplementationException;
use Higidi\Lock\Configuration\Exception\InvalidMutexException;
use Higidi\Lock\Configuration\Exception\InvalidStrategyException;
use Higidi\Lock\Strategy\MutexAdapterStrategy;
use NinjaMutex\Lock\LockInterface;
use NinjaMutex\Mutex;
use TYPO3\CMS\Core\Locking\LockingStrategyInterface;
use TYPO3\CMS\Core\Locking\SimpleLockStrategy;
......@@ -30,6 +32,11 @@ class Configuration implements SingletonInterface
*/
protected $mutex = Mutex::class;
/**
* @var null|string
*/
protected $lockImplementation;
/**
* @param array|null $configuration
*/
......@@ -142,4 +149,31 @@ class Configuration implements SingletonInterface
return $this;
}
/**
* @return string|null
*/
public function getLockImplementation()
{
return $this->lockImplementation;
}
/**
* @param string $lockImplementation
*
* @return $this
* @throws InvalidLockImplementationException
*/
protected function setLockImplementation($lockImplementation)
{
if (! is_a($lockImplementation, LockInterface::class, true)) {
throw new InvalidLockImplementationException(
sprintf('%s only accepts classes extending the %s class', __METHOD__, LockInterface::class),
1510177680
);
}
$this->lockImplementation = $lockImplementation;
return $this;
}
}
......@@ -5,6 +5,7 @@ namespace Higidi\Lock\Tests\Unit\Configuration;
use Higidi\Lock\Configuration\Configuration;
use Higidi\Lock\Strategy\MutexAdapterStrategy;
use Nimut\TestingFramework\TestCase\UnitTestCase;
use NinjaMutex\Lock\LockInterface;
use NinjaMutex\Mutex;
use TYPO3\CMS\Core\Locking\LockingStrategyInterface;
use TYPO3\CMS\Core\Locking\SimpleLockStrategy;
......@@ -159,6 +160,41 @@ class ConfigurationTest extends UnitTestCase
$this->assertSame($className, $sut->getMutex());
}
/**
* @test
*/
public function itIsPossibleToSetLockImplementationViaGlobalsConfigurationArray()
{
$lockImplementation = $this->prophesize(LockInterface::class)->reveal();
$className = get_class($lockImplementation);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locking'] = [
'lockImplementation' => $className,
];
$sut = new Configuration();
$this->assertSame($className, $sut->getLockImplementation());
}
/**
* @test
*/
public function itIsPossibleToSetLockImplementationViaConfigurationArray()
{
$lockImplementation = $this->prophesize(LockInterface::class)->reveal();
$className = get_class($lockImplementation);
$configuration = [
'active' => true,
'lockImplementation' => $className,
];
$sut = new Configuration($configuration);
$this->assertSame($className, $sut->getLockImplementation());
}
/**
* @test
*/
......@@ -248,4 +284,14 @@ class ConfigurationTest extends UnitTestCase
new Configuration($configuration);
}
/**
* @test
*/
public function itHasNullAsDefaultLockImplementation()
{
$sut = new Configuration();
$this->assertNull($sut->getLockImplementation());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment