Skip to content

Commit e9dd470

Browse files
authored
Merge pull request #149 from marc-mabe/ghaction
Migrate from travis to GH workflow
2 parents 6b5f56d + bdffbba commit e9dd470

File tree

6 files changed

+137
-90
lines changed

6 files changed

+137
-90
lines changed

.github/workflows/test.Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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
11+
12+
# install PHP extension pcov
13+
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
14+
&& 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 \
15+
&& docker-php-ext-install pcov \
16+
&& docker-php-ext-enable pcov \
17+
&& rm -Rf /usr/src/php/ext/pcov \
18+
&& apk del --no-cache .build-deps

.github/workflows/test.yml

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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: 7.1
17+
CODE_COVERAGE: false
18+
RUN_PHPSTAN: false
19+
RUN_PSALM: false
20+
RUN_BENCHMARK: false
21+
- PHP_VERSION: 7.2
22+
CODE_COVERAGE: true
23+
RUN_PHPSTAN: false
24+
RUN_PSALM: false
25+
RUN_BENCHMARK: false
26+
- PHP_VERSION: 7.3
27+
CODE_COVERAGE: true
28+
RUN_PHPSTAN: false
29+
RUN_PSALM: false
30+
RUN_BENCHMARK: false
31+
- PHP_VERSION: 7.4
32+
CODE_COVERAGE: true
33+
RUN_PHPSTAN: true
34+
RUN_PSALM: true
35+
RUN_BENCHMARK: true
36+
- PHP_VERSION: 8.0-rc
37+
CODE_COVERAGE: true
38+
RUN_PHPSTAN: true
39+
RUN_PSALM: true
40+
RUN_BENCHMARK: true
41+
COMPOSER_EXTRA_ARGS: --ignore-platform-reqs
42+
43+
steps:
44+
- uses: actions/checkout@v2
45+
46+
- name: Cache Docker Image
47+
id: cache-docker-image
48+
uses: actions/cache@v2
49+
with:
50+
path: /tmp/docker-image.tar
51+
key: cache-docker-image-test:${{ matrix.PHP_VERSION }}
52+
53+
- name: Load Docker Image
54+
if: steps.cache-docker-image.outputs.cache-hit == 'true'
55+
run: docker load --input /tmp/docker-image.tar
56+
57+
- name: Build Docker Image
58+
if: steps.cache-docker-image.outputs.cache-hit != 'true'
59+
run: docker build -f .github/workflows/test.Dockerfile -t 'test:${{ matrix.PHP_VERSION }}' --build-arg 'PHP_VERSION=${{ matrix.PHP_VERSION }}' .
60+
61+
- name: Cache Composer Cache Files
62+
uses: actions/cache@v2
63+
with:
64+
path: /tmp/composer-cache-files
65+
key: cache-composer-cache-files-${{ matrix.PHP_VERSION }}
66+
restore-keys: |
67+
cache-composer-cache-files-
68+
69+
- name: Install Composer Dependencies
70+
run: |
71+
if [ "${{ matrix.RUN_PHPSTAN }}" != "true" ]; then composer remove --dev phpstan/phpstan --no-update --no-interaction; fi
72+
if [ "${{ matrix.RUN_PSALM }}" != "true" ]; then composer remove --dev vimeo/psalm --no-update --no-interaction; fi
73+
if [ "${{ matrix.RUN_BENCHMARK }}" != "true" ]; then composer remove --dev phpbench/phpbench --no-update --no-interaction; fi
74+
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 }}
75+
76+
- name: Run Unit Test
77+
run: |
78+
if [ "${{ matrix.CODE_COVERAGE }}" == "true" ]; then
79+
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
80+
else
81+
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' ./vendor/bin/phpunit
82+
fi
83+
84+
- name: Upload Codecov Report
85+
uses: codecov/codecov-action@v1
86+
if: ${{ matrix.CODE_COVERAGE }}
87+
with:
88+
token: ${{ secrets.CODECOV_TOKEN }}
89+
file: .clover.xml
90+
91+
- name: Run PHPStan
92+
if: ${{ matrix.RUN_PHPSTAN }}
93+
run: docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'memory_limit=2G' ./vendor/bin/phpstan analyse --level max src/ tests/
94+
95+
- name: Run psalm
96+
if: ${{ matrix.RUN_PSALM }}
97+
run: mkdir -p "$HOME/.cache/psalm" && docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" -v "$HOME/.cache/psalm:/.cache/psalm" 'test:${{ matrix.PHP_VERSION }}' php ./vendor/bin/psalm
98+
99+
- name: Run benchmark
100+
if: ${{ matrix.RUN_BENCHMARK }}
101+
run: docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=-1' ./vendor/bin/phpbench run --no-interaction --revs=1 --retry-threshold=100 --progress=travis
102+
103+
- name: Export Docker Image
104+
if: steps.cache-docker-image.outputs.cache-hit != 'true'
105+
run: docker save --output /tmp/docker-image.tar 'test:${{ matrix.PHP_VERSION }}'

.travis.yml

-83
This file was deleted.

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
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?b=master)](https://scrutinizer-ci.com/g/marc-mabe/php-enum/)
4-
[![Code Coverage](https://scrutinizer-ci.com/g/marc-mabe/php-enum/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/marc-mabe/php-enum/)
5-
[![Total Downloads](https://poser.pugx.org/marc-mabe/php-enum/downloads.png)](https://packagist.org/packages/marc-mabe/php-enum)
2+
[![Build Status](https://github.com/marc-mabe/php-enum/workflows/Test/badge.svg?branch=master)](https://github.com/marc-mabe/php-enum/actions?query=workflow%3ATest%20branch%3Amaster)
3+
[![Code Coverage](https://codecov.io/github/marc-mabe/php-enum/coverage.svg?branch=master)](https://codecov.io/gh/marc-mabe/php-enum/branch/master/)
4+
[![License](https://poser.pugx.org/marc-mabe/php-enum/license)](https://github.com/marc-mabe/php-enum/blob/master/LICENSE.txt)
65
[![Latest Stable](https://poser.pugx.org/marc-mabe/php-enum/v/stable.png)](https://packagist.org/packages/marc-mabe/php-enum)
6+
[![Total Downloads](https://poser.pugx.org/marc-mabe/php-enum/downloads.png)](https://packagist.org/packages/marc-mabe/php-enum)
7+
[![Monthly Downloads](https://poser.pugx.org/marc-mabe/php-enum/d/monthly)](https://packagist.org/packages/marc-mabe/php-enum)
8+
[![Dependents](https://poser.pugx.org/marc-mabe/php-enum/dependents)](https://packagist.org/packages/marc-mabe/php-enum/dependents?order_by=downloads)
79

810
This is a native PHP implementation to add enumeration support to PHP.
911
It's an abstract class that needs to be extended to use it.

src/Enum.php

+2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ final public static function getConstants()
392392
$constants = $scopeConstants + $constants;
393393
} while (($reflection = $reflection->getParentClass()) && $reflection->name !== __CLASS__);
394394

395+
/** @var array<string, null|bool|int|float|string|array<mixed>> $constants */
396+
395397
assert(
396398
self::noAmbiguousValues($constants),
397399
'Ambiguous enumerator values detected for ' . static::class

tests/MabeEnumTest/EnumMapTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,13 @@ public function testSerializable(): void
477477

478478
public function testIsEmpty(): void
479479
{
480-
/** @var array<int, string> $items2 */
481-
$items2 = array_combine(Enum32::getValues(), Enum32::getNames());
480+
$makeItems2 = function () {
481+
foreach (Enum32::getEnumerators() as $enumerator) {
482+
yield $enumerator => $enumerator->getName();
483+
}
484+
};
482485
$map1 = new EnumMap(Enum32::class, []);
483-
$map2 = new EnumMap(Enum32::class, $items2);
486+
$map2 = new EnumMap(Enum32::class, $makeItems2());
484487

485488
$this->assertTrue($map1->isEmpty());
486489
$this->assertFalse($map2->isEmpty());

0 commit comments

Comments
 (0)