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
b00b56cf
Commit
b00b56cf
authored
Nov 11, 2017
by
Daniel Hürtgen
Browse files
[FEATURE] LockImplemenationConfiguration added to Configuration
parent
90a381b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Classes/Configuration/Configuration.php
View file @
b00b56cf
...
...
@@ -37,6 +37,11 @@ class Configuration implements SingletonInterface
*/
protected
$lockImplementation
;
/**
* @var array
*/
protected
$lockImplementationConfiguration
=
[];
/**
* @param array|null $configuration
*/
...
...
@@ -166,7 +171,7 @@ class Configuration implements SingletonInterface
*/
protected
function
setLockImplementation
(
$lockImplementation
)
{
if
(
!
is_a
(
$l
ockImplementation
,
L
ockI
nterface
::
class
,
true
))
{
if
(
!
$this
->
isValidL
ockImplementation
(
$l
ockI
mplementation
))
{
throw
new
InvalidLockImplementationException
(
sprintf
(
'%s only accepts classes extending the %s class'
,
__METHOD__
,
LockInterface
::
class
),
1510268834
...
...
@@ -176,4 +181,54 @@ class Configuration implements SingletonInterface
return
$this
;
}
/**
* @param null|string $lockImplementation
*
* @return array
*/
public
function
getLockImplementationConfiguration
(
$lockImplementation
=
null
)
{
if
(
empty
(
$lockImplementation
))
{
return
$this
->
lockImplementationConfiguration
;
}
$lockImplementationConfiguration
=
isset
(
$this
->
lockImplementationConfiguration
[
$lockImplementation
])
?
$this
->
lockImplementationConfiguration
[
$lockImplementation
]
:
[];
return
$lockImplementationConfiguration
;
}
/**
* @param array $configuration
*
* @return $this
* @throws InvalidLockImplementationException
*/
protected
function
setLockImplementationConfiguration
(
$configuration
)
{
if
(
!
is_array
(
$configuration
))
{
$configuration
=
(
array
)
$configuration
;
}
foreach
(
$configuration
as
$lockImplementation
=>
$lockImplementationConfiguration
)
{
if
(
!
$this
->
isValidLockImplementation
(
$lockImplementation
))
{
throw
new
InvalidLockImplementationException
(
''
,
1510436776
);
}
$this
->
lockImplementationConfiguration
[
$lockImplementation
]
=
(
array
)
$lockImplementationConfiguration
;
}
return
$this
;
}
/**
* @param string $className
*
* @return bool
*/
protected
function
isValidLockImplementation
(
$className
)
{
return
is_a
(
$className
,
LockInterface
::
class
,
true
);
}
}
Tests/Unit/Configuration/ConfigurationTest.php
View file @
b00b56cf
...
...
@@ -195,6 +195,44 @@ class ConfigurationTest extends UnitTestCase
$this
->
assertSame
(
$className
,
$sut
->
getLockImplementation
());
}
/**
* @test
*/
public
function
itIsPossibleToSetLockImplementationConfigurationViaGlobalsConfigurationArray
()
{
$lockImplementation
=
$this
->
prophesize
(
LockInterface
::
class
)
->
reveal
();
$className
=
get_class
(
$lockImplementation
);
$lockImplementationConfiguration
=
[
$className
=>
[],
];
$GLOBALS
[
'TYPO3_CONF_VARS'
][
'SYS'
][
'locking'
]
=
[
'lockImplementationConfiguration'
=>
$lockImplementationConfiguration
,
];
$sut
=
new
Configuration
();
$this
->
assertSame
(
$lockImplementationConfiguration
,
$sut
->
getLockImplementationConfiguration
());
}
/**
* @test
*/
public
function
itIsPossibleToSetLockImplementationConfigurationViaConfigurationArray
()
{
$lockImplementation
=
$this
->
prophesize
(
LockInterface
::
class
)
->
reveal
();
$className
=
get_class
(
$lockImplementation
);
$lockImplementationConfiguration
=
[
$className
=>
[],
];
$configuration
=
[
'lockImplementationConfiguration'
=>
$lockImplementationConfiguration
,
];
$sut
=
new
Configuration
(
$configuration
);
$this
->
assertSame
(
$lockImplementationConfiguration
,
$sut
->
getLockImplementationConfiguration
());
}
/**
* @test
*/
...
...
@@ -295,6 +333,46 @@ class ConfigurationTest extends UnitTestCase
$this
->
assertNull
(
$sut
->
getLockImplementation
());
}
/**
* @test
*/
public
function
itHasAnArrayAsDefaultLockImplemenationConfiguration
()
{
$sut
=
new
Configuration
();
$this
->
assertSame
([],
$sut
->
getLockImplementationConfiguration
());
}
/**
* @test
*/
public
function
itReturnsALockImplemenationConfigurationByLockImplemenation
()
{
$lockImplementation
=
$this
->
prophesize
(
LockInterface
::
class
)
->
reveal
();
$className
=
get_class
(
$lockImplementation
);
$config
=
[
'bla'
=>
'foo'
];
$lockImplementationConfiguration
=
[
$className
=>
$config
,
];
$configuration
=
[
'lockImplementationConfiguration'
=>
$lockImplementationConfiguration
,
];
$sut
=
new
Configuration
(
$configuration
);
$this
->
assertSame
(
$config
,
$sut
->
getLockImplementationConfiguration
(
$className
));
}
/**
* @test
*/
public
function
itReturnsPerDefaultAnArrayAsLockImplemenationConfigurationByLockImplemenationIfNotExists
()
{
$sut
=
new
Configuration
();
$this
->
assertSame
([],
$sut
->
getLockImplementationConfiguration
(
\
stdClass
::
class
));
}
/**
* @test
* @expectedException \Higidi\Lock\Configuration\Exception\InvalidLockImplementationException
...
...
@@ -308,4 +386,20 @@ class ConfigurationTest extends UnitTestCase
new
Configuration
(
$configuration
);
}
/**
* @test
* @expectedException \Higidi\Lock\Configuration\Exception\InvalidLockImplementationException
* @expectedExceptionCode 1510436776
*/
public
function
itThrowsAnInvalidLockImplemenationExceptionIfLockImplemenationForConfigurationIsNotValid
()
{
$configuration
=
[
'lockImplementationConfiguration'
=>
[
\
stdClass
::
class
=>
[],
],
];
new
Configuration
(
$configuration
);
}
}
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