Skip to content

Commit f3c2e8d

Browse files
committed
Run CI with all backends
1 parent 515250e commit f3c2e8d

File tree

5 files changed

+83
-15
lines changed

5 files changed

+83
-15
lines changed

.github/workflows/test-unit.yml

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
php: ['7.4', '8.0', '8.1', '8.2', '8.3', 'latest']
18+
php: ['latest']
1919
type: ['Phpunit']
2020
include:
2121
- php: 'latest'
@@ -55,3 +55,80 @@ jobs:
5555
run: |
5656
echo "memory_limit = 2G" > /usr/local/etc/php/conf.d/custom-memory-limit.ini
5757
vendor/bin/phpstan analyse -v
58+
59+
unit-test:
60+
name: Unit
61+
runs-on: ubuntu-latest
62+
container:
63+
image: ghcr.io/mvorisek/image-php:${{ matrix.php }}
64+
strategy:
65+
fail-fast: false
66+
matrix:
67+
php: ['7.4', '8.0', '8.1', '8.2', '8.3']
68+
type: ['Phpunit', 'Phpunit Lowest']
69+
env:
70+
LOG_COVERAGE: "${{ fromJSON('{true: \"1\", false: \"\"}')[matrix.php == '8.3' && matrix.type == 'Phpunit' && (github.event_name == 'pull_request' || (github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')))] }}"
71+
services:
72+
mysql:
73+
image: mysql
74+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 -e MYSQL_ROOT_PASSWORD=test_pass_root -e MYSQL_USER=test_user -e MYSQL_PASSWORD=test_pass -e MYSQL_DATABASE=test_db
75+
postgres:
76+
image: postgres:12-alpine
77+
env:
78+
POSTGRES_USER: test_user
79+
POSTGRES_PASSWORD: test_pass
80+
POSTGRES_DB: test_db
81+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
82+
redis1:
83+
image: redis:alpine
84+
redis2:
85+
image: redis:alpine
86+
redis3:
87+
image: redis:alpine
88+
memcached:
89+
image: memcached:alpine
90+
steps:
91+
- name: Checkout
92+
uses: actions/checkout@v4
93+
94+
- name: Configure PHP
95+
run: |
96+
install-php-extensions lzf memcached sysvsem
97+
if [ -n "$LOG_COVERAGE" ]; then echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; else rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; fi
98+
php --version
99+
100+
- name: Install PHP dependencies
101+
run: |
102+
if [ "${{ matrix.type }}" != "Phpunit" ] && [ "${{ matrix.type }}" != "Phpunit Lowest" ]; then composer remove --no-interaction --no-update phpunit/phpunit ergebnis/phpunit-slow-test-detector --dev; fi
103+
if [ "${{ matrix.type }}" != "CodingStyle" ]; then composer remove --no-interaction --no-update friendsofphp/php-cs-fixer ergebnis/composer-normalize --dev; fi
104+
if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/\* --dev; fi
105+
if [ -n "$LOG_COVERAGE" ]; then composer require --no-interaction --no-install phpunit/phpcov; fi
106+
composer update --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader
107+
if [ "${{ matrix.type }}" = "Phpunit Lowest" ]; then composer update --ansi --prefer-dist --prefer-lowest --prefer-stable --no-interaction --no-progress --optimize-autoloader; fi
108+
109+
- name: Init
110+
run: |
111+
php -r '(new PDO("mysql:host=mysql", "root", "test_pass_root"))->exec("ALTER USER '"'"'test_user'"'"'@'"'"'%'"'"' WITH MAX_USER_CONNECTIONS 15");'
112+
php -r '(new PDO("pgsql:host=postgres;dbname=test_db", "test_user", "test_pass"))->exec("ALTER ROLE test_user CONNECTION LIMIT 1");'
113+
if [ -n "$LOG_COVERAGE" ]; then mkdir coverage; fi
114+
115+
- name: "Run tests"
116+
env:
117+
MYSQL_DSN: "mysql:host=mysql;dbname=test_db"
118+
MYSQL_USER: test_user
119+
MYSQL_PASSWORD: test_pass
120+
PGSQL_DSN: "pgsql:host=postgres;dbname=test_db"
121+
PGSQL_USER: test_user
122+
PGSQL_PASSWORD: test_pass
123+
REDIS_URIS: "redis://redis1,redis://redis2,redis://redis3"
124+
MEMCACHE_HOST: memcached
125+
run: |
126+
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) --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)
127+
128+
- name: Upload coverage (only for coverage)
129+
if: env.LOG_COVERAGE && false # TODO
130+
uses: codecov/codecov-action@v5
131+
with:
132+
token: ${{ secrets.CODECOV_TOKEN }}
133+
fail_ci_if_error: true
134+
files: coverage/phpunit.cov

phpstan.neon.dist

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ parameters:
1111

1212
ignoreErrors:
1313
# TODO
14-
-
15-
path: '*'
16-
identifier: equal.notAllowed
17-
message: '~^Loose comparison via "==" is not allowed\.$~'
18-
count: 4
1914
-
2015
path: 'src/mutex/RedisMutex.php'
2116
identifier: if.condNotBoolean

src/mutex/MySQLMutex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function lock(): void
4848
$statement->setFetchMode(\PDO::FETCH_NUM);
4949
$row = $statement->fetch();
5050

51-
if ($row[0] == 1) {
51+
if ((string) $row[0] === '1') {
5252
// Returns 1 if the lock was obtained successfully.
5353
return;
5454
}

tests/mutex/MutexConcurrencyTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ private function fork(int $concurrency, callable $code): void
8888
* @param callable $mutexFactory the mutex factory
8989
*
9090
* @dataProvider provideHighContentionCases
91-
*
92-
* @slowThreshold 1000
9391
*/
9492
public function testHighContention(callable $code, callable $mutexFactory): void
9593
{
@@ -153,9 +151,9 @@ static function (int $increment) use ($filename): int {
153151
self::$pdo = null;
154152

155153
$cases[$vendor] = [
156-
static function ($increment) use ($dsn, $user, $password) {
154+
static function (int $increment) use ($dsn, $user, $password) {
157155
// This prevents using a closed connection from a child.
158-
if ($increment == 0) {
156+
if ($increment === 0) {
159157
self::$pdo = null;
160158
}
161159
$pdo = self::getPDO($dsn, $user, $password);
@@ -203,8 +201,6 @@ static function ($timeout = 3) use ($dsn, $user, $password) {
203201
* @param callable $mutexFactory the Mutex factory
204202
*
205203
* @dataProvider provideExecutionIsSerializedWhenLockedCases
206-
*
207-
* @slowThreshold 2000
208204
*/
209205
public function testExecutionIsSerializedWhenLocked(callable $mutexFactory): void
210206
{

tests/util/DoubleCheckedLockingTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testLockedCheckAndExecution(): void
5858
});
5959

6060
$checkedLocking = new DoubleCheckedLocking($this->mutex, static function () use (&$lock, &$check): bool {
61-
if ($check == 1) {
61+
if ($check === 1) {
6262
self::assertSame(1, $lock);
6363
}
6464
++$check;
@@ -117,7 +117,7 @@ public static function provideCodeNotExecutedCases(): iterable
117117
}],
118118

119119
[static function () use (&$checkCounter): bool {
120-
$result = $checkCounter == 0;
120+
$result = $checkCounter === 0;
121121
++$checkCounter;
122122

123123
return $result;

0 commit comments

Comments
 (0)