Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
lock
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
4
Issues
4
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Packages
Packages
Container Registry
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
TYPO3
Extensions
lock
Commits
15bca1a4
Commit
15bca1a4
authored
Nov 09, 2017
by
Daniel Hürtgen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEATURE] LockImplementation configuration added
parent
52f72484
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
Classes/Configuration/Configuration.php
Classes/Configuration/Configuration.php
+34
-0
Tests/Unit/Configuration/ConfigurationTest.php
Tests/Unit/Configuration/ConfigurationTest.php
+46
-0
No files found.
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