Skip to content

Commit 4c451f2

Browse files
committed
Add basic CI testing
1 parent 9d92bcb commit 4c451f2

File tree

3 files changed

+84
-28
lines changed

3 files changed

+84
-28
lines changed

.github/workflows/test-unit.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Unit
2+
3+
on:
4+
pull_request:
5+
push:
6+
schedule:
7+
- cron: '0 0/2 * * *'
8+
9+
jobs:
10+
smoke-test:
11+
name: Smoke
12+
runs-on: ubuntu-latest
13+
container:
14+
image: ghcr.io/mvorisek/image-php:${{ matrix.php }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
php: ['8.0']
19+
type: ['Phpunit']
20+
include:
21+
- php: '8.0'
22+
type: 'CodingStyle'
23+
- php: '8.0'
24+
type: 'StaticAnalysis'
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Configure PHP
30+
run: |
31+
install-php-extensions memcached sysvsem
32+
rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
33+
php --version
34+
35+
- name: Install PHP dependencies
36+
run: |
37+
if [ "${{ matrix.type }}" != "Phpunit" ] && [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpunit/phpunit ergebnis/phpunit-slow-test-detector --dev; fi
38+
if [ "${{ matrix.type }}" != "CodingStyle" ]; then composer remove --no-interaction --no-update friendsofphp/php-cs-fixer ergebnis/composer-normalize --dev; fi
39+
if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/\* --dev; fi
40+
composer update --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader
41+
42+
- name: "Run tests (only for Phpunit)"
43+
if: startsWith(matrix.type, 'Phpunit')
44+
run: |
45+
vendor/bin/phpunit --exclude-group none --no-coverage --fail-on-warning --fail-on-risky $(if vendor/bin/phpunit --version | grep -q '^PHPUnit 9\.'; then echo -v; else echo --fail-on-notice --fail-on-deprecation --display-notices --display-deprecations --display-warnings --display-errors --display-incomplete --display-skipped; fi) --filter '^(?!malkusch\\lock\\mutex\\PHPRedisMutexTest::)'
46+
47+
- name: Check Coding Style (only for CodingStyle)
48+
if: matrix.type == 'CodingStyle'
49+
run: |
50+
vendor/bin/php-cs-fixer fix --dry-run --using-cache=no --diff --verbose
51+
composer validate --strict --no-check-lock && composer normalize --dry-run --no-check-lock
52+
53+
- name: Run Static Analysis (only for StaticAnalysis)
54+
if: matrix.type == 'StaticAnalysis'
55+
run: |
56+
echo "memory_limit = 2G" > /usr/local/etc/php/conf.d/custom-memory-limit.ini
57+
vendor/bin/phpstan analyse -v

composer.json

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,21 @@
2121
{
2222
"name": "Markus Malkusch",
2323
"email": "[email protected]",
24-
"homepage": "http://markus.malkusch.de",
25-
"role": "Developer"
24+
"homepage": "http://markus.malkusch.de"
2625
},
2726
{
2827
"name": "Willem Stuursma-Ruwen",
29-
"email": "[email protected]",
30-
"role": "Developer"
28+
"email": "[email protected]"
29+
},
30+
{
31+
"name": "Michael Voříšek",
32+
"homepage": "https://mvorisek.cz/"
3133
}
3234
],
3335
"homepage": "https://github.com/malkusch/lock",
34-
"autoload": {
35-
"psr-4": {
36-
"malkusch\\lock\\": "src/"
37-
}
38-
},
39-
"autoload-dev": {
40-
"psr-4": {
41-
"malkusch\\lock\\": "tests/"
42-
}
43-
},
4436
"require": {
45-
"php": "^7.2 || ^8.0",
46-
"psr/log": "^1|^2|^3"
37+
"php": ">=7.2 <8.4",
38+
"psr/log": "^1 || ^2 || ^3"
4739
},
4840
"require-dev": {
4941
"ext-memcached": "*",
@@ -53,6 +45,7 @@
5345
"ext-pdo_sqlite": "*",
5446
"ext-sysvsem": "*",
5547
"eloquent/liberator": "^2.0",
48+
"ergebnis/composer-normalize": "^2.13",
5649
"friendsofphp/php-cs-fixer": "^2.16",
5750
"johnkary/phpunit-speedtrap": "^3.0",
5851
"mikey179/vfsstream": "^1.6.7",
@@ -71,20 +64,26 @@
7164
"ext-sysvsem": "Enables locking using semaphores.",
7265
"predis/predis": "To use this library with predis."
7366
},
74-
"archive": {
75-
"exclude": [
76-
"/tests",
77-
"/.gitattributes",
78-
"/.gitignore",
79-
"/.travis.yml",
80-
"/phpunit.xml",
81-
"/.github"
82-
]
67+
"minimum-stability": "dev",
68+
"prefer-stable": true,
69+
"autoload": {
70+
"psr-4": {
71+
"malkusch\\lock\\": "src/"
72+
}
8373
},
84-
"scripts": {
85-
"fix-cs": "vendor/bin/phpcbf --standard=PSR2 src/ tests/"
74+
"autoload-dev": {
75+
"psr-4": {
76+
"malkusch\\lock\\": "tests/"
77+
}
8678
},
8779
"config": {
80+
"allow-plugins": {
81+
"ergebnis/composer-normalize": true,
82+
"phpstan/extension-installer": true
83+
},
8884
"sort-packages": true
85+
},
86+
"scripts": {
87+
"fix-cs": "vendor/bin/phpcbf --standard=PSR2 src/ tests/"
8988
}
9089
}

src/util/Loop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function execute(callable $code)
9191
$deadline = microtime(true) + $this->timeout;
9292

9393
$result = null;
94-
for ($i = 0; $this->looping && microtime(true) < $deadline; ++$i) {
94+
for ($i = 0; $this->looping && microtime(true) < $deadline; ++$i) { // @phpstan-ignore-line
9595
$result = $code();
9696
if (!$this->looping) { // @phpstan-ignore-line
9797
/*

0 commit comments

Comments
 (0)