From ba39d60187c88882f80eea97851633cd04de08fd Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 4 Nov 2021 13:45:02 +0100 Subject: [PATCH 01/10] Fix detectGetValuesReturnType --- src/EnumDynamicReturnTypeExtension.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/EnumDynamicReturnTypeExtension.php b/src/EnumDynamicReturnTypeExtension.php index a4de1fd..ab05196 100644 --- a/src/EnumDynamicReturnTypeExtension.php +++ b/src/EnumDynamicReturnTypeExtension.php @@ -8,8 +8,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ParametersAcceptorSelector; -use PHPStan\Type\ArrayType; -use PHPStan\Type\Constant\ConstantArrayType; +use PHPStan\Type\Constant\ConstantArrayTypeBuilder; use PHPStan\Type\ConstantTypeHelper; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\DynamicStaticMethodReturnTypeExtension; @@ -159,10 +158,17 @@ private function detectGetValueReturnType(string $enumeration): Type * Returns return type of Enum::getValues() * @phpstan-param class-string $enumeration */ - private function detectGetValuesReturnType(string $enumeration): ArrayType + private function detectGetValuesReturnType(string $enumeration): Type { $keyTypes = $this->enumOrdinalTypes($enumeration); $valueTypes = $this->enumValueTypes($enumeration); - return new ConstantArrayType($keyTypes, $valueTypes, count($keyTypes)); + + $builder = ConstantArrayTypeBuilder::createEmpty(); + foreach ($keyTypes as $i => $keyType) { + $valueType = $valueTypes[$i]; + $builder->setOffsetValueType($keyType, $valueType); + } + + return $builder->getArray(); } } From 8f77fca0d1fc632e6f39d3cbf5a8391e89ab60c0 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 4 Nov 2021 13:47:24 +0100 Subject: [PATCH 02/10] Fix EnumDynamicReturnTypeExtensionTest --- tests/unit/EnumDynamicReturnTypeExtensionTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/unit/EnumDynamicReturnTypeExtensionTest.php b/tests/unit/EnumDynamicReturnTypeExtensionTest.php index 9198fb2..6e06ec3 100644 --- a/tests/unit/EnumDynamicReturnTypeExtensionTest.php +++ b/tests/unit/EnumDynamicReturnTypeExtensionTest.php @@ -4,14 +4,13 @@ use MabeEnum\Enum; use MabeEnumPHPStan\EnumDynamicReturnTypeExtension; -use MabeEnumPHPStan\EnumMethodsClassReflectionExtension; use PHPStan\Reflection\Dummy\DummyMethodReflection; use PHPStan\Testing\TestCase; class EnumDynamicReturnTypeExtensionTest extends TestCase { /** - * @var EnumMethodsClassReflectionExtension + * @var EnumDynamicReturnTypeExtension */ protected $extension; From 871886fcafaf3b0dff10e06217b746e4992d534e Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 4 Nov 2021 13:37:49 +0100 Subject: [PATCH 03/10] Analyse package with PHPStan --- .gitignore | 3 +++ phpstan.neon.dist | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 phpstan.neon.dist diff --git a/.gitignore b/.gitignore index 0309237..de250b4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ #composer composer.lock vendor + +#phpstan +phpstan.neon diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..8814d51 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,10 @@ +includes: + - extension.neon + +parameters: + level: 5 + paths: + - src + - tests + excludePaths: + - tests/integration/data From d9feadac7dd53c19e2e008320f278ca799c0687d Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 4 Nov 2021 13:50:57 +0100 Subject: [PATCH 04/10] Update to PHPStan 1.0 --- composer.json | 2 +- phpstan.neon.dist | 1 + tests/unit/EnumDynamicReturnTypeExtensionTest.php | 4 ++-- tests/unit/EnumMethodReflectionTest.php | 4 ++-- tests/unit/EnumMethodsClassReflectionExtensionTest.php | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index a8a52b8..8515c66 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "require": { "php": "^7.1 | ^8.0", "marc-mabe/php-enum": "^1.1 || ^2.0 || ^3.0 || ^4.0", - "phpstan/phpstan": "^0.12" + "phpstan/phpstan": "^1.0" }, "require-dev": { "phpunit/phpunit": "^7.5 | ^8.5 | 9.4" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 8814d51..5912a02 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -7,4 +7,5 @@ parameters: - src - tests excludePaths: + - tests/assets - tests/integration/data diff --git a/tests/unit/EnumDynamicReturnTypeExtensionTest.php b/tests/unit/EnumDynamicReturnTypeExtensionTest.php index 6e06ec3..c5f6954 100644 --- a/tests/unit/EnumDynamicReturnTypeExtensionTest.php +++ b/tests/unit/EnumDynamicReturnTypeExtensionTest.php @@ -5,9 +5,9 @@ use MabeEnum\Enum; use MabeEnumPHPStan\EnumDynamicReturnTypeExtension; use PHPStan\Reflection\Dummy\DummyMethodReflection; -use PHPStan\Testing\TestCase; +use PHPStan\Testing\PHPStanTestCase; -class EnumDynamicReturnTypeExtensionTest extends TestCase +class EnumDynamicReturnTypeExtensionTest extends PHPStanTestCase { /** * @var EnumDynamicReturnTypeExtension diff --git a/tests/unit/EnumMethodReflectionTest.php b/tests/unit/EnumMethodReflectionTest.php index 087434f..6aa85d2 100644 --- a/tests/unit/EnumMethodReflectionTest.php +++ b/tests/unit/EnumMethodReflectionTest.php @@ -7,10 +7,10 @@ use MabeEnum\PHPStan\tests\assets\DocCommentEnum; use MabeEnum\PHPStan\tests\assets\VisibilityEnum; use PHPStan\Reflection\ParametersAcceptorSelector; -use PHPStan\Testing\TestCase; +use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\VerbosityLevel; -class EnumMethodReflectionTest extends TestCase +class EnumMethodReflectionTest extends PHPStanTestCase { /** * @var \PHPStan\Broker\Broker diff --git a/tests/unit/EnumMethodsClassReflectionExtensionTest.php b/tests/unit/EnumMethodsClassReflectionExtensionTest.php index 820f3db..9ee8da9 100644 --- a/tests/unit/EnumMethodsClassReflectionExtensionTest.php +++ b/tests/unit/EnumMethodsClassReflectionExtensionTest.php @@ -6,9 +6,9 @@ use MabeEnumPHPStan\EnumMethodsClassReflectionExtension; use MabeEnum\PHPStan\tests\assets\NotAnEnum; use MabeEnum\PHPStan\tests\assets\VisibilityEnum; -use PHPStan\Testing\TestCase; +use PHPStan\Testing\PHPStanTestCase; -class EnumMethodsClassReflectionExtensionTest extends TestCase +class EnumMethodsClassReflectionExtensionTest extends PHPStanTestCase { /** * @var \PHPStan\Broker\Broker From 0d5cbc6e751001a04a18cafbe83f4b97fc0740a7 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 4 Nov 2021 13:54:37 +0100 Subject: [PATCH 05/10] .editorconfig --- .editorconfig | 9 +++++++++ .gitignore | 1 + 2 files changed, 10 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..88d9f04 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 diff --git a/.gitignore b/.gitignore index de250b4..89ee517 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ !.gitignore !.gitattributes !.github +!.editorconfig #composer composer.lock From 35f28c58afa9d3824f05d1822a8f837f8454674a Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 4 Nov 2021 13:56:14 +0100 Subject: [PATCH 06/10] Stop using DummyMethodReflection not covered by Backward Compatibility Promise --- .../EnumDynamicReturnTypeExtensionTest.php | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/unit/EnumDynamicReturnTypeExtensionTest.php b/tests/unit/EnumDynamicReturnTypeExtensionTest.php index c5f6954..32cd363 100644 --- a/tests/unit/EnumDynamicReturnTypeExtensionTest.php +++ b/tests/unit/EnumDynamicReturnTypeExtensionTest.php @@ -4,7 +4,7 @@ use MabeEnum\Enum; use MabeEnumPHPStan\EnumDynamicReturnTypeExtension; -use PHPStan\Reflection\Dummy\DummyMethodReflection; +use PHPStan\Reflection\MethodReflection; use PHPStan\Testing\PHPStanTestCase; class EnumDynamicReturnTypeExtensionTest extends PHPStanTestCase @@ -24,41 +24,49 @@ public function testGetClass(): void $this->assertSame(Enum::class, $this->extension->getClass()); } + private function createMethodWithName(string $name): MethodReflection + { + $method = $this->createMock(MethodReflection::class); + $method->method('getName')->willReturn($name); + + return $method; + } + /** @dataProvider staticMethodsProvider */ public function testIsStaticMethodSupportedShouldReturnTrue(string $method): void { - $reflectionMethod = new DummyMethodReflection($method); + $reflectionMethod = $this->createMethodWithName($method); $this->assertTrue($this->extension->isStaticMethodSupported($reflectionMethod)); - $reflectionMethod = new DummyMethodReflection(strtolower($method)); + $reflectionMethod = $this->createMethodWithName(strtolower($method)); $this->assertTrue($this->extension->isStaticMethodSupported($reflectionMethod)); - $reflectionMethod = new DummyMethodReflection(strtoupper($method)); + $reflectionMethod = $this->createMethodWithName(strtoupper($method)); $this->assertTrue($this->extension->isStaticMethodSupported($reflectionMethod)); } public function testIsStaticMethodSupportedShouldReturnFalse(): void { - $reflectionMethod = new DummyMethodReflection('fooBar'); + $reflectionMethod = $this->createMethodWithName('fooBar'); $this->assertFalse($this->extension->isStaticMethodSupported($reflectionMethod)); } /** @dataProvider objectMethodsProvider */ public function testIsMethodSupportedShouldReturnTrue(string $method): void { - $reflectionMethod = new DummyMethodReflection($method); + $reflectionMethod = $this->createMethodWithName($method); $this->assertTrue($this->extension->isMethodSupported($reflectionMethod)); - $reflectionMethod = new DummyMethodReflection(strtolower($method)); + $reflectionMethod = $this->createMethodWithName(strtolower($method)); $this->assertTrue($this->extension->isMethodSupported($reflectionMethod)); - $reflectionMethod = new DummyMethodReflection(strtoupper($method)); + $reflectionMethod = $this->createMethodWithName(strtoupper($method)); $this->assertTrue($this->extension->isMethodSupported($reflectionMethod)); } public function testIsMethodSupportedShouldReturnFalse(): void { - $reflectionMethod = new DummyMethodReflection('fooBar'); + $reflectionMethod = $this->createMethodWithName('fooBar'); $this->assertFalse($this->extension->isMethodSupported($reflectionMethod)); } From 48ddcfdc65d5a533956a8d0a97cb5f679f03607f Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 4 Nov 2021 13:58:29 +0100 Subject: [PATCH 07/10] Stop using deprecated Broker in favor of ReflectionProvider --- tests/unit/EnumMethodReflectionTest.php | 34 +++++++++---------- ...numMethodsClassReflectionExtensionTest.php | 14 ++++---- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/unit/EnumMethodReflectionTest.php b/tests/unit/EnumMethodReflectionTest.php index 6aa85d2..03f70dd 100644 --- a/tests/unit/EnumMethodReflectionTest.php +++ b/tests/unit/EnumMethodReflectionTest.php @@ -13,9 +13,9 @@ class EnumMethodReflectionTest extends PHPStanTestCase { /** - * @var \PHPStan\Broker\Broker + * @var \PHPStan\Reflection\ReflectionProvider */ - protected $broker; + protected $reflectionProvider; /** * @var EnumMethodsClassReflectionExtension @@ -24,13 +24,13 @@ class EnumMethodReflectionTest extends PHPStanTestCase public function setUp(): void { - $this->broker = $this->createBroker(); + $this->reflectionProvider = $this->createReflectionProvider(); $this->reflectionExtension = new EnumMethodsClassReflectionExtension(); } public function testGetName(): void { - $classReflection = $this->broker->getClass(VisibilityEnum::class); + $classReflection = $this->reflectionProvider->getClass(VisibilityEnum::class); $methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR'); $this->assertSame('STR', $methodReflection->getName()); @@ -38,7 +38,7 @@ public function testGetName(): void public function testGetDeclaringClass(): void { - $classReflection = $this->broker->getClass(VisibilityEnum::class); + $classReflection = $this->reflectionProvider->getClass(VisibilityEnum::class); $methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR'); $this->assertSame($classReflection, $methodReflection->getDeclaringClass()); @@ -46,7 +46,7 @@ public function testGetDeclaringClass(): void public function testShouldBeStatic(): void { - $classReflection = $this->broker->getClass(VisibilityEnum::class); + $classReflection = $this->reflectionProvider->getClass(VisibilityEnum::class); $methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR'); $this->assertTrue($methodReflection->isStatic()); @@ -54,7 +54,7 @@ public function testShouldBeStatic(): void public function testShouldNotBePrivate(): void { - $classReflection = $this->broker->getClass(VisibilityEnum::class); + $classReflection = $this->reflectionProvider->getClass(VisibilityEnum::class); $methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR'); $this->assertFalse($methodReflection->isPrivate()); @@ -62,7 +62,7 @@ public function testShouldNotBePrivate(): void public function testShouldBePublic(): void { - $classReflection = $this->broker->getClass(VisibilityEnum::class); + $classReflection = $this->reflectionProvider->getClass(VisibilityEnum::class); $methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR'); $this->assertTrue($methodReflection->isPublic()); @@ -70,7 +70,7 @@ public function testShouldBePublic(): void public function testGetPrototype(): void { - $classReflection = $this->broker->getClass(VisibilityEnum::class); + $classReflection = $this->reflectionProvider->getClass(VisibilityEnum::class); $methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR'); $this->assertSame($methodReflection, $methodReflection->getPrototype()); @@ -78,7 +78,7 @@ public function testGetPrototype(): void public function testGetVariants(): void { - $classReflection = $this->broker->getClass(VisibilityEnum::class); + $classReflection = $this->reflectionProvider->getClass(VisibilityEnum::class); $methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR'); $parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants()); @@ -87,7 +87,7 @@ public function testGetVariants(): void public function testGetDocComment(): void { - $classReflection = $this->broker->getClass(DocCommentEnum::class); + $classReflection = $this->reflectionProvider->getClass(DocCommentEnum::class); $docMethodRefl = $this->reflectionExtension->getMethod($classReflection, 'WITH_DOC_BLOCK'); $noDocMethodRefl = $this->reflectionExtension->getMethod($classReflection, 'WITHOUT_DOC_BLOCK'); @@ -103,7 +103,7 @@ public function testGetDocComment(): void public function testIsDeprecated(): void { - $classReflection = $this->broker->getClass(DeprecatedEnum::class); + $classReflection = $this->reflectionProvider->getClass(DeprecatedEnum::class); $deprecatedRefl = $this->reflectionExtension->getMethod($classReflection, 'DEPRECATED'); $notDeprecatedRefl = $this->reflectionExtension->getMethod($classReflection, 'NOT_DEPRECATED'); @@ -113,7 +113,7 @@ public function testIsDeprecated(): void public function testGetDeprecatedDescription(): void { - $classReflection = $this->broker->getClass(DeprecatedEnum::class); + $classReflection = $this->reflectionProvider->getClass(DeprecatedEnum::class); $deprecatedRefl = $this->reflectionExtension->getMethod($classReflection, 'DEPRECATED'); $notDeprecatedRefl = $this->reflectionExtension->getMethod($classReflection, 'NOT_DEPRECATED'); @@ -123,7 +123,7 @@ public function testGetDeprecatedDescription(): void public function testIsFinal(): void { - $classReflection = $this->broker->getClass(DeprecatedEnum::class); + $classReflection = $this->reflectionProvider->getClass(DeprecatedEnum::class); $methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR'); $this->assertTrue($methodReflection->isFinal()->no()); @@ -131,7 +131,7 @@ public function testIsFinal(): void public function testIsInternal(): void { - $classReflection = $this->broker->getClass(DeprecatedEnum::class); + $classReflection = $this->reflectionProvider->getClass(DeprecatedEnum::class); $methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR'); $this->assertTrue($methodReflection->isInternal()->no()); @@ -139,7 +139,7 @@ public function testIsInternal(): void public function testGetThrowType(): void { - $classReflection = $this->broker->getClass(DeprecatedEnum::class); + $classReflection = $this->reflectionProvider->getClass(DeprecatedEnum::class); $methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR'); $this->assertNull($methodReflection->getThrowType()); @@ -147,7 +147,7 @@ public function testGetThrowType(): void public function testHasSideEffects(): void { - $classReflection = $this->broker->getClass(DeprecatedEnum::class); + $classReflection = $this->reflectionProvider->getClass(DeprecatedEnum::class); $methodReflection = $this->reflectionExtension->getMethod($classReflection, 'STR'); $this->assertTrue($methodReflection->hasSideEffects()->no()); diff --git a/tests/unit/EnumMethodsClassReflectionExtensionTest.php b/tests/unit/EnumMethodsClassReflectionExtensionTest.php index 9ee8da9..121381d 100644 --- a/tests/unit/EnumMethodsClassReflectionExtensionTest.php +++ b/tests/unit/EnumMethodsClassReflectionExtensionTest.php @@ -11,9 +11,9 @@ class EnumMethodsClassReflectionExtensionTest extends PHPStanTestCase { /** - * @var \PHPStan\Broker\Broker + * @var \PHPStan\Reflection\ReflectionProvider */ - protected $broker; + protected $reflectionProvider; /** * @var EnumMethodsClassReflectionExtension @@ -22,13 +22,13 @@ class EnumMethodsClassReflectionExtensionTest extends PHPStanTestCase public function setUp(): void { - $this->broker = $this->createBroker(); + $this->reflectionProvider = $this->createReflectionProvider(); $this->extension = new EnumMethodsClassReflectionExtension(); } public function testHasMethodSuccess(): void { - $classReflection = $this->broker->getClass(VisibilityEnum::class); + $classReflection = $this->reflectionProvider->getClass(VisibilityEnum::class); foreach (array_keys(VisibilityEnum::getConstants()) as $name) { $this->assertTrue($this->extension->hasMethod($classReflection, $name)); @@ -37,19 +37,19 @@ public function testHasMethodSuccess(): void public function testHasMethodUnknownNotFound(): void { - $classReflection = $this->broker->getClass(VisibilityEnum::class); + $classReflection = $this->reflectionProvider->getClass(VisibilityEnum::class); $this->assertFalse($this->extension->hasMethod($classReflection, 'UNKNOWN')); } public function testHasMethodNotSubclassOfEnumNotFound(): void { - $classReflection = $this->broker->getClass(NotAnEnum::class); + $classReflection = $this->reflectionProvider->getClass(NotAnEnum::class); $this->assertFalse($this->extension->hasMethod($classReflection, 'STR')); } public function testGetMethodSuccess(): void { - $classReflection = $this->broker->getClass(VisibilityEnum::class); + $classReflection = $this->reflectionProvider->getClass(VisibilityEnum::class); foreach (array_keys(VisibilityEnum::getConstants()) as $name) { $methodReflection = $this->extension->getMethod($classReflection, $name); From 61d286d6d12673a1748e9176298bfa353b3387ee Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 4 Nov 2021 14:01:27 +0100 Subject: [PATCH 08/10] Run PHPStan in GitHub Actions --- .editorconfig | 3 +++ .github/workflows/phpstan.yml | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .github/workflows/phpstan.yml diff --git a/.editorconfig b/.editorconfig index 88d9f04..f5c50c2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,6 @@ charset = utf-8 trim_trailing_whitespace = true indent_style = space indent_size = 4 + +[*.yml] +indent_size = 2 diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..5b21f42 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,37 @@ +name: PHPStan + +on: + pull_request: + push: + branches: + - master + +jobs: + phpstan: + name: "PHPStan" + runs-on: "ubuntu-latest" + timeout-minutes: 30 + + strategy: + fail-fast: false + matrix: + php-version: + - "7.4" + - "8.0" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + extensions: mbstring + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "PHPStan" + run: "vendor/bin/phpstan" From 425d060a70bc4c38d3c2581403da2bc0dfbada50 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 4 Nov 2021 14:04:01 +0100 Subject: [PATCH 09/10] GitHub Actions - tests without Docker --- .github/workflows/test.Dockerfile | 18 ------ .github/workflows/test.yml | 76 ----------------------- .github/workflows/tests-code-coverage.yml | 46 ++++++++++++++ .github/workflows/tests.yml | 36 +++++++++++ 4 files changed, 82 insertions(+), 94 deletions(-) delete mode 100644 .github/workflows/test.Dockerfile delete mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/tests-code-coverage.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/test.Dockerfile b/.github/workflows/test.Dockerfile deleted file mode 100644 index a7acaf1..0000000 --- a/.github/workflows/test.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -ARG PHP_VERSION=latest -FROM php:${PHP_VERSION}-cli-alpine - -WORKDIR /workdir - -# install composer -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer -ENV COMPOSER_ALLOW_SUPERUSER=1 -ENV COMPOSER_HTACCESS_PROTECT=0 -ENV COMPOSER_CACHE_DIR=/.composer - -# install PHP extension pcov -RUN 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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 886b473..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: Test - -on: - pull_request: - push: - branches: - - master - -jobs: - php: - runs-on: ubuntu-latest - strategy: - matrix: - include: - - PHP_VERSION: 7.1 - CODE_COVERAGE: false - COMPOSER_EXTRA_ARGS: --prefer-lowest - - PHP_VERSION: 7.1 - CODE_COVERAGE: false - - PHP_VERSION: 7.2 - CODE_COVERAGE: true - - PHP_VERSION: 7.3 - CODE_COVERAGE: true - - PHP_VERSION: 7.4 - CODE_COVERAGE: true - - PHP_VERSION: 8.0 - CODE_COVERAGE: true - - steps: - - uses: actions/checkout@v2 - - - name: Cache Docker Image - id: cache-docker-image - uses: actions/cache@v2 - with: - path: /tmp/docker-image.tar - key: cache-docker-image-test:${{ matrix.PHP_VERSION }} - - - name: Load Docker Image - if: steps.cache-docker-image.outputs.cache-hit == 'true' - run: docker load --input /tmp/docker-image.tar - - - name: Build Docker Image - if: steps.cache-docker-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 }}' . - - - name: Cache Composer Cache Files - uses: actions/cache@v2 - with: - path: /tmp/composer-cache-files - key: cache-composer-cache-files-${{ matrix.PHP_VERSION }} - restore-keys: | - cache-composer-cache-files- - - - name: Install Composer Dependencies - run: | - 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 }} - - - 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 }} - with: - token: ${{ secrets.CODECOV_TOKEN }} - file: .clover.xml - - - name: Export Docker Image - if: steps.cache-docker-image.outputs.cache-hit != 'true' - run: docker save --output /tmp/docker-image.tar 'test:${{ matrix.PHP_VERSION }}' diff --git a/.github/workflows/tests-code-coverage.yml b/.github/workflows/tests-code-coverage.yml new file mode 100644 index 0000000..38061ec --- /dev/null +++ b/.github/workflows/tests-code-coverage.yml @@ -0,0 +1,46 @@ +name: Tests with code coverage + +on: + pull_request: + push: + branches: + - master + +jobs: + tests: + name: "Tests" + runs-on: "ubuntu-latest" + timeout-minutes: 30 + + strategy: + fail-fast: false + matrix: + php-version: + - "7.2" + - "7.3" + - "7.4" + - "8.0" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{ matrix.php-version }}" + extensions: mbstring + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Tests" + run: | + php -d 'zend.assertions=1' -d 'pcov.enabled=1' -d 'pcov.directory=src' vendor/bin/phpunit --coverage-clover=.clover.xml + + - name: "Upload Codecov Report" + uses: "codecov/codecov-action@v1" + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: .clover.xml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..6d29345 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,36 @@ +name: Tests + +on: + pull_request: + push: + branches: + - master + +jobs: + tests: + name: "Tests" + runs-on: "ubuntu-latest" + timeout-minutes: 30 + + strategy: + fail-fast: false + matrix: + php-version: + - "7.1" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + extensions: mbstring + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Tests" + run: "vendor/bin/phpunit" From eaa235952b9b3d7d199ef5cf3c429593cec6b3c9 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 4 Nov 2021 14:13:01 +0100 Subject: [PATCH 10/10] Test PHP 8.1 --- .github/workflows/tests-code-coverage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests-code-coverage.yml b/.github/workflows/tests-code-coverage.yml index 38061ec..9985786 100644 --- a/.github/workflows/tests-code-coverage.yml +++ b/.github/workflows/tests-code-coverage.yml @@ -20,6 +20,7 @@ jobs: - "7.3" - "7.4" - "8.0" + - "8.1" steps: - name: "Checkout"