diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f3203de..5331282 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,9 +5,9 @@ updates: directory: "/" schedule: interval: "weekly" - commit-message: - include: "scope" - prefix: "composer" - labels: - - "dependency-update" versioning-strategy: "widen" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..b4a80b0 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,102 @@ +name: "CI" + +on: + pull_request: + push: + branches: + - "master" + +env: + INI_VALUES: zend.assertions=1,error_reporting=-1 + +jobs: + composer-json-lint: + name: "Lint composer.json" + runs-on: "ubuntu-latest" + strategy: + matrix: + php-version: + - "8.1" + + steps: + - uses: "actions/checkout@v3" + - uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + ini-values: "${{ env.INI_VALUES }}" + tools: composer-normalize,composer-require-checker,composer-unused + - uses: "ramsey/composer-install@v2" + + - run: "composer validate --strict" + - run: "composer-normalize --dry-run" + - run: "composer-require-checker check" + - run: "composer-unused" + + tests: + name: "Tests" + runs-on: "ubuntu-latest" + strategy: + matrix: + php-version: + - "8.2" + code-coverage: + - "none" + include: + - php-version: "8.1" + code-coverage: "pcov" + + steps: + - uses: "actions/checkout@v3" + - uses: "shivammathur/setup-php@v2" + with: + coverage: "${{ matrix.code-coverage }}" + php-version: "${{ matrix.php-version }}" + ini-values: "${{ env.INI_VALUES }}" + - uses: "ramsey/composer-install@v2" + + - run: "vendor/bin/phpunit --no-coverage --no-logging" + if: ${{ matrix.code-coverage == 'none' }} + timeout-minutes: 3 + + - run: "vendor/bin/phpunit --no-logging" + if: ${{ matrix.code-coverage != 'none' }} + timeout-minutes: 3 + + coding-standards: + name: "Coding Standards" + runs-on: "ubuntu-latest" + strategy: + matrix: + php-version: + - "8.1" + + steps: + - uses: "actions/checkout@v3" + - uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + ini-values: "${{ env.INI_VALUES }}" + - uses: "ramsey/composer-install@v2" + + - run: "vendor/bin/php-cs-fixer fix --verbose --dry-run --diff" + + static-analysis: + name: "Static Analysis" + runs-on: "ubuntu-latest" + strategy: + matrix: + php-version: + - "8.1" + + steps: + - uses: "actions/checkout@v3" + - uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + ini-values: "${{ env.INI_VALUES }}" + - uses: "ramsey/composer-install@v2" + + - run: "vendor/bin/phpstan analyse --no-progress --error-format=github" diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml deleted file mode 100644 index a06f7db..0000000 --- a/.github/workflows/integrate.yaml +++ /dev/null @@ -1,169 +0,0 @@ -name: "Integrate" - -on: - pull_request: - push: - branches: - - "master" - -jobs: - composer-json-lint: - name: "Lint composer.json" - - runs-on: "ubuntu-latest" - - strategy: - matrix: - php-version: - - "8.1" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - php-version: "${{ matrix.php-version }}" - tools: composer-normalize, composer-require-checker, composer-unused - - - name: "Get composer cache directory" - id: composercache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: "Cache dependencies" - uses: actions/cache@v2 - with: - path: ${{ steps.composercache.outputs.dir }} - key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer- - - - name: "Install dependencies" - run: "composer update --no-interaction --no-progress" - - - name: "Validate composer.json" - run: "composer validate --strict" - - - name: "Normalize composer.json" - run: "composer-normalize --dry-run" - - - name: "Check composer.json explicit dependencies" - run: "composer-require-checker" - - - name: "Check composer.json unused dependencies" - run: "composer-unused" - - tests: - name: "Tests" - - runs-on: "ubuntu-latest" - - strategy: - matrix: - php-version: - - "8.1" - - "8.2" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "pcov" - php-version: "${{ matrix.php-version }}" - ini-values: zend.assertions=1 - - - name: "Get composer cache directory" - id: composercache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: "Cache dependencies" - uses: actions/cache@v2 - with: - path: ${{ steps.composercache.outputs.dir }} - key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer- - - - name: "Install dependencies" - run: "composer update --no-interaction --no-progress" - - - name: "Run tests" - timeout-minutes: 3 - run: "make test" - - coding-standards: - name: "Coding Standards" - - runs-on: "ubuntu-latest" - - strategy: - matrix: - php-version: - - "8.1" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - php-version: "${{ matrix.php-version }}" - - - name: "Get composer cache directory" - id: composercache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: "Cache dependencies" - uses: actions/cache@v2 - with: - path: ${{ steps.composercache.outputs.dir }} - key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer- - - - name: "Install dependencies" - run: "composer update --no-interaction --no-progress" - - - name: "Check coding standards" - run: "vendor/bin/php-cs-fixer fix --verbose --dry-run --diff" - - static-analysis: - name: "Static Analysis" - - runs-on: "ubuntu-latest" - - strategy: - matrix: - php-version: - - "8.1" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - php-version: "${{ matrix.php-version }}" - - - name: "Get composer cache directory" - id: composercache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: "Cache dependencies" - uses: actions/cache@v2 - with: - path: ${{ steps.composercache.outputs.dir }} - key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer- - - - name: "Install dependencies" - run: "composer update --no-interaction --no-progress" - - - name: "Run static analysis" - run: "vendor/bin/phpstan analyse --no-progress --error-format=github" diff --git a/.gitignore b/.gitignore index e6e2332..77897c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ -.idea/ -vendor/ -.php-cs-fixer.cache -composer.lock -.phpunit.result.cache +/.idea/ +/.phpunit.cache/ +/vendor/ +/coverage/ +/.php-cs-fixer.cache +/.phpunit.result.cache +/composer.lock diff --git a/Makefile b/Makefile index 43345c2..f91d3b0 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,23 @@ +CSFIX_PHP_BIN=PHP_CS_FIXER_IGNORE_ENV=1 php8.2 +PHP_BIN=php8.2 -d zend.assertions=1 -d error_reporting=-1 +COMPOSER_BIN=$(shell command -v composer) + all: csfix static-analysis test @echo "Done." vendor: composer.json - composer update - composer bump + $(PHP_BIN) $(COMPOSER_BIN) update + $(PHP_BIN) $(COMPOSER_BIN) bump touch vendor .PHONY: csfix csfix: vendor - vendor/bin/php-cs-fixer fix --verbose + $(CSFIX_PHP_BIN) vendor/bin/php-cs-fixer fix -v .PHONY: static-analysis static-analysis: vendor - php -d zend.assertions=1 vendor/bin/phpstan analyse + $(PHP_BIN) vendor/bin/phpstan analyse $(PHPSTAN_ARGS) .PHONY: test test: vendor - php -d zend.assertions=1 vendor/bin/phpunit + $(PHP_BIN) vendor/bin/phpunit $(PHPUNIT_ARGS) diff --git a/README.md b/README.md index 0209337..f1f26c4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Latest Stable Version](https://img.shields.io/packagist/v/slam/php-cs-fixer-extensions.svg)](https://packagist.org/packages/slam/php-cs-fixer-extensions) [![Downloads](https://img.shields.io/packagist/dt/slam/php-cs-fixer-extensions.svg)](https://packagist.org/packages/slam/php-cs-fixer-extensions) -[![Integrate](https://github.com/Slamdunk/php-cs-fixer-extensions/workflows/Integrate/badge.svg?branch=master)](https://github.com/Slamdunk/php-cs-fixer-extensions/actions) +[![Integrate](https://github.com/Slamdunk/php-cs-fixer-extensions/workflows/CI/badge.svg?branch=master)](https://github.com/Slamdunk/php-cs-fixer-extensions/actions) [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) extensions and configurations diff --git a/composer.json b/composer.json index 1d7cf72..4c1dc4c 100644 --- a/composer.json +++ b/composer.json @@ -13,12 +13,12 @@ "php": "~8.1.0 || ~8.2.0", "ext-mbstring": "*", "ext-tokenizer": "*", - "friendsofphp/php-cs-fixer": "^3.13.2" + "friendsofphp/php-cs-fixer": "^3.14.4" }, "require-dev": { - "phpstan/phpstan": "^1.9.6", - "phpstan/phpstan-phpunit": "^1.3.3", - "phpunit/phpunit": "^9.5.27", + "phpstan/phpstan": "^1.10.1", + "phpstan/phpstan-phpunit": "^1.3.7", + "phpunit/phpunit": "^10.0.11", "slam/php-debug-r": "^1.7.0", "slam/phpstan-extensions": "^6.0.0" }, diff --git a/lib/Config.php b/lib/Config.php index 3fba633..1ace133 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -57,6 +57,7 @@ final class Config extends PhpCsFixerConfig 'nullable_type_declaration_for_default_null_value' => true, 'ordered_class_elements' => ['order' => ['use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property', 'construct', 'destruct', 'magic', 'phpunit', 'method']], 'ordered_interfaces' => true, + 'php_unit_data_provider_static' => true, 'php_unit_internal_class' => false, 'php_unit_size_class' => false, 'php_unit_strict' => false, diff --git a/phpunit.xml b/phpunit.xml index d7cae63..abb1d34 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,9 +2,8 @@ diff --git a/tests/AbstractFixerTestCase.php b/tests/AbstractFixerTestCase.php index 0af5397..720566c 100644 --- a/tests/AbstractFixerTestCase.php +++ b/tests/AbstractFixerTestCase.php @@ -33,12 +33,7 @@ final protected function createFixer() return new $fixerClass(); } - /** - * @param string $filename - * - * @return SplFileInfo - */ - final protected function getTestFile($filename = __FILE__) + final protected function getTestFile(string $filename = __FILE__): SplFileInfo { static $files = []; @@ -58,12 +53,8 @@ final protected function getTestFile($filename = __FILE__) * as the latter covers both of them. * This method throws an exception if $expected and $input are equal to prevent test cases that accidentally do * not test anything. - * - * @param string $expected The expected fixer output - * @param null|string $input The fixer input, or null if it should intentionally be equal to the output - * @param null|SplFileInfo $file The file to fix, or null if unneeded */ - final protected function doTest($expected, $input = null, ?SplFileInfo $file = null): void + final protected function doTest(string $expected, ?string $input = null, ?SplFileInfo $file = null): void { if ($expected === $input) { throw new InvalidArgumentException('Input parameter must not be equal to expected parameter.'); @@ -123,12 +114,7 @@ final protected function doTest($expected, $input = null, ?SplFileInfo $file = n static::assertFalse($tokens->isChanged(), 'Tokens collection built on expected code must not be marked as changed after fixing.'); } - /** - * @param string $source - * - * @return null|string - */ - private function lintSource($source) + private function lintSource(string $source): ?string { try { $this->linter->lintSource($source)->check(); diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index fba3cc1..94b8ef9 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -10,13 +10,13 @@ use PhpCsFixer\FixerFactory; use PhpCsFixer\RuleSet\RuleSet; use PhpCsFixer\RuleSet\RuleSets; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; +use SlamCsFixer\AbstractFixer; use SlamCsFixer\Config; -/** - * @covers \SlamCsFixer\AbstractFixer - * @covers \SlamCsFixer\Config - */ +#[CoversClass(AbstractFixer::class)] +#[CoversClass(Config::class)] final class ConfigTest extends TestCase { public function testConfig(): void @@ -31,7 +31,6 @@ public function testAllRulesAreSpecifiedAndDifferentFromRuleSets(): void { $config = new Config(); - /** @var array $configRules */ $configRules = $config->getRules(); $ruleSet = new RuleSet($configRules); $rules = $ruleSet->getRules(); diff --git a/tests/FinalAbstractPublicFixerTest.php b/tests/FinalAbstractPublicFixerTest.php index df0a578..f5f7c2b 100644 --- a/tests/FinalAbstractPublicFixerTest.php +++ b/tests/FinalAbstractPublicFixerTest.php @@ -4,14 +4,14 @@ namespace SlamCsFixer\Tests; -/** - * @covers \SlamCsFixer\FinalAbstractPublicFixer - */ +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use SlamCsFixer\FinalAbstractPublicFixer; + +#[CoversClass(FinalAbstractPublicFixer::class)] final class FinalAbstractPublicFixerTest extends AbstractFixerTestCase { - /** - * @dataProvider provideCases - */ + #[DataProvider('provideCases')] public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); @@ -20,7 +20,7 @@ public function testFix(string $expected, ?string $input = null): void /** * @return string[][] */ - public function provideCases(): array + public static function provideCases(): array { $original = ' public $a1; @@ -41,13 +41,13 @@ private static function f6(){} $fixed = \str_replace('public function', 'final public function', $fixed); return [ - 'final-class' => [" [" [" [" [' [" [" [' [ - "doTest($expected, $input); @@ -20,7 +20,7 @@ public function testFix(string $expected, ?string $input = null): void /** * @return string[][] */ - public function provideCases(): array + public static function provideCases(): array { return [ [ diff --git a/tests/FunctionReferenceSpaceFixerTest.php b/tests/FunctionReferenceSpaceFixerTest.php index b01bc6c..762a69c 100644 --- a/tests/FunctionReferenceSpaceFixerTest.php +++ b/tests/FunctionReferenceSpaceFixerTest.php @@ -4,14 +4,14 @@ namespace SlamCsFixer\Tests; -/** - * @covers \SlamCsFixer\FunctionReferenceSpaceFixer - */ +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use SlamCsFixer\FunctionReferenceSpaceFixer; + +#[CoversClass(FunctionReferenceSpaceFixer::class)] final class FunctionReferenceSpaceFixerTest extends AbstractFixerTestCase { - /** - * @dataProvider provideCases - */ + #[DataProvider('provideCases')] public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); @@ -20,7 +20,7 @@ public function testFix(string $expected, ?string $input = null): void /** * @return string[][] */ - public function provideCases(): array + public static function provideCases(): array { $same = static function (string $content): string { $use = $content; diff --git a/tests/InlineCommentSpacerFixerTest.php b/tests/InlineCommentSpacerFixerTest.php index 9e7b3bd..2407fbb 100644 --- a/tests/InlineCommentSpacerFixerTest.php +++ b/tests/InlineCommentSpacerFixerTest.php @@ -5,10 +5,11 @@ namespace SlamCsFixer\Tests; use PhpCsFixer\FixerDefinition\FixerDefinition; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use SlamCsFixer\InlineCommentSpacerFixer; -/** - * @covers \SlamCsFixer\InlineCommentSpacerFixer - */ +#[CoversClass(InlineCommentSpacerFixer::class)] final class InlineCommentSpacerFixerTest extends AbstractFixerTestCase { public function testDefinition(): void @@ -16,9 +17,7 @@ public function testDefinition(): void self::assertInstanceOf(FixerDefinition::class, $this->fixer->getDefinition()); } - /** - * @dataProvider provideCases - */ + #[DataProvider('provideCases')] public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); @@ -27,7 +26,7 @@ public function testFix(string $expected, ?string $input = null): void /** * @return string[][] */ - public function provideCases(): array + public static function provideCases(): array { return [ [ diff --git a/tests/PhpFileOnlyProxyFixerTest.php b/tests/PhpFileOnlyProxyFixerTest.php index 26ce989..e54099e 100644 --- a/tests/PhpFileOnlyProxyFixerTest.php +++ b/tests/PhpFileOnlyProxyFixerTest.php @@ -11,13 +11,12 @@ use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Tokens; use PhpCsFixer\WhitespacesFixerConfig; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use SlamCsFixer\PhpFileOnlyProxyFixer; use SplFileInfo; -/** - * @covers \SlamCsFixer\PhpFileOnlyProxyFixer - */ +#[CoversClass(PhpFileOnlyProxyFixer::class)] final class PhpFileOnlyProxyFixerTest extends TestCase { public function testFixerInterfaceProxy(): void diff --git a/tests/Utf8FixerTest.php b/tests/Utf8FixerTest.php index 5a7d168..7b8967d 100644 --- a/tests/Utf8FixerTest.php +++ b/tests/Utf8FixerTest.php @@ -4,9 +4,10 @@ namespace SlamCsFixer\Tests; -/** - * @covers \SlamCsFixer\Utf8Fixer - */ +use PHPUnit\Framework\Attributes\CoversClass; +use SlamCsFixer\Utf8Fixer; + +#[CoversClass(Utf8Fixer::class)] final class Utf8FixerTest extends AbstractFixerTestCase { public function testFix(): void