Skip to content

Commit

Permalink
Add support for PHPStan 2 (#348)
Browse files Browse the repository at this point in the history
This PR includes a lot of changes to pass CI.

### requiments, dependency
- Update requirements PHPUnit >=9.1 .
  - Becaouse, run test with  PHPUnit 8 would cause deprecation warning.
  - PHPUnit 9 requires PHP 7.3, and PHPStan requires PHP 7.4. So update requirements is acceptable, I think.
- Add requiments [phpspec/prophecy-phpunit](1470fd3)
- Update php-cs-fixer 2 to 3. ( `.php_cs` to `.php-cs-fixer.php`)
  - to run under  recent PHP 8 versions
  - I'm not familiar with php-cs-fixer, so if you find any problem, please tell me.
### tests
-  [Use PHP's reflection to get stub object, instead of prophesize() call](315866a)
   - PHPStan 2's `Reflection\ClassReflection` is final class.
   - I can't see any good reason to use `prophesize()` in these unit tests.



---------

Co-authored-by: Christophe Coevoet <[email protected]>
Co-authored-by: Alexander Schranz <[email protected]>
Co-authored-by: Alessandro Lai <[email protected]>
  • Loading branch information
4 people authored Nov 21, 2024
1 parent cf740b0 commit cc8c094
Show file tree
Hide file tree
Showing 21 changed files with 1,582 additions and 1,113 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test/ export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php_cs export-ignore
.php-cs-fixer.php export-ignore
.yamllint.yaml export-ignore
composer.lock export-ignore
Makefile export-ignore
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.1"
- "7.4"

dependencies:
- "locked"
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
restore-keys: "php-${{ matrix.php-version }}-php-cs-fixer-"

- name: "Run friendsofphp/php-cs-fixer"
run: "vendor/bin/php-cs-fixer fix --ansi --config=.php_cs --diff --diff-format=udiff --dry-run --verbose"
run: "vendor/bin/php-cs-fixer fix --ansi --config=.php-cs-fixer.php --diff --dry-run --verbose"

static-code-analysis:
name: "Static Code Analysis"
Expand All @@ -90,10 +90,7 @@ jobs:
- "7.4"

phpunit-version:
- "6.0.0"
- "7.0.0"
- "8.0.0"
- "9.0.0"
- "9.1.0"

dependencies:
- "lowest"
Expand Down
6 changes: 3 additions & 3 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
__DIR__ . '/LICENSE.md',
License\Year::fromString('2018'),
License\Holder::fromString('Jan Gregor Emge-Triebel'),
License\Url::fromString('https://github.com/Jan0707/phpstan-prophecy')
License\Url::fromString('https://github.com/Jan0707/phpstan-prophecy'),
);

$license->save();

$config = PhpCsFixer\Config\Factory::fromRuleSet(new PhpCsFixer\Config\RuleSet\Php71($license->header()), [
$config = PhpCsFixer\Config\Factory::fromRuleSet(new PhpCsFixer\Config\RuleSet\Php74($license->header()), [
'final_class' => false,
]);

Expand All @@ -36,7 +36,7 @@
->ignoreDotFiles(false)
->in(__DIR__)
->name('*.phpstub')
->name('.php_cs');
->name('.php-cs-fixer.php');

$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php_cs.cache');

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ coding-standards: vendor ## Normalizes composer.json with ergebnis/composer-norm
composer normalize
yamllint -c .yamllint.yaml --strict .
mkdir -p .build/php-cs-fixer
vendor/bin/php-cs-fixer fix --config=.php_cs --diff --diff-format=udiff --verbose
export PHP_CS_FIXER_IGNORE_ENV=1 && vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --verbose

.PHONY: help
help: ## Displays this list of targets with descriptions
Expand All @@ -26,7 +26,7 @@ static-code-analysis: vendor ## Runs a static code analysis with phpstan/phpstan
.PHONY: static-code-analysis-baseline
static-code-analysis-baseline: vendor ## Generates a baseline for static code analysis with phpstan/phpstan and vimeo/psalm
mkdir -p .build/phpstan
vendor/bin/phpstan analyze --configuration=phpstan-with-extension.neon --generate-baseline=phpstan-with-extension-baseline.neon --memory-limit=-1
vendor/bin/phpstan analyze --configuration=phpstan-with-extension.neon --generate-baseline=phpstan-with-extension-baseline.neon --allow-empty-baseline --memory-limit=-1
vendor/bin/phpstan analyze --configuration=phpstan-without-extension.neon --generate-baseline=phpstan-without-extension-baseline.neon --memory-limit=-1

.PHONY: tests
Expand Down
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
}
],
"require": {
"php": "^7.1 || ^8.0",
"phpstan/phpstan": "^1.0.0"
"php": "^7.4 || ^8.0",
"phpstan/phpstan": "^2.0.0"
},
"conflict": {
"phpspec/prophecy": "<1.7.0 || >=2.0.0",
"phpunit/phpunit": "<6.0.0 || >=12.0.0"
"phpspec/prophecy": "<1.17.0 || >=2.0.0",
"phpspec/prophecy-phpunit": "<2.3.0 || >=3.0.0",
"phpunit/phpunit": "<9.1.0 || >=12.0.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.1.1",
"ergebnis/license": "^1.0.0",
"ergebnis/php-cs-fixer-config": "~2.2.0",
"ergebnis/php-cs-fixer-config": "^4.0 || ^5.0 || ^6.0",
"phpspec/prophecy": "^1.7.0",
"phpunit/phpunit": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0"
"phpspec/prophecy-phpunit": "^2.3",
"phpunit/phpunit": "^9.1.0"
},
"config": {
"allow-plugins": {
Expand Down
Loading

0 comments on commit cc8c094

Please sign in to comment.