Skip to content

Commit f798295

Browse files
authored
Merge pull request #5 from maksimovic/php85
PHP 8.5 support, CI improvements, and test coverage
2 parents c519533 + a051f66 commit f798295

7 files changed

Lines changed: 86 additions & 34 deletions

File tree

.github/workflows/ci.yml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
name: CI
22

3-
on: [push]
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
47

58
jobs:
6-
build-test:
9+
test:
710
runs-on: ubuntu-latest
811
strategy:
912
fail-fast: false
1013
matrix:
11-
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
12-
name: PHP ${{ matrix.php-versions }} Test
14+
php-version: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
15+
name: PHP ${{ matrix.php-version }} Test
1316
services:
1417
redis:
1518
image: redis
@@ -22,30 +25,30 @@ jobs:
2225
- 6379:6379
2326
steps:
2427
- name: Checkout Code
25-
uses: actions/checkout@v3
28+
uses: actions/checkout@v4
2629

2730
- name: Install PHP
2831
uses: shivammathur/setup-php@v2
2932
with:
30-
php-version: ${{ matrix.php-versions }}
31-
extensions: :redis
33+
php-version: ${{ matrix.php-version }}
34+
extensions: pcntl, sysvshm, sysvsem, sysvmsg, redis
35+
coverage: ${{ matrix.php-version == '8.5' && 'xdebug' || 'none' }}
3236

33-
- name: Install composer and dependencies
34-
uses: php-actions/composer@v6
37+
- name: Install dependencies
38+
run: composer install --no-interaction --prefer-dist
3539

36-
- name: PHPUnit Tests
37-
uses: php-actions/phpunit@v3
38-
env:
39-
XDEBUG_MODE: coverage
40-
with:
41-
bootstrap: vendor/autoload.php
42-
configuration: phpunit.xml
43-
php_extensions: xdebug sysvshm pcntl sysvsem sysvmsg redis
44-
version: 9
45-
args: tests --coverage-clover ./coverage.xml
40+
- name: Run tests (with coverage)
41+
if: matrix.php-version == '8.5'
42+
run: |
43+
XDEBUG_MODE=coverage vendor/bin/phpunit --configuration phpunit.xml --coverage-clover ./coverage.xml
44+
45+
- name: Run tests
46+
if: matrix.php-version != '8.5'
47+
run: vendor/bin/phpunit --configuration phpunit.xml
4648

4749
- name: Upload to Codecov
48-
uses: codecov/codecov-action@v3
50+
if: matrix.php-version == '8.5'
51+
uses: codecov/codecov-action@v4
4952
env:
5053
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5154
with:

src/Lock/Semaphore.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
class Semaphore implements LockInterface
1717
{
18+
/** @var false|resource|\SysvSemaphore */
1819
private $lock_id;
1920

2021
/**
@@ -151,17 +152,13 @@ public function remove()
151152
if ($this->locked) {
152153
throw new \RuntimeException('can not remove a locked semaphore resource');
153154
}
154-
if (!is_resource($this->lock_id)) {
155-
throw new \RuntimeException('can not remove a empty semaphore resource');
156-
}
157155

158-
// @codeCoverageIgnoreStart
159-
// seems impossible to reproduce further below
160-
if (!sem_release($this->lock_id)) {
161-
return false;
162-
}
156+
if (is_resource($this->lock_id) || $this->lock_id instanceof \SysvSemaphore) {
157+
$result = sem_remove($this->lock_id);
158+
$this->lock_id = null;
159+
return $result;
160+
}
163161

164-
return true;
165-
// @codeCoverageIgnoreEnd
166-
}
167-
}
162+
throw new \RuntimeException('can not remove a empty semaphore resource');
163+
}
164+
}

src/Process.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Process
7575
* @param string|callable|null $execution it can be a Runnable object, callback function or null
7676
* @param string|null $name process name,you can manager the process by it's name.
7777
*/
78-
public function __construct($execution = null, string $name = null)
78+
public function __construct($execution = null, ?string $name = null)
7979
{
8080
if ($execution instanceof Runnable) {
8181
$this->runnable = $execution;

tests/FileCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testCacheExpiration()
3434
$this->assertTrue($cache->delete($key));
3535
$this->assertNull($cache->get($key));
3636
$this->assertTrue($cache->flush());
37-
$this->assertFileDoesNotExist($path);
37+
$this->assertFalse(file_exists($path));
3838
}
3939

4040
/**

tests/PipeQueueTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ public function testPutAndGet()
2323
$queue->remove();
2424
}
2525

26+
public function testGetFromEmptyQueue()
27+
{
28+
$queue = new \Jenner\SimpleFork\Queue\PipeQueue();
29+
$this->assertNull($queue->get());
30+
$queue->remove();
31+
}
32+
2633
public function testValueTooLong()
2734
{
2835
$memory_limit = ini_get('memory_limit');

tests/ProcessTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,42 @@ public function testInvalidProcess(): void
115115
new \Jenner\SimpleFork\Process("abc");
116116
}
117117

118+
public function testGetPid(): void
119+
{
120+
$process = new \Jenner\SimpleFork\Process(function () {
121+
usleep(100000);
122+
});
123+
$this->assertNull($process->getPid());
124+
$process->start();
125+
$this->assertIsInt($process->getPid());
126+
$this->assertGreaterThan(0, $process->getPid());
127+
$process->wait();
128+
}
129+
130+
public function testName(): void
131+
{
132+
$process = new \Jenner\SimpleFork\Process(function () {}, 'my-process');
133+
$this->assertEquals('my-process', $process->name());
134+
135+
$process->name('renamed');
136+
$this->assertEquals('renamed', $process->name());
137+
}
138+
139+
public function testIsStartedAndIsStopped(): void
140+
{
141+
$process = new \Jenner\SimpleFork\Process(function () {
142+
usleep(100000);
143+
});
144+
$this->assertFalse($process->isStarted());
145+
$this->assertFalse($process->isStopped());
146+
147+
$process->start();
148+
$this->assertTrue($process->isStarted());
149+
150+
$process->wait();
151+
$this->assertTrue($process->isStopped());
152+
}
153+
118154
}
119155

120156
class MyThread extends \Jenner\SimpleFork\Process

tests/SemaphoreTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public function testRemoveLockWhenLockReleased()
7676
$this->lock->acquire(false);
7777
$this->lock->release();
7878

79+
$this->assertTrue($this->lock->remove());
80+
}
81+
82+
public function testRemoveAlreadyRemovedSemaphore()
83+
{
84+
$this->lock->acquire(false);
85+
$this->lock->release();
86+
$this->lock->remove();
87+
7988
$this->expectException(RuntimeException::class);
8089
$this->expectExceptionMessage("can not remove a empty semaphore resource");
8190
$this->lock->remove();

0 commit comments

Comments
 (0)