Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lock
Manage
Activity
Members
Labels
Plan
Issues
9
Issue boards
Milestones
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
TYPO3
Extensions
lock
Commits
09e244fa
Commit
09e244fa
authored
7 years ago
by
Daniel Hürtgen
Browse files
Options
Downloads
Patches
Plain Diff
[FEATURE] LockFactory implemented
parent
04906fe6
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Classes/LockFactory.php
+62
-0
62 additions, 0 deletions
Classes/LockFactory.php
Tests/Unit/LockFactoryTest.php
+104
-0
104 additions, 0 deletions
Tests/Unit/LockFactoryTest.php
with
166 additions
and
0 deletions
Classes/LockFactory.php
0 → 100644
+
62
−
0
View file @
09e244fa
<?php
namespace
Higidi\Lock
;
use
Higidi\Lock\Configuration\Configuration
;
use
TYPO3\CMS\Core\Locking\Exception\LockCreateException
;
use
TYPO3\CMS\Core\Locking\LockFactory
as
CoreLockFactory
;
use
TYPO3\CMS\Core\Locking\LockingStrategyInterface
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
/**
* Factory class creates locks.
*/
class
LockFactory
extends
CoreLockFactory
{
/**
* @var Configuration
*/
protected
$configuration
;
/**
* @param Configuration|null $configuration The configuration to use
*/
public
function
__construct
(
Configuration
$configuration
=
null
)
{
if
(
null
===
$configuration
)
{
$configuration
=
GeneralUtility
::
makeInstance
(
Configuration
::
class
);
}
$this
->
configuration
=
$configuration
;
}
/**
* Get the configuration.
*
* @return Configuration
*/
public
function
getConfiguration
()
{
return
$this
->
configuration
;
}
/**
* Get best matching locking method
*
* @param string $id ID to identify this lock in the system
* @param int $capabilities LockingStrategyInterface::LOCK_CAPABILITY_* elements combined with bit-wise OR
*
* @return LockingStrategyInterface Class name for a locking method
* @throws LockCreateException if no locker could be created with the requested capabilities
*/
public
function
createLocker
(
$id
,
$capabilities
=
LockingStrategyInterface
::
LOCK_CAPABILITY_EXCLUSIVE
)
{
if
(
!
$this
->
configuration
->
isActive
())
{
return
parent
::
createLocker
(
$id
,
$capabilities
);
}
$className
=
$this
->
configuration
->
getStrategy
();
$locker
=
GeneralUtility
::
makeInstance
(
$className
,
$id
);
return
$locker
;
}
}
This diff is collapsed.
Click to expand it.
Tests/Unit/LockFactoryTest.php
0 → 100644
+
104
−
0
View file @
09e244fa
<?php
namespace
Higidi\Lock\Tests\Unit
;
use
Higidi\Lock\Configuration\Configuration
;
use
Higidi\Lock\LockFactory
;
use
Higidi\Lock\Strategy\MutexAdapterStrategy
;
use
Nimut\TestingFramework\TestCase\UnitTestCase
;
use
TYPO3\CMS\Core\Locking
as
CoreLocking
;
use
TYPO3\CMS\Core\Locking\LockFactory
as
CoreLockFactory
;
/**
* Test case for "\Higidi\Lock\LockFactory".
*
* @covers \Higidi\Lock\LockFactory
*/
class
LockFactoryTest
extends
UnitTestCase
{
/**
* @return array
*/
public
function
coreLockingStrategyDataProvider
()
{
return
[
'simple_strategy'
=>
[
CoreLocking\SimpleLockStrategy
::
class
],
'file_lock_strategy'
=>
[
CoreLocking\FileLockStrategy
::
class
],
'semaphore_strategy'
=>
[
CoreLocking\SemaphoreLockStrategy
::
class
],
];
}
/**
* @test
*/
public
function
itExtendsTheCoreLockFactory
()
{
$sut
=
new
LockFactory
();
$this
->
assertInstanceOf
(
CoreLockFactory
::
class
,
$sut
);
}
/**
* @test
*/
public
function
itCreatesADefaultConfigurationIfNotPassed
()
{
$sut
=
new
LockFactory
();
$this
->
assertInstanceOf
(
Configuration
::
class
,
$sut
->
getConfiguration
());
}
/**
* @test
*/
public
function
itHoldsAConfiguration
()
{
$configuration
=
$this
->
prophesize
(
Configuration
::
class
);
$sut
=
new
LockFactory
(
$configuration
->
reveal
());
$this
->
assertSame
(
$configuration
->
reveal
(),
$sut
->
getConfiguration
());
}
/**
* @test
*/
public
function
itOnlyOperatesIfIsActive
()
{
$configuration
=
$this
->
prophesize
(
Configuration
::
class
);
$configuration
->
isActive
()
->
willReturn
(
false
);
$sut
=
new
LockFactory
(
$configuration
->
reveal
());
$locker
=
$sut
->
createLocker
(
'blafoo'
);
$this
->
assertNotInstanceOf
(
MutexAdapterStrategy
::
class
,
$locker
);
}
/**
* @test
* @dataProvider coreLockingStrategyDataProvider
*
* @param string $strategy
*/
public
function
itCreatesSpecificLockerIfConfigurationIsSet
(
$strategy
)
{
$configuration
=
$this
->
prophesize
(
Configuration
::
class
);
$configuration
->
isActive
()
->
willReturn
(
true
);
$configuration
->
getStrategy
()
->
willReturn
(
$strategy
);
$configuration
->
isMutexStrategy
()
->
willReturn
(
false
);
$sut
=
new
LockFactory
(
$configuration
->
reveal
());
$locker
=
$sut
->
createLocker
(
'blafoo'
);
$this
->
assertInstanceOf
(
$strategy
,
$locker
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment