Skip to content

Commit 94a47c5

Browse files
authored
Merge pull request #17 from timeweb/migrate-to-github-actions
Migrate to GitHub Actions, Fix tests, Add linter
2 parents 0c5919a + be472a5 commit 94a47c5

File tree

8 files changed

+111
-39
lines changed

8 files changed

+111
-39
lines changed

.github/linters/phpcs.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<ruleset name="super-linter">
4+
<rule ref="PSR12">
5+
<exclude name="PSR12.Properties.ConstantVisibility.NotFound" />
6+
</rule>
7+
</ruleset>

.github/linters/phpstan.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
level: max
3+
checkGenericClassInNonGenericObjectType: false
4+
ignoreErrors:
5+
- '#constructor invoked with#'
6+
- '#FunctionVariant constructor expects#'

.github/workflows/ci.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: CI
2+
3+
on: push
4+
5+
jobs:
6+
php-tests:
7+
8+
strategy:
9+
matrix:
10+
php: ['7.1', '7.2', '7.3', '7.4', '8.0']
11+
prefer: ['lowest', 'stable']
12+
13+
name: Test on PHP ${{ matrix.php }} with ${{ matrix.prefer }} composer prefer option
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout Code
18+
uses: actions/checkout@v2
19+
20+
- name: Install PHP
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php }}
24+
25+
- name: Check PHP Version
26+
run: php -v
27+
28+
- name: Cache Composer packages
29+
id: composer-cache
30+
uses: actions/cache@v2
31+
with:
32+
path: vendor
33+
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.prefer }}-
34+
restore-keys: |
35+
${{ runner.os }}-php-${{ matrix.php }}-composer-${{ matrix.prefer }}-
36+
37+
- name: Install dependencies
38+
if: steps.composer-cache.outputs.cache-hit != 'true'
39+
run: composer update --prefer-${{ matrix.prefer }} --prefer-dist --no-progress
40+
41+
- name: Run tests
42+
run: composer test
43+
44+
linter:
45+
name: Linter
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- name: Checkout Code
50+
uses: actions/checkout@v2
51+
52+
- name: Install PHP
53+
uses: shivammathur/setup-php@v2
54+
with:
55+
php-version: 7.1
56+
57+
- name: Install dependencies
58+
run: composer update --prefer-stable --prefer-dist --no-progress
59+
60+
- name: Lint Code
61+
uses: github/super-linter@v3
62+
env:
63+
FILTER_REGEX_EXCLUDE: .*vendor.*
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
VALIDATE_PHP_PSALM: false

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Enum class reflection extension for PHPStan
22

3-
[![Build Status](https://travis-ci.org/timeweb/phpstan-enum.svg?branch=master)](https://travis-ci.org/timeweb/phpstan-enum)
3+
[![Packagist Version](https://img.shields.io/packagist/v/timeweb/phpstan-enum)](https://packagist.org/packages/timeweb/phpstan-enum)
4+
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/timeweb/phpstan-enum/ci)
45

56
* [PHPStan](https://phpstan.org/)
67
* [PHP Enum](https://github.com/myclabs/php-enum)
@@ -11,13 +12,13 @@ This extension defines dynamic methods for `MyCLabs\Enum\Enum` subclasses.
1112

1213
To use this extension, require it with [Composer](https://getcomposer.org)
1314

14-
```
15+
```bash
1516
composer require --dev timeweb/phpstan-enum
1617
```
1718

1819
And include extension.neon in your project's PHPStan config
1920

20-
```
21+
```yaml
2122
includes:
2223
- vendor/timeweb/phpstan-enum/extension.neon
2324
```

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
"require": {
88
"php": "~7.1|^8.0",
99
"myclabs/php-enum": "^1.2",
10-
"phpstan/phpstan": "^0.10|^0.11|^0.12"
10+
"phpstan/phpstan": "^0.10|^0.11|^0.12.34"
1111
},
1212
"require-dev": {
13-
"phpunit/phpunit": "^6.0"
13+
"phpunit/phpunit": "^7.0|^9.0"
1414
},
1515
"autoload": {
1616
"psr-4": {
1717
"Timeweb\\PHPStan\\": "src/"
1818
}
1919
},
2020
"autoload-dev": {
21-
"classmap": [
22-
"tests/_fixture/"
23-
]
21+
"psr-4": {
22+
"Timeweb\\Tests\\PHPStan\\": "tests/"
23+
}
2424
},
2525
"scripts": {
2626
"test": "phpunit"

tests/_fixture/EnumFixture.php renamed to tests/Fixture/EnumFixture.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?php
22

3-
class EnumFixture extends MyCLabs\Enum\Enum
3+
declare(strict_types=1);
4+
5+
namespace Timeweb\Tests\PHPStan\Fixture;
6+
7+
use MyCLabs\Enum\Enum;
8+
9+
class EnumFixture extends Enum
410
{
511
const MEMBER = 'member';
612

tests/Reflection/EnumMethodsClassReflectionExtensionTest.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
declare(strict_types=1);
44

5+
namespace Timeweb\Tests\PHPStan\Reflection;
6+
57
use PHPStan\Reflection\ParametersAcceptorSelector;
68
use PHPStan\Testing\TestCase;
79
use PHPStan\Type\VerbosityLevel;
810
use Timeweb\PHPStan\Reflection\EnumMethodReflection;
911
use Timeweb\PHPStan\Reflection\EnumMethodsClassReflectionExtension;
12+
use Timeweb\Tests\PHPStan\Fixture\EnumFixture;
1013

1114
/**
12-
* @coversDefaultClass Timeweb\PHPStan\Reflection\EnumMethodsClassReflectionExtension
15+
* @coversDefaultClass \Timeweb\PHPStan\Reflection\EnumMethodsClassReflectionExtension
1316
*/
1417
class EnumMethodsClassReflectionExtensionTest extends TestCase
1518
{
@@ -23,7 +26,7 @@ class EnumMethodsClassReflectionExtensionTest extends TestCase
2326
*/
2427
protected $reflectionExtension;
2528

26-
public function setUp()
29+
public function setUp(): void
2730
{
2831
$this->broker = $this->createBroker();
2932
$this->reflectionExtension = new EnumMethodsClassReflectionExtension();
@@ -33,14 +36,17 @@ public function setUp()
3336
* @covers ::hasMethod
3437
* @dataProvider methodNameDataProvider
3538
*/
36-
public function testEnumMethodsCanBeFoundInEnumSubclasses(bool $expected, string $methodName)
39+
public function testEnumMethodsCanBeFoundInEnumSubclasses(bool $expected, string $methodName): void
3740
{
3841
$classReflection = $this->broker->getClass(EnumFixture::class);
3942
$hasMethod = $this->reflectionExtension->hasMethod($classReflection, $methodName);
4043

4144
$this->assertEquals($expected, $hasMethod);
4245
}
4346

47+
/**
48+
* @return array[]
49+
*/
4450
public function methodNameDataProvider(): array
4551
{
4652
return [
@@ -52,7 +58,7 @@ public function methodNameDataProvider(): array
5258
/**
5359
* @covers ::hasMethod
5460
*/
55-
public function testEnumMethodsCannotBeFoundInNonEnumSubclasses()
61+
public function testEnumMethodsCannotBeFoundInNonEnumSubclasses(): void
5662
{
5763
$classReflection = $this->broker->getClass(EnumFixture::class);
5864
$hasMethod = $this->reflectionExtension->hasMethod($classReflection, 'SOME_NAME');
@@ -62,9 +68,9 @@ public function testEnumMethodsCannotBeFoundInNonEnumSubclasses()
6268

6369
/**
6470
* @covers ::getMethod
65-
* @uses Timeweb\PHPStan\Reflection\EnumMethodReflection
71+
* @uses \Timeweb\PHPStan\Reflection\EnumMethodReflection
6672
*/
67-
public function testEnumMethodReflectionCanBeObtained()
73+
public function testEnumMethodReflectionCanBeObtained(): void
6874
{
6975
$classReflection = $this->broker->getClass(EnumFixture::class);
7076
$methodReflection = $this->reflectionExtension->getMethod($classReflection, 'SOME_NAME');
@@ -80,10 +86,10 @@ public function testEnumMethodReflectionCanBeObtained()
8086
* @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::isPublic
8187
* @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::getPrototype
8288
* @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::getVariants
83-
* @uses Timeweb\PHPStan\Reflection\EnumMethodReflection
89+
* @uses \Timeweb\PHPStan\Reflection\EnumMethodReflection
8490
* @dataProvider enumFixtureProperties
8591
*/
86-
public function testEnumMethodProperties(string $propertyName)
92+
public function testEnumMethodProperties(string $propertyName): void
8793
{
8894
$classReflection = $this->broker->getClass(EnumFixture::class);
8995
$methodReflection = $this->reflectionExtension->getMethod($classReflection, $propertyName);
@@ -97,6 +103,9 @@ public function testEnumMethodProperties(string $propertyName)
97103
$this->assertSame(EnumFixture::class, $parametersAcceptor->getReturnType()->describe(VerbosityLevel::value()));
98104
}
99105

106+
/**
107+
* @return string[][]
108+
*/
100109
public function enumFixtureProperties(): array
101110
{
102111
return [

0 commit comments

Comments
 (0)