Commit bcd1f320 authored by Daniel Hürtgen's avatar Daniel Hürtgen

[FEATURE] LockBuilder::buildMySQLLock() implemented

parent 0580e18a
......@@ -37,9 +37,14 @@ lint:cgl:
stage: test
services:
- redis:latest
- mysql:latest
variables:
MYSQL_DATABASE: "typo3"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
before_script:
- apk add --no-cache --virtual .build-deps autoconf g++ make
- pecl install -f redis
- docker-php-ext-install pdo pdo_mysql
- docker-php-ext-enable redis
- wget https://composer.github.io/installer.sig -O - -q | tr -d '\n' > installer.sig
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
......
......@@ -41,6 +41,32 @@ class LockBuilder implements SingletonInterface
return $lock;
}
/**
* @param array $configuration
*
* @return Lock\MySqlLock
* @throws InvalidConfigurationException
*/
public function buildMySqlLock(array $configuration)
{
$host = isset($configuration['host']) ? (string)$configuration['host'] : null;
$port = isset($configuration['port']) ? (int)$configuration['port'] : 3306;
$userName = isset($configuration['username']) ? (string)$configuration['username'] : '';
$password = isset($configuration['password']) ? (string)$configuration['password'] : '';
$className = isset($configuration['className']) ? (string)$configuration['className'] : '\PDO';
if (empty($host)) {
throw new InvalidConfigurationException($configuration, 'Missing or empty mysql host', 1510327148);
}
if (! is_a($className, \PDO::class, true)) {
throw new InvalidConfigurationException($configuration, 'Classname must an instance of \PDO', 1510327151);
}
$lock = GeneralUtility::makeInstance(Lock\MySqlLock::class, $userName, $password, $host, $port, $className);
return $lock;
}
/**
* @param array $configuration
*
......
......@@ -128,6 +128,51 @@ class LockBuilderTest extends UnitTestCase
$builder->buildFlockLock([]);
}
/**
* @test
*/
public function itBuildsAMySqlLock()
{
$configuration = [
'host' => 'mysql',
];
$builder = new LockBuilder();
$lock = $builder->buildMySqlLock($configuration);
$this->assertInstanceOf(Lock\MySqlLock::class, $lock);
}
/**
* @test
* @expectedException \Higidi\Lock\Builder\Exception\InvalidConfigurationException
* @expectedExceptionCode 1510327148
*/
public function itThrowsAInvalidConfigurationExceptionOnBuildAMySQLLockWithMissingHostConfiguration()
{
$builder = new LockBuilder();
$builder->buildMysqlLock([]);
}
/**
* @test
* @expectedException \Higidi\Lock\Builder\Exception\InvalidConfigurationException
* @expectedExceptionCode 1510327151
*/
public function itThrowsAInvalidConfigurationExceptionOnBuildAMySQLLockWithInvalidClassNameConfiguration()
{
$configuration = [
'host' => '127.0.0.1',
'className' => \stdClass::class,
];
$builder = new LockBuilder();
$builder->buildMysqlLock($configuration);
}
/**
* @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