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
b00b56cf
Commit
b00b56cf
authored
Nov 11, 2017
by
Daniel Hürtgen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEATURE] LockImplemenationConfiguration added to Configuration
parent
90a381b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
1 deletion
+150
-1
Classes/Configuration/Configuration.php
Classes/Configuration/Configuration.php
+56
-1
Tests/Unit/Configuration/ConfigurationTest.php
Tests/Unit/Configuration/ConfigurationTest.php
+94
-0
No files found.
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
(
$lockImplementation
,
LockInterface
::
class
,
true
))
{
if
(
!
$this
->
isValidLockImplementation
(
$lockImplementation
))
{
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