Commit 00362ef5 authored by Daniel Hürtgen's avatar Daniel Hürtgen
Browse files

[FEATURE] Inject lock implementation builder

parent fb408934
......@@ -18,15 +18,25 @@ class LockFactory extends CoreLockFactory
*/
protected $configuration;
/**
* @var LockBuilder
*/
protected $lockBuilder;
/**
* @param Configuration|null $configuration The configuration to use
* @param LockBuilder|null $lockBuilder The lock implementation builder to use
*/
public function __construct(Configuration $configuration = null)
public function __construct(Configuration $configuration = null, LockBuilder $lockBuilder = null)
{
if (null === $configuration) {
$configuration = GeneralUtility::makeInstance(Configuration::class);
}
if (null === $lockBuilder) {
$lockBuilder = GeneralUtility::makeInstance(LockBuilder::class);
}
$this->configuration = $configuration;
$this->lockBuilder = $lockBuilder;
}
/**
......@@ -39,6 +49,16 @@ class LockFactory extends CoreLockFactory
return $this->configuration;
}
/**
* Get lock builder.
*
* @return LockBuilder
*/
public function getLockBuilder()
{
return $this->lockBuilder;
}
/**
* Get best matching locking method
*
......
......@@ -3,6 +3,7 @@
namespace Higidi\Lock\Tests\Unit;
use Higidi\Lock\Configuration\Configuration;
use Higidi\Lock\LockBuilder;
use Higidi\Lock\LockFactory;
use Higidi\Lock\Strategy\MutexAdapterStrategy;
use Nimut\TestingFramework\TestCase\UnitTestCase;
......@@ -60,6 +61,28 @@ class LockFactoryTest extends UnitTestCase
$this->assertSame($configuration->reveal(), $sut->getConfiguration());
}
/**
* @test
*/
public function itCreatesADefaultLockBuilderIfNotPassed()
{
$sut = new LockFactory();
$this->assertInstanceOf(LockBuilder::class, $sut->getLockBuilder());
}
/**
* @test
*/
public function itHoldsALockBuilder()
{
$lockBuilder = $this->prophesize(LockBuilder::class);
$sut = new LockFactory(null, $lockBuilder->reveal());
$this->assertSame($lockBuilder->reveal(), $sut->getLockBuilder());
}
/**
* @test
*/
......
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