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

[TASK] Make strategy & mutex read-only

parent 19f62ca8
......@@ -91,7 +91,7 @@ class Configuration implements SingletonInterface
* @return $this
* @throws InvalidStrategyException
*/
public function setStrategy($strategy = null)
protected function setStrategy($strategy = null)
{
if (! is_a($strategy, LockingStrategyInterface::class, true)) {
throw new InvalidStrategyException(
......@@ -130,7 +130,7 @@ class Configuration implements SingletonInterface
* @return $this
* @throws InvalidMutexException
*/
public function setMutex($mutex)
protected function setMutex($mutex)
{
if (! is_a($mutex, Mutex::class, true)) {
throw new InvalidMutexException(
......
......@@ -193,20 +193,6 @@ class ConfigurationTest extends UnitTestCase
$this->assertSame(SimpleLockStrategy::class, $className);
}
/**
* @test
*/
public function itHoldsAStrategy()
{
$strategy = $this->prophesize(LockingStrategyInterface::class)->reveal();
$className = get_class($strategy);
$sut = new Configuration();
$sut->setStrategy($className);
$this->assertSame($className, $sut->getStrategy());
}
/**
* @test
* @expectedException \Higidi\Lock\Configuration\Exception\InvalidStrategyException
......@@ -214,8 +200,11 @@ class ConfigurationTest extends UnitTestCase
*/
public function itThrowsAnInvalidStrategyExceptionIfStrategyDoNotImplementTheLockingStrategyInterface()
{
$sut = new Configuration();
$sut->setStrategy(\stdClass::class);
$configuration = [
'strategy' => \stdClass::class,
];
new Configuration($configuration);
}
/**
......@@ -225,11 +214,12 @@ class ConfigurationTest extends UnitTestCase
{
$strategy = $this->prophesize(MutexAdapterStrategy::class)->reveal();
$className = get_class($strategy);
$configuration = [
'active' => true,
'strategy' => $className,
];
$sut = new Configuration();
$sut->setActive(true);
$this->assertFalse($sut->isMutexStrategy());
$sut->setStrategy($className);
$sut = new Configuration($configuration);
$this->assertTrue($sut->isMutexStrategy());
}
......@@ -245,20 +235,6 @@ class ConfigurationTest extends UnitTestCase
$this->assertSame(Mutex::class, $className);
}
/**
* @test
*/
public function itHoldsAMutex()
{
$mutex = $this->prophesize(Mutex::class)->reveal();
$className = get_class($mutex);
$sut = new Configuration();
$sut->setMutex($className);
$this->assertSame($className, $sut->getMutex());
}
/**
* @test
* @expectedException \Higidi\Lock\Configuration\Exception\InvalidMutexException
......@@ -266,7 +242,10 @@ class ConfigurationTest extends UnitTestCase
*/
public function itThrowsAnInvalidMutexExceptionIfMutexDoNotExtendTheBaseMutex()
{
$sut = new Configuration();
$sut->setMutex(\stdClass::class);
$configuration = [
'mutex' => \stdClass::class,
];
new Configuration($configuration);
}
}
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