Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
TYPO3
Extensions
lock
Commits
15bca1a4
Commit
15bca1a4
authored
Nov 09, 2017
by
Daniel Hürtgen
Browse files
[FEATURE] LockImplementation configuration added
parent
52f72484
Changes
2
Hide whitespace changes
Inline
Side-by-side
Classes/Configuration/Configuration.php
View file @
15bca1a4
...
...
@@ -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
;
}
}
Tests/Unit/Configuration/ConfigurationTest.php
View file @
15bca1a4
...
...
@@ -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
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment