Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions classes/mutex/SemaphoreMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class SemaphoreMutex extends LockMutex
{
/**
* @var resource The semaphore id.
* @var \SysvSemaphore|resource The semaphore id.
*/
private $semaphore;

Expand All @@ -33,12 +33,12 @@ class SemaphoreMutex extends LockMutex
* $mutex = new SemaphoreMutex($semaphore);
* </code>
*
* @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;
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
},
"require": {
"php": "^7.2",
"php": "^7.2 || ^8.0",
"psr/log": "^1"
},
"require-dev": {
Expand All @@ -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",
Expand Down
13 changes: 8 additions & 5 deletions tests/mutex/MutexConcurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}],
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions tests/mutex/MutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions tests/mutex/PHPRedisMutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down