From 6f750f6d0c8bd8ca08c024aefb603a6e83beedab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20DESTRE?= Date: Thu, 5 Nov 2015 15:14:38 +0100 Subject: [PATCH 01/35] Fix Fatal error: Call to a member function fetch() on boolean Escape lock name to prevent the generation of a broken SQL query if the lock name contains special characters ( " for example) --- src/NinjaMutex/Lock/MySqlLock.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/NinjaMutex/Lock/MySqlLock.php b/src/NinjaMutex/Lock/MySqlLock.php index 8c55546..0974c01 100644 --- a/src/NinjaMutex/Lock/MySqlLock.php +++ b/src/NinjaMutex/Lock/MySqlLock.php @@ -81,8 +81,8 @@ protected function getLock($name, $blocking) { return !$this->isLocked($name) && $this->pdo[$name]->query( sprintf( - 'SELECT GET_LOCK("%s", %d)', - $name, + 'SELECT GET_LOCK(%s, %d)', + $this->pdo[$name]->quote($name), 0 ), PDO::FETCH_COLUMN, @@ -104,8 +104,8 @@ public function releaseLock($name) $released = (bool) $this->pdo[$name]->query( sprintf( - 'SELECT RELEASE_LOCK("%s")', - $name + 'SELECT RELEASE_LOCK(%s)', + $this->pdo[$name]->quote($name) ), PDO::FETCH_COLUMN, 0 @@ -135,8 +135,8 @@ public function isLocked($name) return !current($this->pdo)->query( sprintf( - 'SELECT IS_FREE_LOCK("%s")', - $name + 'SELECT IS_FREE_LOCK(%s)', + current($this->pdo)->quote($name) ), PDO::FETCH_COLUMN, 0 From 5b09f4b70776a56890658c490d6a4aeddf5342a0 Mon Sep 17 00:00:00 2001 From: Guillaume Boudreau Date: Tue, 13 Jun 2017 09:43:21 -0400 Subject: [PATCH 02/35] Add optional SSL CA certificate option to MySQL Lock --- src/Lock/MySqlLock.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Lock/MySqlLock.php b/src/Lock/MySqlLock.php index c11e581..5ca4674 100644 --- a/src/Lock/MySqlLock.php +++ b/src/Lock/MySqlLock.php @@ -30,6 +30,7 @@ class MySqlLock extends LockAbstract protected $host; protected $port; protected $classname; + protected $ssl_ca_cert; /** * Provide data for PDO connection @@ -40,7 +41,7 @@ class MySqlLock extends LockAbstract * @param int $port * @param string $classname class name to create as PDO connection */ - public function __construct($user, $password, $host, $port = 3306, $classname = 'PDO') + public function __construct($user, $password, $host, $port = 3306, $classname = 'PDO', $ssl_ca_cert = NULL) { parent::__construct(); @@ -49,6 +50,7 @@ public function __construct($user, $password, $host, $port = 3306, $classname = $this->host = $host; $this->port = $port; $this->classname = $classname; + $this->ssl_ca_cert = $ssl_ca_cert; } public function __clone() @@ -157,7 +159,15 @@ protected function setupPDO($name) } $dsn = sprintf('mysql:host=%s;port=%d', $this->host, $this->port); - $this->pdo[$name] = new $this->classname($dsn, $this->user, $this->password); + $opts = array(); + if (!empty($this->ssl_ca_cert)) { + if (file_exists($this->ssl_ca_cert)) { + $opts[\PDO::MYSQL_ATTR_SSL_CA] = $this->ssl_ca_cert; + } else { + error_log("Warning: specified SSL CA Certificate file doesn't exist."); + } + } + $this->pdo[$name] = new $this->classname($dsn, $this->user, $this->password, $opts); return true; } From 603eb99fa5250bc9e0b40be8102d3a07e1811756 Mon Sep 17 00:00:00 2001 From: Guillaume Boudreau Date: Tue, 13 Jun 2017 09:48:03 -0400 Subject: [PATCH 03/35] Was missing PHPDoc for new param --- src/Lock/MySqlLock.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Lock/MySqlLock.php b/src/Lock/MySqlLock.php index 5ca4674..a34833f 100644 --- a/src/Lock/MySqlLock.php +++ b/src/Lock/MySqlLock.php @@ -40,6 +40,7 @@ class MySqlLock extends LockAbstract * @param string $host * @param int $port * @param string $classname class name to create as PDO connection + * @param string $ssl_ca_cert Path to a file containing the SSL CA certificate(s), if you'd like to connect using SSL */ public function __construct($user, $password, $host, $port = 3306, $classname = 'PDO', $ssl_ca_cert = NULL) { From 0a4bbb46e2198efb463d61383036cb8a9c901488 Mon Sep 17 00:00:00 2001 From: Dominik Kasprzak Date: Wed, 28 Jun 2017 10:50:44 +0200 Subject: [PATCH 04/35] Decouple lock information provision from the lock itself, disable DNS lookup by default, add it as an optional information provider --- src/Lock/BasicLockInformationProvider.php | 30 +++++++++++++ src/Lock/LockAbstract.php | 45 ++++++++----------- src/Lock/LockInformationProviderInterface.php | 24 ++++++++++ ...esolvedHostnameLockInformationProvider.php | 29 ++++++++++++ 4 files changed, 101 insertions(+), 27 deletions(-) create mode 100644 src/Lock/BasicLockInformationProvider.php create mode 100644 src/Lock/LockInformationProviderInterface.php create mode 100644 src/Lock/ResolvedHostnameLockInformationProvider.php diff --git a/src/Lock/BasicLockInformationProvider.php b/src/Lock/BasicLockInformationProvider.php new file mode 100644 index 0000000..15f4604 --- /dev/null +++ b/src/Lock/BasicLockInformationProvider.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace NinjaMutex\Lock; + + +class BasicLockInformationProvider implements LockInformationProviderInterface +{ + /** + * @inheritdoc + */ + public function getLockInformation() + { + $pid = getmypid(); + $hostname = gethostname(); + + $params = array(); + $params[] = $pid; + $params[] = $hostname; + + return $params; + } +} diff --git a/src/Lock/LockAbstract.php b/src/Lock/LockAbstract.php index d6ebf08..5daf6e4 100644 --- a/src/Lock/LockAbstract.php +++ b/src/Lock/LockAbstract.php @@ -21,20 +21,20 @@ abstract class LockAbstract implements LockInterface const USLEEP_TIME = 100; /** - * Information which allows to track down process which acquired lock + * Provides information which allows to track down process which acquired lock * - * @var array + * @var LockInformationProviderInterface */ - protected $lockInformation = array(); + protected $lockInformationProvider; /** * @var array */ protected $locks = array(); - public function __construct() + public function __construct(LockInformationProviderInterface $informationProvider = null) { - $this->lockInformation = $this->generateLockInformation(); + $this->lockInformationProvider = $informationProvider ? : new BasicLockInformationProvider(); } public function __clone() @@ -101,37 +101,28 @@ public function acquireLock($name, $timeout = null) abstract protected function getLock($name, $blocking); /** - * Information generate by this method allow to track down process which acquired lock + * Information returned by this method allow to track down process which acquired lock * . - * By default it returns array with: - * 1. pid - * 2. server_ip - * 3. server_name - * * @return array */ - protected function generateLockInformation() + protected function getLockInformation() { - $pid = getmypid(); - $hostname = gethostname(); - $host = gethostbyname($hostname); - - // Compose data to one string - $params = array(); - $params[] = $pid; - $params[] = $host; - $params[] = $hostname; + return $this->lockInformationProvider->getLockInformation(); + } - return $params; + /** + * @return LockInformationProviderInterface + */ + public function getLockInformationProvider() + { + return $this->lockInformationProvider; } /** - * Information returned by this method allow to track down process which acquired lock - * . - * @return array + * @param LockInformationProviderInterface $lockInformationProvider */ - protected function getLockInformation() + public function setLockInformationProvider($lockInformationProvider) { - return $this->lockInformation; + $this->lockInformationProvider = $lockInformationProvider; } } diff --git a/src/Lock/LockInformationProviderInterface.php b/src/Lock/LockInformationProviderInterface.php new file mode 100644 index 0000000..8d40917 --- /dev/null +++ b/src/Lock/LockInformationProviderInterface.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace NinjaMutex\Lock; + +/** + * Provides lock debugging information + * @package NinjaMutex\Lock + */ +interface LockInformationProviderInterface +{ + /** + * Gathers lock debug information + * @return array + */ + public function getLockInformation(); +} diff --git a/src/Lock/ResolvedHostnameLockInformationProvider.php b/src/Lock/ResolvedHostnameLockInformationProvider.php new file mode 100644 index 0000000..4b8200b --- /dev/null +++ b/src/Lock/ResolvedHostnameLockInformationProvider.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace NinjaMutex\Lock; + + +class ResolvedHostnameLockInformationProvider extends BasicLockInformationProvider +{ + /** + * Adds resolved host IP to the provided information + * (WARNING! Using DNS queries at runtime may introduce significant delays to script execution, use with caution!) + * @return array + */ + public function getLockInformation() + { + $params = parent::gatherInformation(); + $params[] = gethostbyname(gethostname()); + + return $params; + } + +} From 2cc20bb9df676a4731f72aa5e321a11bc2570ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20DESTRE?= Date: Thu, 5 Nov 2015 15:14:38 +0100 Subject: [PATCH 05/35] Fix Fatal error: Call to a member function fetch() on boolean Escape lock name to prevent the generation of a broken SQL query if the lock name contains special characters ( " for example) --- src/Lock/MySqlLock.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Lock/MySqlLock.php b/src/Lock/MySqlLock.php index a34833f..4293639 100644 --- a/src/Lock/MySqlLock.php +++ b/src/Lock/MySqlLock.php @@ -87,8 +87,8 @@ protected function getLock($name, $blocking) { return !$this->isLocked($name) && $this->pdo[$name]->query( sprintf( - 'SELECT GET_LOCK("%s", %d)', - $name, + 'SELECT GET_LOCK(%s, %d)', + $this->pdo[$name]->quote($name), 0 ), PDO::FETCH_COLUMN, @@ -110,8 +110,8 @@ public function releaseLock($name) $released = (bool) $this->pdo[$name]->query( sprintf( - 'SELECT RELEASE_LOCK("%s")', - $name + 'SELECT RELEASE_LOCK(%s)', + $this->pdo[$name]->quote($name) ), PDO::FETCH_COLUMN, 0 @@ -141,8 +141,8 @@ public function isLocked($name) return !current($this->pdo)->query( sprintf( - 'SELECT IS_FREE_LOCK("%s")', - $name + 'SELECT IS_FREE_LOCK(%s)', + current($this->pdo)->quote($name) ), PDO::FETCH_COLUMN, 0 From 75833f0a4f00182e63f5f8006e7ed0eb7ed5b894 Mon Sep 17 00:00:00 2001 From: Guillaume Boudreau Date: Fri, 1 Sep 2017 09:17:39 -0400 Subject: [PATCH 06/35] Add optional 'SSL Verify Server Certificate' option to MySQL Lock Defaults to 'true', same as before. Can only be used if the PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT constant exists (PHP 7.0.18+, 7.1.4+) --- src/Lock/MySqlLock.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Lock/MySqlLock.php b/src/Lock/MySqlLock.php index 4293639..3f0558b 100644 --- a/src/Lock/MySqlLock.php +++ b/src/Lock/MySqlLock.php @@ -31,6 +31,7 @@ class MySqlLock extends LockAbstract protected $port; protected $classname; protected $ssl_ca_cert; + protected $ssl_verify_server_cert = true; /** * Provide data for PDO connection @@ -41,8 +42,9 @@ class MySqlLock extends LockAbstract * @param int $port * @param string $classname class name to create as PDO connection * @param string $ssl_ca_cert Path to a file containing the SSL CA certificate(s), if you'd like to connect using SSL + * @param bool $ssl_verify_server_cert Indicate if you want to verify that the server certificate is valid. */ - public function __construct($user, $password, $host, $port = 3306, $classname = 'PDO', $ssl_ca_cert = NULL) + public function __construct($user, $password, $host, $port = 3306, $classname = 'PDO', $ssl_ca_cert = NULL, $ssl_verify_server_cert = true) { parent::__construct(); @@ -52,6 +54,7 @@ public function __construct($user, $password, $host, $port = 3306, $classname = $this->port = $port; $this->classname = $classname; $this->ssl_ca_cert = $ssl_ca_cert; + $this->ssl_verify_server_cert = $ssl_verify_server_cert; } public function __clone() @@ -164,6 +167,9 @@ protected function setupPDO($name) if (!empty($this->ssl_ca_cert)) { if (file_exists($this->ssl_ca_cert)) { $opts[\PDO::MYSQL_ATTR_SSL_CA] = $this->ssl_ca_cert; + if (!$this->ssl_verify_server_cert && defined('\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT')) { + $opts[\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false; + } } else { error_log("Warning: specified SSL CA Certificate file doesn't exist."); } From b29bce898effcb91238d74f994e918020067bd3f Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 01:06:42 +0200 Subject: [PATCH 07/35] Drop php 5.3; not supported on travis anymore; --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0ee284c..facc573 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.3 - 5.4 - 5.5 - 5.6 From ec5304696d725b6fc2496a7ba690684dab671faa Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 01:24:13 +0200 Subject: [PATCH 08/35] Try to use travis method for extenstions. --- .travis.php.ini | 3 --- .travis.yml | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) delete mode 100644 .travis.php.ini diff --git a/.travis.php.ini b/.travis.php.ini deleted file mode 100644 index ab3c96a..0000000 --- a/.travis.php.ini +++ /dev/null @@ -1,3 +0,0 @@ -extension=memcache.so -extension=memcached.so -extension=redis.so diff --git a/.travis.yml b/.travis.yml index facc573..3bc3fee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,9 @@ services: - redis-server before_script: - - if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then cat .travis.php.ini >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; echo "Loading additional config for version $TRAVIS_PHP_VERSION" ; fi + - pecl install memcache + - pecl install memcached + - pecl install redis - composer self-update || true - composer install - ./tests/travis/mysql-setup.sh From b35d4cf0edb068ff42355c2e490131ed448e9f51 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 01:40:50 +0200 Subject: [PATCH 09/35] let's try to fix hhvm build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3bc3fee..bc4142e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,7 @@ services: - redis-server before_script: + - curl -sSf -o ~/.phpenv/versions/hhvm/bin/phpunit https://phar.phpunit.de/phpunit-5.7.phar - pecl install memcache - pecl install memcached - pecl install redis From 1c566539b1ba6bbdc20880d8b3da64fe08f3da9e Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 02:15:32 +0200 Subject: [PATCH 10/35] let's try correctly enable extensions --- .travis.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index bc4142e..a5438b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,10 +7,17 @@ php: - 7.0 - 7.1 - hhvm +env: + - MEMCACHE=1 matrix: + include: + - php: hhvm + env: MEMCACHE=0 allow_failures: - php: 7.0 - php: 7.1 + - php: hhvm + env: MEMCACHE=1 addons: code_climate: @@ -23,9 +30,9 @@ services: before_script: - curl -sSf -o ~/.phpenv/versions/hhvm/bin/phpunit https://phar.phpunit.de/phpunit-5.7.phar - - pecl install memcache - - pecl install memcached - - pecl install redis + - if [[ "$MEMCACHE" == "1" ]]; then phpenv config-add .travis.php.memcache.ini fi + - phpenv config-add .travis.php.memcached.ini + - phpenv config-add .travis.php.redis.ini - composer self-update || true - composer install - ./tests/travis/mysql-setup.sh From a34748f5c6896c0b41cb26b0fc771c0b9b5dd58e Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 02:19:24 +0200 Subject: [PATCH 11/35] fix travis.yaml --- .travis.php.memcache.ini | 1 + .travis.php.memcached.ini | 1 + .travis.php.redis.ini | 1 + .travis.yml | 14 ++++++++++---- 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 .travis.php.memcache.ini create mode 100644 .travis.php.memcached.ini create mode 100644 .travis.php.redis.ini diff --git a/.travis.php.memcache.ini b/.travis.php.memcache.ini new file mode 100644 index 0000000..587455f --- /dev/null +++ b/.travis.php.memcache.ini @@ -0,0 +1 @@ +extension=memcache.so diff --git a/.travis.php.memcached.ini b/.travis.php.memcached.ini new file mode 100644 index 0000000..7d09664 --- /dev/null +++ b/.travis.php.memcached.ini @@ -0,0 +1 @@ +extension=memcached.so diff --git a/.travis.php.redis.ini b/.travis.php.redis.ini new file mode 100644 index 0000000..6aecae4 --- /dev/null +++ b/.travis.php.redis.ini @@ -0,0 +1 @@ +extension=redis.so diff --git a/.travis.yml b/.travis.yml index a5438b2..3a53a33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,16 +8,22 @@ php: - 7.1 - hhvm env: - - MEMCACHE=1 + - MEMCACHE_EXT=1 matrix: include: + - php: 7.0 + env: MEMCACHE_EXT=0 + - php: 7.1 + env: MEMCACHE_EXT=0 - php: hhvm - env: MEMCACHE=0 + env: MEMCACHE_EXT=0 allow_failures: - php: 7.0 + env: MEMCACHE_EXT=1 - php: 7.1 + env: MEMCACHE_EXT=1 - php: hhvm - env: MEMCACHE=1 + env: MEMCACHE_EXT=1 addons: code_climate: @@ -30,7 +36,7 @@ services: before_script: - curl -sSf -o ~/.phpenv/versions/hhvm/bin/phpunit https://phar.phpunit.de/phpunit-5.7.phar - - if [[ "$MEMCACHE" == "1" ]]; then phpenv config-add .travis.php.memcache.ini fi + - if [[ "$MEMCACHE_EXT" == "1" ]]; then phpenv config-add .travis.php.memcache.ini fi - phpenv config-add .travis.php.memcached.ini - phpenv config-add .travis.php.redis.ini - composer self-update || true From c46b4a9178995e13c06dfcb99fe792cab0eef72f Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 02:23:54 +0200 Subject: [PATCH 12/35] add missing ; --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3a53a33..5ca9ced 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,7 @@ services: before_script: - curl -sSf -o ~/.phpenv/versions/hhvm/bin/phpunit https://phar.phpunit.de/phpunit-5.7.phar - - if [[ "$MEMCACHE_EXT" == "1" ]]; then phpenv config-add .travis.php.memcache.ini fi + - if [[ "$MEMCACHE_EXT" == "1" ]]; then phpenv config-add .travis.php.memcache.ini ; fi - phpenv config-add .travis.php.memcached.ini - phpenv config-add .travis.php.redis.ini - composer self-update || true From 7850581fc79bcbbe9823cb55f9f7765a4576b56c Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 02:25:35 +0200 Subject: [PATCH 13/35] drop MySQL setup --- .travis.yml | 1 - tests/travis/mysql-setup.sh | 3 --- 2 files changed, 4 deletions(-) delete mode 100755 tests/travis/mysql-setup.sh diff --git a/.travis.yml b/.travis.yml index 5ca9ced..2bffa5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,7 +41,6 @@ before_script: - phpenv config-add .travis.php.redis.ini - composer self-update || true - composer install - - ./tests/travis/mysql-setup.sh script: phpunit diff --git a/tests/travis/mysql-setup.sh b/tests/travis/mysql-setup.sh deleted file mode 100755 index 3dafca1..0000000 --- a/tests/travis/mysql-setup.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -mysql -e 'create database myapp_test;' \ No newline at end of file From ce78555ad6edbb49b36eae20e97ab049e31d0cad Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 02:58:06 +0200 Subject: [PATCH 14/35] disable memcache requirement --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 2bffa5e..6e6472a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,6 +40,7 @@ before_script: - phpenv config-add .travis.php.memcached.ini - phpenv config-add .travis.php.redis.ini - composer self-update || true + - if [[ "$MEMCACHE_EXT" == "0" ]]; then composer config platform.ext-memcache 0.0.1 ; fi - composer install script: phpunit From 06c29f7e8576d2f514eabfd89bd59c7da1a0a407 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 03:00:54 +0200 Subject: [PATCH 15/35] follow redirects --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6e6472a..0299e32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ services: - redis-server before_script: - - curl -sSf -o ~/.phpenv/versions/hhvm/bin/phpunit https://phar.phpunit.de/phpunit-5.7.phar + - curl -sSfL -o ~/.phpenv/versions/hhvm/bin/phpunit https://phar.phpunit.de/phpunit-5.7.phar - if [[ "$MEMCACHE_EXT" == "1" ]]; then phpenv config-add .travis.php.memcache.ini ; fi - phpenv config-add .travis.php.memcached.ini - phpenv config-add .travis.php.redis.ini From c3644b1dae367e706efb167448864b21f3a900a4 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 03:13:23 +0200 Subject: [PATCH 16/35] let's try with vendored phpunit --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0299e32..d16a953 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ before_script: - if [[ "$MEMCACHE_EXT" == "0" ]]; then composer config platform.ext-memcache 0.0.1 ; fi - composer install -script: phpunit +script: vendor/bin/phpunit after_script: - vendor/bin/ocular code-coverage:upload --format=php-clover build/logs/clover.xml From 5bd52401b1e700a6aa12a7814db8c70273e02598 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 03:28:38 +0200 Subject: [PATCH 17/35] hhvm works? --- .travis.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index d16a953..6ee5399 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,15 +15,11 @@ matrix: env: MEMCACHE_EXT=0 - php: 7.1 env: MEMCACHE_EXT=0 - - php: hhvm - env: MEMCACHE_EXT=0 allow_failures: - php: 7.0 env: MEMCACHE_EXT=1 - php: 7.1 env: MEMCACHE_EXT=1 - - php: hhvm - env: MEMCACHE_EXT=1 addons: code_climate: @@ -35,13 +31,13 @@ services: - redis-server before_script: - - curl -sSfL -o ~/.phpenv/versions/hhvm/bin/phpunit https://phar.phpunit.de/phpunit-5.7.phar - if [[ "$MEMCACHE_EXT" == "1" ]]; then phpenv config-add .travis.php.memcache.ini ; fi - phpenv config-add .travis.php.memcached.ini - phpenv config-add .travis.php.redis.ini - composer self-update || true - if [[ "$MEMCACHE_EXT" == "0" ]]; then composer config platform.ext-memcache 0.0.1 ; fi - composer install + - phpunit --version script: vendor/bin/phpunit From a2e55013be9ac9e96f37be010619cf4ef58b6b9b Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 03:45:34 +0200 Subject: [PATCH 18/35] let's try to skip Memcache tests if Memcache is not available --- tests/AbstractTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index 9257df6..ec2f530 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -25,6 +25,7 @@ use org\bovigo\vfs; use Predis; use Redis; +use Memcache; abstract class AbstractTest extends \PHPUnit_Framework_TestCase { @@ -64,7 +65,6 @@ public function lockImplementorProvider() // Just mocks $this->provideFlockMockLock(), $this->provideDirectoryMockLock(), - $this->provideMemcacheMockLock(), $this->provideMemcachedMockLock(), $this->provideMysqlMockLock(), $this->providePredisRedisMockLock(), @@ -72,13 +72,17 @@ public function lockImplementorProvider() // Real locks $this->provideFlockLock(), $this->provideDirectoryLock(), - array($memcacheLockFabric->create()), array($memcachedLockFabric->create()), $this->provideMysqlLock(), $this->providePredisRedisLock(), $this->providePhpRedisLock(), ); + if (class_exists("Memcache")) { + array_push($data, $this->provideMemcacheMockLock()); + array_push($data, array($memcacheLockFabric->create())); + } + return $data; } From 97833e8da47eb09daf7206eb73f283d9cd18bb31 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 03:54:03 +0200 Subject: [PATCH 19/35] try to run tests without Memcache --- tests/AbstractTest.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index ec2f530..9680cb2 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -58,7 +58,6 @@ public function tearDown() */ public function lockImplementorProvider() { - $memcacheLockFabric = new MemcacheLockFabric(); $memcachedLockFabric = new MemcachedLockFabric(); $data = array( @@ -80,6 +79,8 @@ public function lockImplementorProvider() if (class_exists("Memcache")) { array_push($data, $this->provideMemcacheMockLock()); + + $memcacheLockFabric = new MemcacheLockFabric(); array_push($data, array($memcacheLockFabric->create())); } @@ -93,12 +94,15 @@ public function lockImplementorWithBackendProvider() { $data = array( // Just mocks - $this->provideMemcacheMockLock(), $this->provideMemcachedMockLock(), $this->providePredisRedisMockLock(), $this->providePhpRedisMockLock(), ); + if (class_exists("Memcache")) { + array_push($data, $this->provideMemcacheMockLock()); + } + return $data; } @@ -107,14 +111,17 @@ public function lockImplementorWithBackendProvider() */ public function lockFabricWithExpirationProvider() { - $memcacheLockFabric = new MemcacheLockFabric(); $memcachedLockFabric = new MemcachedLockFabric(); $data = array( - array($memcacheLockFabric), array($memcachedLockFabric), ); + if (class_exists("Memcache")) { + $memcacheLockFabric = new MemcacheLockFabric(); + array_push($data, array($memcacheLockFabric)); + } + return $data; } From c7d8b575dcbf61931761d6e68a2be05b5e805518 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 03:55:42 +0200 Subject: [PATCH 20/35] use vendored phpunit --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6ee5399..0b71cb2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ before_script: - composer self-update || true - if [[ "$MEMCACHE_EXT" == "0" ]]; then composer config platform.ext-memcache 0.0.1 ; fi - composer install - - phpunit --version + - vendor/bin/phpunit --version script: vendor/bin/phpunit From 325b0b07e16ab2b0403b176e34921619fae59c10 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 04:24:10 +0200 Subject: [PATCH 21/35] let's try to update some versions --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 58269b2..9fa14b4 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,9 @@ "php": ">=5.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8 || ^5.5 || ^5.6", - "codeclimate/php-test-reporter": "^0.1 || ^0.3", - "scrutinizer/ocular": "^1.1 || ^1.3", + "phpunit/phpunit": "^4.8 || ^5.5 || ^5.6 || ^5.7 || ^6.3 || ^6.4", + "codeclimate/php-test-reporter": "^0.1 || ^0.3 || ^0.4", + "scrutinizer/ocular": "^1.1 || ^1.3 || ^1.4", "mikey179/vfsStream": "^1.4 || ^1.5 || ^1.6", "predis/predis": "^1.0 || ^1.1", "ext-memcache": "*", From f648d289816f4ea102e2b20a765093f1e9807d2b Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 04:43:59 +0200 Subject: [PATCH 22/35] fix badges --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 395c213..06337ae 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT) [![GitHub version](https://badge.fury.io/gh/arvenil%2Fninja-mutex.svg)](http://badge.fury.io/gh/arvenil%2Fninja-mutex) [![Build Status](https://travis-ci.org/arvenil/ninja-mutex.svg?branch=master)](https://travis-ci.org/arvenil/ninja-mutex) -[![HHVM Status](http://hhvm.h4cc.de/badge/arvenil/ninja-mutex.svg)](http://hhvm.h4cc.de/package/arvenil/ninja-mutex) +[![Tested](https://php-eye.com/badge/arvenil/ninja-mutex/tested.svg)](https://travis-ci.org/arvenil/ninja-mutex) +[![Partial](https://php-eye.com/badge/arvenil/ninja-mutex/partial.svg)](https://travis-ci.org/arvenil/ninja-mutex) +[![Not tested](https://php-eye.com/badge/arvenil/ninja-mutex/not-tested.svg)](https://travis-ci.org/arvenil/ninja-mutex) [![Code Climate](https://codeclimate.com/github/arvenil/ninja-mutex/badges/gpa.svg)](https://codeclimate.com/github/arvenil/ninja-mutex) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/arvenil/ninja-mutex/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/arvenil/ninja-mutex/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/arvenil/ninja-mutex/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/arvenil/ninja-mutex/?branch=master) From c9b4588435d7822f4fd8d357584c4158298ca52c Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 04:45:37 +0200 Subject: [PATCH 23/35] phpunit 6.* is not supported yet --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9fa14b4..8bebb70 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "php": ">=5.3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8 || ^5.5 || ^5.6 || ^5.7 || ^6.3 || ^6.4", + "phpunit/phpunit": "^4.8 || ^5.5 || ^5.6 || ^5.7", "codeclimate/php-test-reporter": "^0.1 || ^0.3 || ^0.4", "scrutinizer/ocular": "^1.1 || ^1.3 || ^1.4", "mikey179/vfsStream": "^1.4 || ^1.5 || ^1.6", From ad72db8a83ab337d3b9a2d82aad36aeddea22faa Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 04:52:11 +0200 Subject: [PATCH 24/35] reverse variable for nicer travis-ci summary --- .travis.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0b71cb2..a1170ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,19 +7,17 @@ php: - 7.0 - 7.1 - hhvm -env: - - MEMCACHE_EXT=1 matrix: include: - php: 7.0 - env: MEMCACHE_EXT=0 + env: SKIP_MEMCACHE=1 - php: 7.1 - env: MEMCACHE_EXT=0 + env: SKIP_MEMCACHE=1 allow_failures: - php: 7.0 - env: MEMCACHE_EXT=1 + env: - php: 7.1 - env: MEMCACHE_EXT=1 + env: addons: code_climate: @@ -31,11 +29,11 @@ services: - redis-server before_script: - - if [[ "$MEMCACHE_EXT" == "1" ]]; then phpenv config-add .travis.php.memcache.ini ; fi + - if [[ "$SKIP_MEMCACHE" != "1" ]]; then phpenv config-add .travis.php.memcache.ini ; fi - phpenv config-add .travis.php.memcached.ini - phpenv config-add .travis.php.redis.ini - composer self-update || true - - if [[ "$MEMCACHE_EXT" == "0" ]]; then composer config platform.ext-memcache 0.0.1 ; fi + - if [[ "$SKIP_MEMCACHE" == "1" ]]; then composer config platform.ext-memcache 0.0.1 ; fi - composer install - vendor/bin/phpunit --version From bc3a47e3881856d4fcd0546836cebb8700ba24b1 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 05:05:13 +0200 Subject: [PATCH 25/35] rename variable --- .travis.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index a1170ed..4cc2aca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,11 +8,13 @@ php: - 7.1 - hhvm matrix: + # Memcache extension is unsupported in php 7 + # https://github.com/websupport-sk/pecl-memcache/issues/11 include: - php: 7.0 - env: SKIP_MEMCACHE=1 + env: MEMCACHE_EXT_UNSUPPORTED=1 - php: 7.1 - env: SKIP_MEMCACHE=1 + env: MEMCACHE_EXT_UNSUPPORTED=1 allow_failures: - php: 7.0 env: @@ -29,11 +31,14 @@ services: - redis-server before_script: - - if [[ "$SKIP_MEMCACHE" != "1" ]]; then phpenv config-add .travis.php.memcache.ini ; fi + # If Memcache is supported then enable it + - if [[ "$MEMCACHE_EXT_UNSUPPORTED" != "1" ]]; then phpenv config-add .travis.php.memcache.ini ; fi - phpenv config-add .travis.php.memcached.ini - phpenv config-add .travis.php.redis.ini - composer self-update || true - - if [[ "$SKIP_MEMCACHE" == "1" ]]; then composer config platform.ext-memcache 0.0.1 ; fi + # If Memcache extension is not supported we need to fake it, + # otherwise composer will complain about missing dev dependencies + - if [[ "$MEMCACHE_EXT_UNSUPPORTED" == "1" ]]; then composer config platform.ext-memcache 0.0.1 ; fi - composer install - vendor/bin/phpunit --version From 78ccdfe346f47959ffb07b5fb8171982e58116af Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 05:13:03 +0200 Subject: [PATCH 26/35] re-add php 5.3 but allow to fail --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4cc2aca..d715443 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: php php: + - 5.3 - 5.4 - 5.5 - 5.6 @@ -16,6 +17,8 @@ matrix: - php: 7.1 env: MEMCACHE_EXT_UNSUPPORTED=1 allow_failures: + - php: 5.3 + env: - php: 7.0 env: - php: 7.1 From c27cfe4bf9f3e2513b66600b0e754af8476e5e4e Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sat, 7 Oct 2017 05:17:05 +0200 Subject: [PATCH 27/35] cleanups --- .travis.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index d715443..29c0898 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,14 +9,16 @@ php: - 7.1 - hhvm matrix: - # Memcache extension is unsupported in php 7 - # https://github.com/websupport-sk/pecl-memcache/issues/11 include: + # Memcache extension is not supported in php 7 + # https://github.com/websupport-sk/pecl-memcache/issues/11 - php: 7.0 env: MEMCACHE_EXT_UNSUPPORTED=1 - php: 7.1 env: MEMCACHE_EXT_UNSUPPORTED=1 allow_failures: + # PHP 5.3 is no longer supported on travis + # https://docs.travis-ci.com/user/languages/php#PHP-5.2(.x)-and-5.3(.x)-support-is-available-on-Precise-only - php: 5.3 env: - php: 7.0 @@ -34,13 +36,13 @@ services: - redis-server before_script: - # If Memcache is supported then enable it + # If Memcache is supported then enable it. - if [[ "$MEMCACHE_EXT_UNSUPPORTED" != "1" ]]; then phpenv config-add .travis.php.memcache.ini ; fi - phpenv config-add .travis.php.memcached.ini - phpenv config-add .travis.php.redis.ini - composer self-update || true # If Memcache extension is not supported we need to fake it, - # otherwise composer will complain about missing dev dependencies + # otherwise composer will complain about missing dev dependencies. - if [[ "$MEMCACHE_EXT_UNSUPPORTED" == "1" ]]; then composer config platform.ext-memcache 0.0.1 ; fi - composer install - vendor/bin/phpunit --version From e66eee53e18d430b6bf27184d9c65ca2e2c66fec Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sun, 8 Oct 2017 17:47:24 +0200 Subject: [PATCH 28/35] mock pdo->quote() --- tests/Mock/MockPDO.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/Mock/MockPDO.php b/tests/Mock/MockPDO.php index 9a75dcb..93fd303 100644 --- a/tests/Mock/MockPDO.php +++ b/tests/Mock/MockPDO.php @@ -53,6 +53,24 @@ public function query($statement) } } + /** + * Quotes a string for use in a query. + * @link http://php.net/manual/en/pdo.quote.php + * @param string $string

+ * The string to be quoted. + *

+ * @param int $parameter_type [optional]

+ * Provides a data type hint for drivers that have alternate quoting styles. + *

+ * @return string a quoted string that is theoretically safe to pass into an + * SQL statement. Returns FALSE if the driver does not support quoting in + * this way. + */ + public function quote ($string, $parameter_type = PDO::PARAM_STR) + { + return $string; + } + /** * @param string $key * @param int $timeout From 5bbff604addbec6852c4ed6472649bea135e432a Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sun, 8 Oct 2017 17:59:39 +0200 Subject: [PATCH 29/35] fix mock --- tests/Mock/MockPDO.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Mock/MockPDO.php b/tests/Mock/MockPDO.php index 93fd303..ffb92d5 100644 --- a/tests/Mock/MockPDO.php +++ b/tests/Mock/MockPDO.php @@ -44,11 +44,11 @@ public function __construct($dsn, $user, $password) */ public function query($statement) { - if (preg_match('/RELEASE_LOCK\("(.*)"\)/', $statement, $m)) { + if (preg_match('/RELEASE_LOCK\((.*)\)/', $statement, $m)) { return $this->_mock_release_lock($m[1]); - } elseif (preg_match('/GET_LOCK\("(.*)", *(.*)\)/', $statement, $m)) { + } elseif (preg_match('/GET_LOCK\((.*), *(.*)\)/', $statement, $m)) { return $this->_mock_get_lock($m[1], $m[2]); - } elseif (preg_match('/IS_FREE_LOCK\("(.*)"\)/', $statement, $m)) { + } elseif (preg_match('/IS_FREE_LOCK\((.*)\)/', $statement, $m)) { return $this->_mock_is_free_lock($m[1]); } } From 7a2c80c2e9171fc0831b101f67c05743ecc99574 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sun, 8 Oct 2017 18:49:16 +0200 Subject: [PATCH 30/35] use default blocking method --- src/Lock/DirectoryLock.php | 10 +--------- src/Lock/LockAbstract.php | 3 ++- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Lock/DirectoryLock.php b/src/Lock/DirectoryLock.php index f3c9a9c..1e309ca 100644 --- a/src/Lock/DirectoryLock.php +++ b/src/Lock/DirectoryLock.php @@ -35,15 +35,7 @@ public function __construct($dirname) */ protected function getLock($name, $blocking) { - while (!@mkdir($this->getDirectoryPath($name))) { - if (!$blocking) { - return false; - } - - usleep(rand(5000, 20000)); - } - - return true; + return @mkdir($this->getDirectoryPath($name)); } /** diff --git a/src/Lock/LockAbstract.php b/src/Lock/LockAbstract.php index 5daf6e4..90bcafb 100644 --- a/src/Lock/LockAbstract.php +++ b/src/Lock/LockAbstract.php @@ -95,7 +95,8 @@ public function acquireLock($name, $timeout = null) /** * @param string $name - * @param bool $blocking + * @param bool $blocking If lock provider supports blocking then you can pass this param through, + * otherwise, ignore this variable, default blocking method will be used. * @return bool */ abstract protected function getLock($name, $blocking); From 6208737689420217c0525e1f807c0673250d8285 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sun, 8 Oct 2017 20:14:18 +0200 Subject: [PATCH 31/35] re-arrange parameters to be inline with PDO::__construct() Also rename class to force updating parameters --- composer.json | 2 +- src/Lock/{MySqlLock.php => MySQLPDOLock.php} | 67 ++++++++++---------- tests/AbstractTest.php | 6 +- tests/Mock/MockPDO.php | 25 ++++++-- 4 files changed, 57 insertions(+), 43 deletions(-) rename src/Lock/{MySqlLock.php => MySQLPDOLock.php} (66%) diff --git a/composer.json b/composer.json index 8bebb70..57d820d 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,6 @@ "predis/predis" : "Create mutex using Predis (client library for Redis)", "ext-memcache": "Create mutex using memcache extension", "ext-memcached": "Create mutex using memcached extension", - "ext-pdo_mysql": "Create mutex using MySql" + "ext-pdo_mysql": "Create mutex using MySQL PDO" } } diff --git a/src/Lock/MySqlLock.php b/src/Lock/MySQLPDOLock.php similarity index 66% rename from src/Lock/MySqlLock.php rename to src/Lock/MySQLPDOLock.php index 3f0558b..ebc981e 100644 --- a/src/Lock/MySqlLock.php +++ b/src/Lock/MySQLPDOLock.php @@ -12,49 +12,58 @@ use PDO; /** - * Lock implementor using MySql + * Lock implementor using MySQL PDO driver * * @author Kamil Dziedzic */ -class MySqlLock extends LockAbstract +class MySQLPDOLock extends LockAbstract { /** - * MySql connections + * MySQL connections * * @var PDO[] */ protected $pdo = array(); - protected $user; - protected $password; - protected $host; - protected $port; + /** + * @var string + */ + protected $dsn; + /** + * @var string + */ + protected $username; + /** + * @var string + */ + protected $passwd; + /** + * @var array + */ + protected $options; + /** + * @var string + */ protected $classname; - protected $ssl_ca_cert; - protected $ssl_verify_server_cert = true; /** * Provide data for PDO connection * - * @param string $user - * @param string $password - * @param string $host - * @param int $port + * @param string $dsn + * @param string $username + * @param string $passwd + * @param array $options * @param string $classname class name to create as PDO connection - * @param string $ssl_ca_cert Path to a file containing the SSL CA certificate(s), if you'd like to connect using SSL - * @param bool $ssl_verify_server_cert Indicate if you want to verify that the server certificate is valid. */ - public function __construct($user, $password, $host, $port = 3306, $classname = 'PDO', $ssl_ca_cert = NULL, $ssl_verify_server_cert = true) + public function __construct($dsn, $username = null, $passwd = null, $options = null, $classname = 'PDO') { parent::__construct(); - $this->user = $user; - $this->password = $password; - $this->host = $host; - $this->port = $port; + $this->dsn = $dsn; + $this->username = $username; + $this->passwd = $passwd; + $this->options = $options; $this->classname = $classname; - $this->ssl_ca_cert = $ssl_ca_cert; - $this->ssl_verify_server_cert = $ssl_verify_server_cert; } public function __clone() @@ -162,19 +171,7 @@ protected function setupPDO($name) return true; } - $dsn = sprintf('mysql:host=%s;port=%d', $this->host, $this->port); - $opts = array(); - if (!empty($this->ssl_ca_cert)) { - if (file_exists($this->ssl_ca_cert)) { - $opts[\PDO::MYSQL_ATTR_SSL_CA] = $this->ssl_ca_cert; - if (!$this->ssl_verify_server_cert && defined('\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT')) { - $opts[\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false; - } - } else { - error_log("Warning: specified SSL CA Certificate file doesn't exist."); - } - } - $this->pdo[$name] = new $this->classname($dsn, $this->user, $this->password, $opts); + $this->pdo[$name] = new $this->classname($this->dsn, $this->username, $this->passwd, $this->options); return true; } diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index 9680cb2..a4d941a 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -13,7 +13,7 @@ use NinjaMutex\Lock\FlockLock; use NinjaMutex\Lock\MemcachedLock; use NinjaMutex\Lock\MemcacheLock; -use NinjaMutex\Lock\MySqlLock; +use NinjaMutex\Lock\MySQLPDOLock; use NinjaMutex\Lock\PredisRedisLock; use NinjaMutex\Lock\PhpRedisLock; use NinjaMutex\Tests\Lock\Fabric\MemcachedLockFabric; @@ -166,7 +166,7 @@ protected function provideDirectoryMockLock() */ protected function provideMysqlMockLock() { - return array(new MySqlLock('', '', '', 3306, 'NinjaMutex\Tests\Mock\MockPDO')); + return array(new MySQLPDOLock('', null, null, null, 'NinjaMutex\Tests\Mock\MockPDO')); } /** @@ -210,7 +210,7 @@ protected function provideDirectoryLock() */ protected function provideMysqlLock() { - return array(new MySqlLock('root', '', '127.0.0.1')); + return array(new MySQLPDOLock('', 'root', '')); } /** diff --git a/tests/Mock/MockPDO.php b/tests/Mock/MockPDO.php index ffb92d5..3b77134 100644 --- a/tests/Mock/MockPDO.php +++ b/tests/Mock/MockPDO.php @@ -10,6 +10,7 @@ namespace NinjaMutex\Tests\Mock; use PDO; +use PDOStatement; /** * Mock PDO to mimic *_lock functionality @@ -33,16 +34,32 @@ class MockPDO extends PDO */ protected $current = array(); - public function __construct($dsn, $user, $password) + public function __construct($dsn, $user, $password, $options) { $this->_mock_pdo_statement = new MockPDOStatement(); } /** - * @param string $statement - * @return MockPDOStatement + * @param string $statement

+ * The SQL statement to prepare and execute. + *

+ *

+ * Data inside the query should be properly escaped. + *

+ * @param int $mode

+ * The fetch mode must be one of the PDO::FETCH_* constants. + *

+ * @param mixed $arg3

+ * The second and following parameters are the same as the parameters for PDOStatement::setFetchMode. + *

+ * @param array $ctorargs [optional]

+ * Arguments of custom class constructor when the mode + * parameter is set to PDO::FETCH_CLASS. + *

+ * @return PDOStatement PDO::query returns a PDOStatement object, or FALSE + * on failure. */ - public function query($statement) + public function query ($statement, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = array()) { if (preg_match('/RELEASE_LOCK\((.*)\)/', $statement, $m)) { return $this->_mock_release_lock($m[1]); From 63c524a92fe50fa3df9c0b4b87cd033832978960 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sun, 8 Oct 2017 20:18:24 +0200 Subject: [PATCH 32/35] fix comments --- tests/Mock/MockPDO.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/Mock/MockPDO.php b/tests/Mock/MockPDO.php index 3b77134..2744dfb 100644 --- a/tests/Mock/MockPDO.php +++ b/tests/Mock/MockPDO.php @@ -34,12 +34,22 @@ class MockPDO extends PDO */ protected $current = array(); - public function __construct($dsn, $user, $password, $options) + /** + * Creates a PDO instance representing a connection to a database + * @link http://php.net/manual/en/pdo.construct.php + * @param $dsn + * @param $username [optional] + * @param $passwd [optional] + * @param $options [optional] + */ + public function __construct($dsn, $username, $passwd, $options) { $this->_mock_pdo_statement = new MockPDOStatement(); } /** + * Executes an SQL statement, returning a result set as a PDOStatement object + * @link http://php.net/manual/en/pdo.query.php * @param string $statement

* The SQL statement to prepare and execute. *

From 73ec9b750865f218cb7113cbe12d4ff09bad12d0 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sun, 8 Oct 2017 20:34:39 +0200 Subject: [PATCH 33/35] missing 'mysql:' in dsn --- tests/AbstractTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index a4d941a..9c4667d 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -210,7 +210,7 @@ protected function provideDirectoryLock() */ protected function provideMysqlLock() { - return array(new MySQLPDOLock('', 'root', '')); + return array(new MySQLPDOLock('mysql:', 'root', '')); } /** From cd757931cd60fc1f42708e8f33d1ad0ebb4bf7a1 Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sun, 8 Oct 2017 20:41:20 +0200 Subject: [PATCH 34/35] fix comment --- src/Lock/MySQLPDOLock.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Lock/MySQLPDOLock.php b/src/Lock/MySQLPDOLock.php index ebc981e..32c6c8c 100644 --- a/src/Lock/MySQLPDOLock.php +++ b/src/Lock/MySQLPDOLock.php @@ -49,11 +49,14 @@ class MySQLPDOLock extends LockAbstract /** * Provide data for PDO connection * + * @link http://php.net/manual/en/pdo.construct.php * @param string $dsn - * @param string $username - * @param string $passwd - * @param array $options - * @param string $classname class name to create as PDO connection + * @param string $username [optional] + * @param string $passwd [optional] + * @param array $options [optional] + * + * @param string $classname class name to create as PDO connection, + * by default this is PDO, but in tests we can inject MockPDO */ public function __construct($dsn, $username = null, $passwd = null, $options = null, $classname = 'PDO') { From 3dae88714ff2e33e2695625394b8ae73552cdeec Mon Sep 17 00:00:00 2001 From: Kamil Dziedzic Date: Sun, 8 Oct 2017 20:44:55 +0200 Subject: [PATCH 35/35] fmt --- tests/Mock/MockPDO.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Mock/MockPDO.php b/tests/Mock/MockPDO.php index 2744dfb..ef78534 100644 --- a/tests/Mock/MockPDO.php +++ b/tests/Mock/MockPDO.php @@ -39,8 +39,8 @@ class MockPDO extends PDO * @link http://php.net/manual/en/pdo.construct.php * @param $dsn * @param $username [optional] - * @param $passwd [optional] - * @param $options [optional] + * @param $passwd [optional] + * @param $options [optional] */ public function __construct($dsn, $username, $passwd, $options) { @@ -69,7 +69,7 @@ public function __construct($dsn, $username, $passwd, $options) * @return PDOStatement PDO::query returns a PDOStatement object, or FALSE * on failure. */ - public function query ($statement, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = array()) + public function query($statement, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = array()) { if (preg_match('/RELEASE_LOCK\((.*)\)/', $statement, $m)) { return $this->_mock_release_lock($m[1]); @@ -93,7 +93,7 @@ public function query ($statement, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = * SQL statement. Returns FALSE if the driver does not support quoting in * this way. */ - public function quote ($string, $parameter_type = PDO::PARAM_STR) + public function quote($string, $parameter_type = PDO::PARAM_STR) { return $string; }