Skip to content

Commit 55f5814

Browse files
authored
Merge pull request #6 from marc-mabe/gh-workflow
Migrate from travis + scurinizer to Github workflow + codecov
2 parents 29bbc50 + 8c6cbfb commit 55f5814

7 files changed

+109
-76
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

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
php:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
include:
15+
- PHP_VERSION: 7.1
16+
CODE_COVERAGE: false
17+
COMPOSER_EXTRA_ARGS: --prefer-lowest
18+
- PHP_VERSION: 7.1
19+
CODE_COVERAGE: false
20+
- PHP_VERSION: 7.2
21+
CODE_COVERAGE: true
22+
- PHP_VERSION: 7.3
23+
CODE_COVERAGE: true
24+
- PHP_VERSION: 7.4
25+
CODE_COVERAGE: true
26+
27+
steps:
28+
- uses: actions/checkout@v2
29+
30+
- name: Cache Docker Image
31+
id: cache-docker-image
32+
uses: actions/cache@v2
33+
with:
34+
path: /tmp/docker-image.tar
35+
key: cache-docker-image-test:${{ matrix.PHP_VERSION }}
36+
37+
- name: Load Docker Image
38+
if: steps.cache-docker-image.outputs.cache-hit == 'true'
39+
run: docker load --input /tmp/docker-image.tar
40+
41+
- name: Build Docker Image
42+
if: steps.cache-docker-image.outputs.cache-hit != 'true'
43+
run: docker build -f .github/workflows/test.Dockerfile -t 'test:${{ matrix.PHP_VERSION }}' --build-arg 'PHP_VERSION=${{ matrix.PHP_VERSION }}' .
44+
45+
- name: Cache Composer Cache Files
46+
uses: actions/cache@v2
47+
with:
48+
path: /tmp/composer-cache-files
49+
key: cache-composer-cache-files-${{ matrix.PHP_VERSION }}
50+
restore-keys: |
51+
cache-composer-cache-files-
52+
53+
- name: Install Composer Dependencies
54+
run: |
55+
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" -v '/tmp/composer-cache-files:/.composer' 'test:${{ matrix.PHP_VERSION }}' composer update --no-interaction --no-progress --prefer-dist ${{ matrix.COMPOSER_EXTRA_ARGS }}
56+
57+
- name: Run Unit Test
58+
run: |
59+
if [ "${{ matrix.CODE_COVERAGE }}" == "true" ]; then
60+
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
61+
else
62+
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' ./vendor/bin/phpunit
63+
fi
64+
65+
- name: Upload Codecov Report
66+
uses: codecov/codecov-action@v1
67+
if: ${{ matrix.CODE_COVERAGE }}
68+
with:
69+
token: ${{ secrets.CODECOV_TOKEN }}
70+
file: .clover.xml
71+
72+
- name: Export Docker Image
73+
if: steps.cache-docker-image.outputs.cache-hit != 'true'
74+
run: docker save --output /tmp/docker-image.tar 'test:${{ matrix.PHP_VERSION }}'

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# hidden files
22
.*
33
!.gitignore
4-
!.travis.yml
4+
!.github
55

66
#composer
77
composer.lock
8-
composer.phar
98
vendor

.travis.yml

-58
This file was deleted.

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
"keywords": ["enum", "phpstan"],
66
"license": "BSD-3-Clause",
77
"require": {
8-
"php": "~7.1",
8+
"php": "^7.1",
99
"marc-mabe/php-enum": "^1.1 || ^2.0 || ^3.0 || ^4.0",
1010
"phpstan/phpstan": "^0.12"
1111
},
1212
"require-dev": {
13-
"phpunit/phpunit": "^7.5.20"
13+
"phpunit/phpunit": "^7.5 | ^8.5 | 9.4"
1414
},
1515
"autoload": {
1616
"psr-4": {

tests/unit/EnumMethodReflectionTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,45 +25,45 @@ class EnumMethodReflectionTest extends TestCase
2525
*/
2626
protected $reflectionExtension;
2727

28-
public function setUp()
28+
public function setUp(): void
2929
{
3030
$this->broker = $this->createBroker();
3131
$this->reflectionExtension = new EnumMethodsClassReflectionExtension();
3232
}
3333

34-
public function getDeclaringClass()
34+
public function testGetDeclaringClass(): void
3535
{
3636
$classReflection = $this->broker->getClass(VisibilityEnum::class);
3737
$methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR');
3838

3939
$this->assertSame($classReflection, $methodReflection->getDeclaringClass());
4040
}
4141

42-
public function testShouldBeStatic()
42+
public function testShouldBeStatic(): void
4343
{
4444
$classReflection = $this->broker->getClass(VisibilityEnum::class);
4545
$methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR');
4646

4747
$this->assertTrue($methodReflection->isStatic());
4848
}
4949

50-
public function testShouldNotBePrivate()
50+
public function testShouldNotBePrivate(): void
5151
{
5252
$classReflection = $this->broker->getClass(VisibilityEnum::class);
5353
$methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR');
5454

5555
$this->assertFalse($methodReflection->isPrivate());
5656
}
5757

58-
public function testShouldBePublic()
58+
public function testShouldBePublic(): void
5959
{
6060
$classReflection = $this->broker->getClass(VisibilityEnum::class);
6161
$methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR');
6262

6363
$this->assertTrue($methodReflection->isPublic());
6464
}
6565

66-
public function testGetVariants()
66+
public function testGetVariants(): void
6767
{
6868
$classReflection = $this->broker->getClass(VisibilityEnum::class);
6969
$methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR');
@@ -72,7 +72,7 @@ public function testGetVariants()
7272
$this->assertSame(VisibilityEnum::class, $parametersAcceptor->getReturnType()->describe(VerbosityLevel::value()));
7373
}
7474

75-
public function testGetDocComment()
75+
public function testGetDocComment(): void
7676
{
7777
$classReflection = $this->broker->getClass(DocCommentEnum::class);
7878
$docMethodRefl = $this->reflectionExtension->getMethod($classReflection, 'WITH_DOC_BLOCK');
@@ -88,7 +88,7 @@ public function testGetDocComment()
8888
$this->assertNotRegExp('/@var/', $docMethodRefl->getDocComment());
8989
}
9090

91-
public function testIsDeprecated()
91+
public function testIsDeprecated(): void
9292
{
9393
$classReflection = $this->broker->getClass(DeprecatedEnum::class);
9494
$deprecatedRefl = $this->reflectionExtension->getMethod($classReflection, 'DEPRECATED');
@@ -98,7 +98,7 @@ public function testIsDeprecated()
9898
$this->assertTrue($notDeprecatedRefl->isDeprecated()->no());
9999
}
100100

101-
public function testGetDeprecatedDescription()
101+
public function testGetDeprecatedDescription(): void
102102
{
103103
$classReflection = $this->broker->getClass(DeprecatedEnum::class);
104104
$deprecatedRefl = $this->reflectionExtension->getMethod($classReflection, 'DEPRECATED');

tests/unit/EnumMethodsClassReflectionExtensionTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class EnumMethodsClassReflectionExtensionTest extends TestCase
2222
*/
2323
protected $reflectionExtension;
2424

25-
public function setUp()
25+
public function setUp(): void
2626
{
2727
$this->broker = $this->createBroker();
2828
$this->reflectionExtension = new EnumMethodsClassReflectionExtension();
2929
}
3030

31-
public function testHasMethodSuccess()
31+
public function testHasMethodSuccess(): void
3232
{
3333
$classReflection = $this->broker->getClass(VisibilityEnum::class);
3434

@@ -37,19 +37,19 @@ public function testHasMethodSuccess()
3737
}
3838
}
3939

40-
public function testHasMethodUnknownNotFound()
40+
public function testHasMethodUnknownNotFound(): void
4141
{
4242
$classReflection = $this->broker->getClass(VisibilityEnum::class);
4343
$this->assertFalse($this->reflectionExtension->hasMethod($classReflection, 'UNKNOWN'));
4444
}
4545

46-
public function testHasMethodNotSubclassOfEnumNotFound()
46+
public function testHasMethodNotSubclassOfEnumNotFound(): void
4747
{
4848
$classReflection = $this->broker->getClass(NotAnEnum::class);
4949
$this->assertFalse($this->reflectionExtension->hasMethod($classReflection, 'STR'));
5050
}
5151

52-
public function testGetMethodSuccess()
52+
public function testGetMethodSuccess(): void
5353
{
5454
$classReflection = $this->broker->getClass(VisibilityEnum::class);
5555

0 commit comments

Comments
 (0)