Skip to content

Commit 021dae8

Browse files
authored
Merge pull request #154 from marc-mabe/3.x-php8.1
Support PHP-8.1
2 parents 7bccc3e + f7d8f78 commit 021dae8

File tree

9 files changed

+80
-110
lines changed

9 files changed

+80
-110
lines changed

.github/workflows/test.Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ARG PHP_VERSION=latest
2+
FROM php:${PHP_VERSION}-cli-alpine
3+
4+
WORKDIR /workdir
5+
6+
# install composer
7+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
8+
ENV COMPOSER_ALLOW_SUPERUSER=1
9+
ENV COMPOSER_HTACCESS_PROTECT=0
10+
ENV COMPOSER_CACHE_DIR=/.composer

.github/workflows/test.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
- '[0-9]+.x'
9+
10+
jobs:
11+
php:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
include:
16+
- PHP_VERSION: 5.6
17+
- PHP_VERSION: 7.0
18+
- PHP_VERSION: 7.1
19+
- PHP_VERSION: 7.2
20+
- PHP_VERSION: 7.3
21+
- PHP_VERSION: 7.4
22+
- PHP_VERSION: 8.0
23+
- PHP_VERSION: 8.1
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
28+
- name: Build Docker Image
29+
if: steps.cache-docker-image.outputs.cache-hit != 'true'
30+
run: docker build -f .github/workflows/test.Dockerfile -t 'test:${{ matrix.PHP_VERSION }}' --build-arg 'PHP_VERSION=${{ matrix.PHP_VERSION }}' .
31+
32+
- name: Cache Composer Cache Files
33+
uses: actions/cache@v2
34+
with:
35+
path: /tmp/composer-cache-files
36+
key: cache-composer-cache-files-${{ matrix.PHP_VERSION }}
37+
restore-keys: |
38+
cache-composer-cache-files-
39+
40+
- name: Install Composer Dependencies
41+
run: |
42+
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" -v '/tmp/composer-cache-files:/.composer' 'test:${{ matrix.PHP_VERSION }}' composer install --no-interaction --no-progress --prefer-dist ${{ matrix.COMPOSER_EXTRA_ARGS }}
43+
44+
- name: Run Unit Test
45+
run: |
46+
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' ./vendor/bin/phpunit

.travis.yml

-81
This file was deleted.

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# php-enum
2-
[![Build Status](https://secure.travis-ci.org/marc-mabe/php-enum.png?branch=master)](http://travis-ci.org/marc-mabe/php-enum)
3-
[![Quality Score](https://scrutinizer-ci.com/g/marc-mabe/php-enum/badges/quality-score.png?s=7dfddb19a12314ecc5f05eeb2b297bdde3ad2623)](https://scrutinizer-ci.com/g/marc-mabe/php-enum/)
4-
[![Code Coverage](https://scrutinizer-ci.com/g/marc-mabe/php-enum/badges/coverage.png?s=8442d532fad964fd3d8afe493ac2d0d65162306a)](https://scrutinizer-ci.com/g/marc-mabe/php-enum/)
2+
[![Build Status](https://github.com/marc-mabe/php-enum/workflows/Test/badge.svg?branch=3.x)](https://github.com/marc-mabe/php-enum/actions?query=workflow%3ATest%20branch%3A3.x)
53
[![Total Downloads](https://poser.pugx.org/marc-mabe/php-enum/downloads.png)](https://packagist.org/packages/marc-mabe/php-enum)
64
[![Latest Stable](https://poser.pugx.org/marc-mabe/php-enum/v/stable.png)](https://packagist.org/packages/marc-mabe/php-enum)
75

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"ext-reflection": "*"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "^5.7 || ^6.0",
24+
"phpunit/phpunit": "^5.7 || ^6.0 || ^9.0",
2525
"phpbench/phpbench": "@dev",
2626

2727
"lstrojny/functional-php": "HHVM: variadic params with type constraints are not supported in non-Hack",

src/Enum.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function __toString()
7777
* @throws LogicException Enums are not cloneable
7878
* because instances are implemented as singletons
7979
*/
80-
final private function __clone()
80+
final public function __clone()
8181
{
8282
throw new LogicException('Enums are not cloneable');
8383
}
@@ -299,7 +299,7 @@ final public static function getNames()
299299
}
300300
return self::$names[static::class];
301301
}
302-
302+
303303
/**
304304
* Get a list of enumerator ordinal numbers
305305
*
@@ -324,7 +324,7 @@ final public static function getConstants()
324324

325325
/**
326326
* Test if the given enumerator is part of this enumeration
327-
*
327+
*
328328
* @param static|null|bool|int|float|string|array $enumerator
329329
* @return bool
330330
*/

tests/MabeEnumTest/EnumSerializableTraitTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class EnumSerializableTraitTest extends TestCase
2121
public function testSerializeSerializableEnum()
2222
{
2323
$serialized = serialize(SerializableEnum::get(SerializableEnum::NIL));
24-
$this->assertInternalType('string', $serialized);
24+
$this->assertSame('string', gettype($serialized));
2525

2626
$unserialized = unserialize($serialized);
2727
$this->assertInstanceOf(SerializableEnum::class, $unserialized);
@@ -30,7 +30,7 @@ public function testSerializeSerializableEnum()
3030
public function testUnserializeFirstWillHoldTheSameInstance()
3131
{
3232
$serialized = serialize(SerializableEnum::get(SerializableEnum::STR));
33-
$this->assertInternalType('string', $serialized);
33+
$this->assertSame('string', gettype($serialized));
3434

3535
// clear all instantiated instances so we can virtual test unserializing first
3636
$this->clearEnumeration(SerializableEnum::class);

tests/MabeEnumTest/EnumTest.php

+17-19
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@
2626
*/
2727
class EnumTest extends TestCase
2828
{
29-
public function setUp()
30-
{
31-
$this->resetStaticEnumProps();
32-
}
33-
34-
public function tearDown()
35-
{
36-
assert_options(ASSERT_ACTIVE, 1);
37-
}
38-
3929
/**
4030
* Un-initialize all known enumerations
4131
*/
@@ -233,7 +223,7 @@ public function testGetNamesConstantsNotDetected()
233223
$this->assertSame($expectedNames[$i], $names[$i]);
234224
}
235225
}
236-
226+
237227
public function testGetOrdinals()
238228
{
239229
$constants = EnumInheritance::getConstants();
@@ -325,10 +315,15 @@ public function testEnabledAssertAmbiguousEnumeratorValues()
325315

326316
public function testDisabledAssertAmbiguousEnumeratorValues()
327317
{
328-
assert_options(ASSERT_ACTIVE, 0);
329318
$this->expectException(InvalidArgumentException::class);
330319

331-
EnumAmbiguous::get('unknown');
320+
try {
321+
assert_options(ASSERT_ACTIVE, 0);
322+
EnumAmbiguous::get('unknown');
323+
} catch (\Exception $e) {
324+
assert_options(ASSERT_ACTIVE, 1);
325+
throw $e;
326+
}
332327
}
333328

334329
public function testExtendedEnabledAssertAmbiguousEnumeratorValues()
@@ -345,10 +340,15 @@ public function testExtendedEnabledAssertAmbiguousEnumeratorValues()
345340

346341
public function testExtendedDisabledAssertAmbiguousEnumeratorValues()
347342
{
348-
assert_options(ASSERT_ACTIVE, 0);
349343
$this->expectException(InvalidArgumentException::class);
350344

351-
EnumExtendedAmbiguous::get('unknown');
345+
try {
346+
assert_options(ASSERT_ACTIVE, 0);
347+
EnumExtendedAmbiguous::get('unknown');
348+
} catch (\Exception $e) {
349+
assert_options(ASSERT_ACTIVE, 1);
350+
throw $e;
351+
}
352352
}
353353

354354
public function testSingleton()
@@ -364,12 +364,10 @@ public function testCloneNotCallableAndThrowsLogicException()
364364

365365
$reflectionClass = new ReflectionClass($enum);
366366
$reflectionMethod = $reflectionClass->getMethod('__clone');
367-
$this->assertTrue($reflectionMethod->isPrivate(), 'The method __clone must be private');
368367
$this->assertTrue($reflectionMethod->isFinal(), 'The method __clone must be final');
369368

370-
$reflectionMethod->setAccessible(true);
371369
$this->expectException(LogicException::class);
372-
$reflectionMethod->invoke($enum);
370+
clone $enum;
373371
}
374372

375373
public function testNotSerializable()
@@ -430,7 +428,7 @@ public function testConstVisibility()
430428
'PUB' => ConstVisibilityEnum::PUB,
431429
), $constants);
432430
}
433-
431+
434432
public function testConstVisibilityExtended()
435433
{
436434
if (PHP_VERSION_ID < 70100) {

tests/bootstrap.php

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
assert_options(ASSERT_ACTIVE, 1);
1616
assert_options(ASSERT_WARNING, 0);
1717
assert_options(ASSERT_BAIL, 0);
18-
assert_options(ASSERT_QUIET_EVAL, 0);
1918
if (!class_exists('AssertionError')) {
2019
// AssertionError has been added in PHP-7.0
2120
class AssertionError extends Exception {};

0 commit comments

Comments
 (0)