Commit 0580e18a authored by Daniel Hürtgen's avatar Daniel Hürtgen

[FEATURE] LockBuilder::buildPredisRedisLock() implemented

parent 7a302aab
...@@ -87,6 +87,26 @@ class LockBuilder implements SingletonInterface ...@@ -87,6 +87,26 @@ class LockBuilder implements SingletonInterface
return $lock; return $lock;
} }
/**
* @param array $configuration
*
* @return Lock\PredisRedisLock
* @throws InvalidConfigurationException
*/
public function buildPredisRedisLock(array $configuration)
{
$parameters = isset($configuration['parameters']) ? (array)$configuration['parameters'] : null;
$options = isset($configuration['options']) ? (array)$configuration['options'] : [];
if (empty($parameters)) {
throw new InvalidConfigurationException($configuration, 'Missing or empty predis parameters', 1510325325);
}
$client = GeneralUtility::makeInstance(\Predis\Client::class, $parameters, $options);
$lock = GeneralUtility::makeInstance(Lock\PredisRedisLock::class, $client);
return $lock;
}
/** /**
* @param string $className * @param string $className
* @param array $configuration * @param array $configuration
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
namespace Higidi\Lock\Tests\Unit; namespace Higidi\Lock\Tests\Unit;
use Higidi\Lock\Builder\LockBuilder; use Higidi\Lock\Builder\LockBuilder;
use NinjaMutex\Lock;
use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Tests\UnitTestCase; use TYPO3\CMS\Core\Tests\UnitTestCase;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use NinjaMutex\Lock;
/** /**
* Test case for "\Higidi\Lock\LockBuilder". * Test case for "\Higidi\Lock\LockBuilder".
...@@ -189,6 +189,7 @@ class LockBuilderTest extends UnitTestCase ...@@ -189,6 +189,7 @@ class LockBuilderTest extends UnitTestCase
$builder->buildPhpRedisLock($configuration); $builder->buildPhpRedisLock($configuration);
} }
/** /**
* @test * @test
* @expectedException \Higidi\Lock\Builder\Exception\LockCreateException * @expectedException \Higidi\Lock\Builder\Exception\LockCreateException
...@@ -205,4 +206,32 @@ class LockBuilderTest extends UnitTestCase ...@@ -205,4 +206,32 @@ class LockBuilderTest extends UnitTestCase
$builder->buildPhpRedisLock($configuration); $builder->buildPhpRedisLock($configuration);
} }
/**
* @test
*/
public function itBuildsAPredisRedisLock()
{
$configuration = [
'parameters' => 'redis',
];
$builder = new LockBuilder();
$lock = $builder->buildPredisRedisLock($configuration);
$this->assertInstanceOf(Lock\PredisRedisLock::class, $lock);
}
/**
* @test
* @expectedException \Higidi\Lock\Builder\Exception\InvalidConfigurationException
* @expectedExceptionCode 1510325325
*/
public function itThrowsAInvalidConfigurationExceptionOnBuildAPredisRedisLockWithMissingParametersConfiguration()
{
$builder = new LockBuilder();
$builder->buildPredisRedisLock([]);
}
} }
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
}, },
"require-dev": { "require-dev": {
"friendsofphp/php-cs-fixer": "^2.0", "friendsofphp/php-cs-fixer": "^2.0",
"nimut/testing-framework": "^2.0" "nimut/testing-framework": "^2.0",
"predis/predis": "^1.1"
}, },
"license": "GPL-2.0+", "license": "GPL-2.0+",
"authors": [ "authors": [
......
Markdown is supported
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