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
11 changes: 0 additions & 11 deletions .github/workflows/test.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,3 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV COMPOSER_HTACCESS_PROTECT=0
ENV COMPOSER_CACHE_DIR=/.composer-cache-dir

# install PHP extension pcov
ARG CODE_COVERAGE
RUN if [[ "${CODE_COVERAGE}" == "true" ]] ; then \
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
&& 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 \
&& docker-php-ext-install pcov \
&& docker-php-ext-enable pcov \
&& rm -Rf /usr/src/php/ext/pcov \
&& apk del --no-cache .build-deps \
; fi
46 changes: 21 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,56 @@ jobs:
matrix:
include:
- PHP_VERSION: '7.1'
CODE_COVERAGE: 'false'
RUN_PHPSTAN: 'false'
RUN_PSALM: 'false'
- PHP_VERSION: '7.2'
CODE_COVERAGE: 'true'
RUN_PHPSTAN: 'false'
RUN_PHPSTAN: 'true'
RUN_PSALM: 'false'
- PHP_VERSION: '7.3'
CODE_COVERAGE: 'true'
RUN_PHPSTAN: 'false'
RUN_PSALM: 'false'
- PHP_VERSION: '7.4'
CODE_COVERAGE: 'true'
RUN_PHPSTAN: 'true'
RUN_PSALM: 'true'
RUN_PHPSTAN: 'false'
RUN_PSALM: 'false'
- PHP_VERSION: '8.0'
CODE_COVERAGE: 'true'
RUN_PHPSTAN: 'true'
RUN_PSALM: 'true'
- PHP_VERSION: '8.1'
CODE_COVERAGE: 'true'
RUN_PHPSTAN: 'false'
RUN_PSALM: 'false'
- PHP_VERSION: '8.2'
RUN_PHPSTAN: 'false'
RUN_PSALM: 'false'
- PHP_VERSION: '8.3'
RUN_PHPSTAN: 'false'
RUN_PSALM: 'false'
- PHP_VERSION: '8.4'
RUN_PHPSTAN: 'false'
RUN_PSALM: 'false'
- PHP_VERSION: '8.5'
RUN_PHPSTAN: 'true'
RUN_PSALM: 'false'

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6

- name: Cache Docker Image
id: docker-cache-image
uses: actions/cache@v2
uses: actions/cache@v5
with:
path: /tmp/docker-cache-image.tar
key: docker-cache-image:${{ matrix.PHP_VERSION }}:${{ matrix.CODE_COVERAGE }}
key: docker-cache-image:${{ matrix.PHP_VERSION }}

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

- name: Build Docker Image
if: steps.docker-cache-image.outputs.cache-hit != 'true'
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 }}' .
run: docker build -f .github/workflows/test.Dockerfile -t 'test:${{ matrix.PHP_VERSION }}' --build-arg 'PHP_VERSION=${{ matrix.PHP_VERSION }}' .

- name: Cache Composer Cache Dir
uses: actions/cache@v2
uses: actions/cache@v5
with:
path: /tmp/composer-cache-dir
key: composer-cache-dir:${{ matrix.PHP_VERSION }}
Expand All @@ -76,17 +82,7 @@ jobs:

- name: Run Unit Test
run: |
if [ "${{ matrix.CODE_COVERAGE }}" == "true" ]; then
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
else
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' ./vendor/bin/phpunit
fi

- name: Upload Codecov Report
uses: codecov/codecov-action@v1
if: ${{ matrix.CODE_COVERAGE == 'true' }}
with:
file: .clover.xml
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' ./vendor/bin/phpunit

- name: Run PHPStan
if: ${{ matrix.RUN_PHPSTAN == 'true' }}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"composer-runtime-api": "^2.0"
},
"require-dev": {
"phpstan/phpstan": "^1.3.0",
"phpunit/phpunit": "^7.5.20 | ^8.5.52 | ^9.6.33",
"phpstan/phpstan": "^1.4.0",
"phpunit/phpunit": "^7.5.20 | ^8.5.52 | ^9.6.34",
"vimeo/psalm": "^4.17.0"
},
"autoload": {
Expand Down
1 change: 1 addition & 0 deletions examples/doctrine/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"license": "BSD-3-Clause",
"require": {
"php": "^7.1 | ^8.0",
"ext-pdo_sqlite": "*",
"marc-mabe/enum-cl": "@dev",
"doctrine/orm": "2.9.6"
},
Expand Down
5 changes: 0 additions & 5 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ function get_debug_type($value): string
return 'class@anonymous';
default:
/** @var resource $value */
/** @var string|null $type */
$type = @get_resource_type($value);
if (null === $type) {
return 'unknown';
}

if ('Unknown' === $type) {
$type = 'closed';
Expand All @@ -79,7 +75,6 @@ function get_debug_type($value): string
function enum_exists(string $enum, bool $autoload = true) : bool
{
if (\PHP_VERSION_ID >= 80100) {
/** @phpstan-ignore-next-line */
return \enum_exists($enum, $autoload);
}

Expand Down
1 change: 1 addition & 0 deletions src/psr-4/EmulatedBackedEnumTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ trait EmulatedBackedEnumTrait
/** @param string|int $value */
final private function __construct(string $name, $value)
{
/** @phpstan-ignore-next-line */
$this->name = $name;

/** @phpstan-ignore-next-line */
Expand Down
26 changes: 23 additions & 3 deletions tests/BasicIntEnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ public function testFromSuccess(): void

public function testFromInvalidValue(): void
{
if (PHP_VERSION_ID < 80200) {
$enumClass = '"' . BasicIntEnum::class . '"';
} else {
$enumClass = BasicIntEnum::class;
}

$this->expectExceptionMessage("10 is not a valid backing value for enum {$enumClass}");
$this->expectException('ValueError');
$this->expectExceptionMessage('10 is not a valid backing value for enum "BasicIntEnum"');
BasicIntEnum::from(10);
}

Expand Down Expand Up @@ -74,13 +80,20 @@ public function testFromUnexpectedBoolTypeError(): void
if (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100) {
$class = EmulatedIntEnum::class;
$type = 'string|int';
$given = 'bool';
} else {
$class = BasicIntEnum::class;
$type = 'int';

if (PHP_VERSION_ID >= 80300) {
$given = 'true';
} else {
$given = 'bool';
}
}

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

/** @phpstan-ignore-next-line */
BasicIntEnum::from(true);
Expand Down Expand Up @@ -169,13 +182,20 @@ public function testTryFromUnexpectedBoolTypeError(): void
if (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100) {
$class = EmulatedIntEnum::class;
$type = 'string|int';
$given = 'bool';
} else {
$class = BasicIntEnum::class;
$type = 'int';

if (PHP_VERSION_ID >= 80300) {
$given = 'true';
} else {
$given = 'bool';
}
}

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

/** @phpstan-ignore-next-line */
BasicIntEnum::tryFrom(true);
Expand Down
26 changes: 23 additions & 3 deletions tests/BasicStringEnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ public function testFromSuccess(): void

public function testFromInvalidValue(): void
{
if (PHP_VERSION_ID < 80200) {
$enumClass = '"' . BasicStringEnum::class . '"';
} else {
$enumClass = BasicStringEnum::class;
}

$this->expectExceptionMessage("\"10\" is not a valid backing value for enum {$enumClass}");
$this->expectException('ValueError');
$this->expectExceptionMessage('"10" is not a valid backing value for enum "BasicStringEnum"');
BasicStringEnum::from('10');
}

Expand Down Expand Up @@ -74,13 +80,20 @@ public function testFromUnexpectedBoolTypeError(): void
if (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100) {
$class = EmulatedStringEnum::class;
$type = 'string|int';
$given = 'bool';
} else {
$class = BasicStringEnum::class;
$type = 'string';

if (PHP_VERSION_ID >= 80300) {
$given = 'true';
} else {
$given = 'bool';
}
}

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

/** @phpstan-ignore-next-line */
BasicStringEnum::from(true);
Expand Down Expand Up @@ -169,13 +182,20 @@ public function testTryFromUnexpectedBoolTypeError(): void
if (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100) {
$class = EmulatedStringEnum::class;
$type = 'string|int';
$given = 'bool';
} else {
$class = BasicStringEnum::class;
$type = 'string';

if (PHP_VERSION_ID >= 80300) {
$given = 'true';
} else {
$given = 'bool';
}
}

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

/** @phpstan-ignore-next-line */
BasicStringEnum::tryFrom(true);
Expand Down