Skip to content
Snippets Groups Projects
Commit 0dee446b authored by Daniel Hürtgen's avatar Daniel Hürtgen
Browse files

[FEATURE] LockBuilder::buildFlockLock() implemented

parent f76c284d
Branches
Tags
No related merge requests found
......@@ -21,6 +21,35 @@ class LockBuilder implements SingletonInterface
* @throws LockCreateException
*/
public function buildDirectoryLock(array $configuration)
{
$lock = $this->buildPathLock(Lock\DirectoryLock::class, $configuration);
return $lock;
}
/**
* @param array $configuration
*
* @return Lock\FlockLock
* @throws InvalidConfigurationException
* @throws LockCreateException
*/
public function buildFlockLock(array $configuration)
{
$lock = $this->buildPathLock(Lock\FlockLock::class, $configuration);
return $lock;
}
/**
* @param string $className
* @param array $configuration
*
* @return Lock\LockInterface
* @throws InvalidConfigurationException
* @throws LockCreateException
*/
protected function buildPathLock($className, array $configuration)
{
$path = isset($configuration['path']) ? (string)$configuration['path'] : null;
if (empty($path)) {
......@@ -33,7 +62,7 @@ class LockBuilder implements SingletonInterface
if (! $this->preparePath($path)) {
throw new LockCreateException(sprintf('Path %s is not usable (not readable/writeable)', $path), 1510318759);
}
$lock = GeneralUtility::makeInstance(Lock\DirectoryLock::class, $path);
$lock = GeneralUtility::makeInstance($className, $path);
return $lock;
}
......
......@@ -99,4 +99,32 @@ class LockBuilderTest extends UnitTestCase
$builder->buildDirectoryLock([]);
}
/**
* @test
*/
public function itBuildsAFlockLock()
{
$configurtion = [
'path' => $this->getLockPath(),
];
$builder = new LockBuilder();
$lock = $builder->buildFlockLock($configurtion);
$this->assertInstanceOf(Lock\FlockLock::class, $lock);
}
/**
* @test
* @expectedException \Higidi\Lock\Builder\Exception\InvalidConfigurationException
* @expectedExceptionCode 1510318044
*/
public function itThrowsAnInvalidConfigurationExceptionOnBuildAFlockLockWithMissingPathConfiguration()
{
$builder = new LockBuilder();
$builder->buildFlockLock([]);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment