Skip to content

Commit 92351d9

Browse files
authored
Merge pull request #6 from marc-mabe/fix-gh-ci
Test on PHP 7.1 to 8.5 and fix CI
2 parents f5dd360 + f02c750 commit 92351d9

8 files changed

Lines changed: 71 additions & 49 deletions

File tree

.github/workflows/test.Dockerfile

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,3 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local
88
ENV COMPOSER_ALLOW_SUPERUSER=1
99
ENV COMPOSER_HTACCESS_PROTECT=0
1010
ENV COMPOSER_CACHE_DIR=/.composer-cache-dir
11-
12-
# install PHP extension pcov
13-
ARG CODE_COVERAGE
14-
RUN if [[ "${CODE_COVERAGE}" == "true" ]] ; then \
15-
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
16-
&& mkdir -p /usr/src/php/ext/pcov && curl -fsSL https://pecl.php.net/get/pcov | tar xvz -C /usr/src/php/ext/pcov --strip 1 \
17-
&& docker-php-ext-install pcov \
18-
&& docker-php-ext-enable pcov \
19-
&& rm -Rf /usr/src/php/ext/pcov \
20-
&& apk del --no-cache .build-deps \
21-
; fi

.github/workflows/test.yml

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,56 @@ jobs:
1414
matrix:
1515
include:
1616
- PHP_VERSION: '7.1'
17-
CODE_COVERAGE: 'false'
1817
RUN_PHPSTAN: 'false'
1918
RUN_PSALM: 'false'
2019
- PHP_VERSION: '7.2'
21-
CODE_COVERAGE: 'true'
22-
RUN_PHPSTAN: 'false'
20+
RUN_PHPSTAN: 'true'
2321
RUN_PSALM: 'false'
2422
- PHP_VERSION: '7.3'
25-
CODE_COVERAGE: 'true'
2623
RUN_PHPSTAN: 'false'
2724
RUN_PSALM: 'false'
2825
- PHP_VERSION: '7.4'
29-
CODE_COVERAGE: 'true'
30-
RUN_PHPSTAN: 'true'
31-
RUN_PSALM: 'true'
26+
RUN_PHPSTAN: 'false'
27+
RUN_PSALM: 'false'
3228
- PHP_VERSION: '8.0'
33-
CODE_COVERAGE: 'true'
3429
RUN_PHPSTAN: 'true'
3530
RUN_PSALM: 'true'
3631
- PHP_VERSION: '8.1'
37-
CODE_COVERAGE: 'true'
3832
RUN_PHPSTAN: 'false'
3933
RUN_PSALM: 'false'
34+
- PHP_VERSION: '8.2'
35+
RUN_PHPSTAN: 'false'
36+
RUN_PSALM: 'false'
37+
- PHP_VERSION: '8.3'
38+
RUN_PHPSTAN: 'false'
39+
RUN_PSALM: 'false'
40+
- PHP_VERSION: '8.4'
41+
RUN_PHPSTAN: 'false'
42+
RUN_PSALM: 'false'
43+
- PHP_VERSION: '8.5'
44+
RUN_PHPSTAN: 'true'
45+
RUN_PSALM: 'false'
4046

4147
steps:
42-
- uses: actions/checkout@v2
48+
- uses: actions/checkout@v6
4349

4450
- name: Cache Docker Image
4551
id: docker-cache-image
46-
uses: actions/cache@v2
52+
uses: actions/cache@v5
4753
with:
4854
path: /tmp/docker-cache-image.tar
49-
key: docker-cache-image:${{ matrix.PHP_VERSION }}:${{ matrix.CODE_COVERAGE }}
55+
key: docker-cache-image:${{ matrix.PHP_VERSION }}
5056

5157
- name: Load Docker Image
5258
if: steps.docker-cache-image.outputs.cache-hit == 'true'
5359
run: docker load --input /tmp/docker-cache-image.tar
5460

5561
- name: Build Docker Image
5662
if: steps.docker-cache-image.outputs.cache-hit != 'true'
57-
run: docker build -f .github/workflows/test.Dockerfile -t 'test:${{ matrix.PHP_VERSION }}' --build-arg 'PHP_VERSION=${{ matrix.PHP_VERSION }}' --build-arg 'CODE_COVERAGE=${{ matrix.CODE_COVERAGE }}' .
63+
run: docker build -f .github/workflows/test.Dockerfile -t 'test:${{ matrix.PHP_VERSION }}' --build-arg 'PHP_VERSION=${{ matrix.PHP_VERSION }}' .
5864

5965
- name: Cache Composer Cache Dir
60-
uses: actions/cache@v2
66+
uses: actions/cache@v5
6167
with:
6268
path: /tmp/composer-cache-dir
6369
key: composer-cache-dir:${{ matrix.PHP_VERSION }}
@@ -76,17 +82,7 @@ jobs:
7682
7783
- name: Run Unit Test
7884
run: |
79-
if [ "${{ matrix.CODE_COVERAGE }}" == "true" ]; then
80-
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' -d 'pcov.enabled=1' ./vendor/bin/phpunit --coverage-clover=.clover.xml
81-
else
82-
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' ./vendor/bin/phpunit
83-
fi
84-
85-
- name: Upload Codecov Report
86-
uses: codecov/codecov-action@v1
87-
if: ${{ matrix.CODE_COVERAGE == 'true' }}
88-
with:
89-
file: .clover.xml
85+
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' ./vendor/bin/phpunit
9086
9187
- name: Run PHPStan
9288
if: ${{ matrix.RUN_PHPSTAN == 'true' }}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"composer-runtime-api": "^2.0"
2222
},
2323
"require-dev": {
24-
"phpstan/phpstan": "^1.3.0",
25-
"phpunit/phpunit": "^7.5.20 | ^8.5.52 | ^9.6.33",
24+
"phpstan/phpstan": "^1.4.0",
25+
"phpunit/phpunit": "^7.5.20 | ^8.5.52 | ^9.6.34",
2626
"vimeo/psalm": "^4.17.0"
2727
},
2828
"autoload": {

examples/doctrine/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"license": "BSD-3-Clause",
1717
"require": {
1818
"php": "^7.1 | ^8.0",
19+
"ext-pdo_sqlite": "*",
1920
"marc-mabe/enum-cl": "@dev",
2021
"doctrine/orm": "2.9.6"
2122
},

src/functions.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ function get_debug_type($value): string
5151
return 'class@anonymous';
5252
default:
5353
/** @var resource $value */
54-
/** @var string|null $type */
5554
$type = @get_resource_type($value);
56-
if (null === $type) {
57-
return 'unknown';
58-
}
5955

6056
if ('Unknown' === $type) {
6157
$type = 'closed';
@@ -79,7 +75,6 @@ function get_debug_type($value): string
7975
function enum_exists(string $enum, bool $autoload = true) : bool
8076
{
8177
if (\PHP_VERSION_ID >= 80100) {
82-
/** @phpstan-ignore-next-line */
8378
return \enum_exists($enum, $autoload);
8479
}
8580

src/psr-4/EmulatedBackedEnumTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ trait EmulatedBackedEnumTrait
5757
/** @param string|int $value */
5858
final private function __construct(string $name, $value)
5959
{
60+
/** @phpstan-ignore-next-line */
6061
$this->name = $name;
6162

6263
/** @phpstan-ignore-next-line */

tests/BasicIntEnumTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ public function testFromSuccess(): void
3838

3939
public function testFromInvalidValue(): void
4040
{
41+
if (PHP_VERSION_ID < 80200) {
42+
$enumClass = '"' . BasicIntEnum::class . '"';
43+
} else {
44+
$enumClass = BasicIntEnum::class;
45+
}
46+
47+
$this->expectExceptionMessage("10 is not a valid backing value for enum {$enumClass}");
4148
$this->expectException('ValueError');
42-
$this->expectExceptionMessage('10 is not a valid backing value for enum "BasicIntEnum"');
4349
BasicIntEnum::from(10);
4450
}
4551

@@ -74,13 +80,20 @@ public function testFromUnexpectedBoolTypeError(): void
7480
if (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100) {
7581
$class = EmulatedIntEnum::class;
7682
$type = 'string|int';
83+
$given = 'bool';
7784
} else {
7885
$class = BasicIntEnum::class;
7986
$type = 'int';
87+
88+
if (PHP_VERSION_ID >= 80300) {
89+
$given = 'true';
90+
} else {
91+
$given = 'bool';
92+
}
8093
}
8194

8295
$this->expectException('TypeError');
83-
$this->expectExceptionMessage("{$class}::from(): Argument #1 (\$value) must be of type {$type}, bool given");
96+
$this->expectExceptionMessage("{$class}::from(): Argument #1 (\$value) must be of type {$type}, {$given} given");
8497

8598
/** @phpstan-ignore-next-line */
8699
BasicIntEnum::from(true);
@@ -169,13 +182,20 @@ public function testTryFromUnexpectedBoolTypeError(): void
169182
if (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100) {
170183
$class = EmulatedIntEnum::class;
171184
$type = 'string|int';
185+
$given = 'bool';
172186
} else {
173187
$class = BasicIntEnum::class;
174188
$type = 'int';
189+
190+
if (PHP_VERSION_ID >= 80300) {
191+
$given = 'true';
192+
} else {
193+
$given = 'bool';
194+
}
175195
}
176196

177197
$this->expectException('TypeError');
178-
$this->expectExceptionMessage("{$class}::tryFrom(): Argument #1 (\$value) must be of type {$type}, bool given");
198+
$this->expectExceptionMessage("{$class}::tryFrom(): Argument #1 (\$value) must be of type {$type}, {$given} given");
179199

180200
/** @phpstan-ignore-next-line */
181201
BasicIntEnum::tryFrom(true);

tests/BasicStringEnumTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ public function testFromSuccess(): void
3838

3939
public function testFromInvalidValue(): void
4040
{
41+
if (PHP_VERSION_ID < 80200) {
42+
$enumClass = '"' . BasicStringEnum::class . '"';
43+
} else {
44+
$enumClass = BasicStringEnum::class;
45+
}
46+
47+
$this->expectExceptionMessage("\"10\" is not a valid backing value for enum {$enumClass}");
4148
$this->expectException('ValueError');
42-
$this->expectExceptionMessage('"10" is not a valid backing value for enum "BasicStringEnum"');
4349
BasicStringEnum::from('10');
4450
}
4551

@@ -74,13 +80,20 @@ public function testFromUnexpectedBoolTypeError(): void
7480
if (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100) {
7581
$class = EmulatedStringEnum::class;
7682
$type = 'string|int';
83+
$given = 'bool';
7784
} else {
7885
$class = BasicStringEnum::class;
7986
$type = 'string';
87+
88+
if (PHP_VERSION_ID >= 80300) {
89+
$given = 'true';
90+
} else {
91+
$given = 'bool';
92+
}
8093
}
8194

8295
$this->expectException('TypeError');
83-
$this->expectExceptionMessage("{$class}::from(): Argument #1 (\$value) must be of type {$type}, bool given");
96+
$this->expectExceptionMessage("{$class}::from(): Argument #1 (\$value) must be of type {$type}, {$given} given");
8497

8598
/** @phpstan-ignore-next-line */
8699
BasicStringEnum::from(true);
@@ -169,13 +182,20 @@ public function testTryFromUnexpectedBoolTypeError(): void
169182
if (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100) {
170183
$class = EmulatedStringEnum::class;
171184
$type = 'string|int';
185+
$given = 'bool';
172186
} else {
173187
$class = BasicStringEnum::class;
174188
$type = 'string';
189+
190+
if (PHP_VERSION_ID >= 80300) {
191+
$given = 'true';
192+
} else {
193+
$given = 'bool';
194+
}
175195
}
176196

177197
$this->expectException('TypeError');
178-
$this->expectExceptionMessage("{$class}::tryFrom(): Argument #1 (\$value) must be of type {$type}, bool given");
198+
$this->expectExceptionMessage("{$class}::tryFrom(): Argument #1 (\$value) must be of type {$type}, {$given} given");
179199

180200
/** @phpstan-ignore-next-line */
181201
BasicStringEnum::tryFrom(true);

0 commit comments

Comments
 (0)