diff --git a/classes/mutex/SemaphoreMutex.php b/classes/mutex/SemaphoreMutex.php index 006d7989..13f94bdb 100644 --- a/classes/mutex/SemaphoreMutex.php +++ b/classes/mutex/SemaphoreMutex.php @@ -18,7 +18,7 @@ class SemaphoreMutex extends LockMutex { /** - * @var resource The semaphore id. + * @var \SysvSemaphore|resource The semaphore id. */ private $semaphore; @@ -33,12 +33,12 @@ class SemaphoreMutex extends LockMutex * $mutex = new SemaphoreMutex($semaphore); * * - * @param resource $semaphore The semaphore id. + * @param \SysvSemaphore|resource $semaphore The semaphore id. * @throws \InvalidArgumentException The semaphore id is not a valid resource. */ public function __construct($semaphore) { - if (!is_resource($semaphore)) { + if (!$semaphore instanceof \SysvSemaphore && !is_resource($semaphore)) { throw new InvalidArgumentException('The semaphore id is not a valid resource.'); } $this->semaphore = $semaphore; diff --git a/composer.json b/composer.json index b91c1e56..73d571a8 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ } }, "require": { - "php": "^7.2", + "php": "^7.2 || ^8.0", "psr/log": "^1" }, "require-dev": { @@ -55,7 +55,7 @@ "eloquent/liberator": "^2.0", "friendsofphp/php-cs-fixer": "^2.16", "johnkary/phpunit-speedtrap": "^3.0", - "mikey179/vfsstream": "^1.6", + "mikey179/vfsstream": "^1.6.7", "php-mock/php-mock-phpunit": "^2.1", "phpstan/phpstan": "^0.12.58", "phpunit/phpunit": "^9.4", diff --git a/tests/mutex/MutexConcurrencyTest.php b/tests/mutex/MutexConcurrencyTest.php index c3e908ff..b25d2ed5 100644 --- a/tests/mutex/MutexConcurrencyTest.php +++ b/tests/mutex/MutexConcurrencyTest.php @@ -252,7 +252,7 @@ public function provideMutexFactories() 'semaphore' => [function ($timeout = 3) use ($filename): Mutex { $semaphore = sem_get(ftok($filename, 'b')); - $this->assertTrue(is_resource($semaphore)); + $this->assertTrue($semaphore instanceof \SysvSemaphore || is_resource($semaphore)); // @phpstan-ignore-line return new SemaphoreMutex($semaphore); }], @@ -290,10 +290,13 @@ function (string $uri): Redis { $redis = new Redis(); $uri = parse_url($uri); - if (!empty($uri['port'])) { - $redis->connect($uri['host'], $uri['port']); - } else { - $redis->connect($uri['host']); + $redis->connect($uri['host'], $uri['port'] ?? 6379); + if (!empty($uri['pass'])) { + $redis->auth( + empty($uri['user']) + ? $uri['pass'] + : [$uri['user'], $uri['pass']] + ); } return $redis; diff --git a/tests/mutex/MutexTest.php b/tests/mutex/MutexTest.php index 64d424ff..d5d04375 100644 --- a/tests/mutex/MutexTest.php +++ b/tests/mutex/MutexTest.php @@ -133,10 +133,13 @@ function ($uri) { $redis = new Redis(); $uri = parse_url($uri); - if (!empty($uri['port'])) { - $redis->connect($uri['host'], $uri['port']); - } else { - $redis->connect($uri['host']); + $redis->connect($uri['host'], $uri['port'] ?? 6379); + if (!empty($uri['pass'])) { + $redis->auth( + empty($uri['user']) + ? $uri['pass'] + : [$uri['user'], $uri['pass']] + ); } return $redis; diff --git a/tests/mutex/PHPRedisMutexTest.php b/tests/mutex/PHPRedisMutexTest.php index 28457e5f..01b82e5b 100644 --- a/tests/mutex/PHPRedisMutexTest.php +++ b/tests/mutex/PHPRedisMutexTest.php @@ -74,10 +74,13 @@ public function eval($script, $args = [], $numKeys = 0) } }; - if (!empty($uri['port'])) { - $connection->connect($uri['host'], $uri['port']); - } else { - $connection->connect($uri['host']); + $connection->connect($uri['host'], $uri['port'] ?? 6379); + if (!empty($uri['pass'])) { + $connection->auth( + empty($uri['user']) + ? $uri['pass'] + : [$uri['user'], $uri['pass']] + ); } $connection->flushAll(); // Clear any existing locks.