From cf2c77e156ee4d4d917ab047f08ba206c6bb46d5 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 30 May 2025 23:33:01 +0200 Subject: [PATCH 1/7] Install Rector to help migrate toward PHPUnit 10+ --- composer.json | 3 ++- rector.php | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index 77a95e3..dffd1ba 100644 --- a/composer.json +++ b/composer.json @@ -36,11 +36,12 @@ "require-dev": { "facile-it/facile-coding-standard": "^1.2", "jangregor/phpstan-prophecy": "2.2.0", + "phpspec/prophecy-phpunit": "^2.0", "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "2.1.17", "phpstan/phpstan-phpunit": "2.0.6", "phpunit/phpunit": "^9.6.6", - "phpspec/prophecy-phpunit": "^2.0", + "rector/rector": "2.0.17", "symfony/phpunit-bridge": "^6.4 || ^7.0", "vimeo/psalm": "^4.6 || ^5.0" } diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..c5099f8 --- /dev/null +++ b/rector.php @@ -0,0 +1,20 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + // uncomment to reach your current PHP version + // ->withPhpSets() + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0) + ->withSets([ + \Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100, + ]) +; From 7c8d0b1d515895d07bb885e776e9453da30a605a Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 30 May 2025 23:34:22 +0200 Subject: [PATCH 2/7] Apply Rector PHPUnit 10 set --- tests/E2E/TerminateCommandTest.php | 4 ++-- tests/Unit/AbstractTerminableCommandTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/E2E/TerminateCommandTest.php b/tests/E2E/TerminateCommandTest.php index 9509ce1..6fe7a99 100644 --- a/tests/E2E/TerminateCommandTest.php +++ b/tests/E2E/TerminateCommandTest.php @@ -37,7 +37,7 @@ public function testStubCommand(array $commandLine): void /** * @return string[][][] */ - public function commandLineProvider(): array + public static function commandLineProvider(): array { return [ [ @@ -119,7 +119,7 @@ public function testSigTermDuringSleep(int $signal, int $exitCode): void /** * @return array */ - public function provideSignals(): array + public static function provideSignals(): array { return [ [SIGTERM, 143], diff --git a/tests/Unit/AbstractTerminableCommandTest.php b/tests/Unit/AbstractTerminableCommandTest.php index 04239ca..373e894 100644 --- a/tests/Unit/AbstractTerminableCommandTest.php +++ b/tests/Unit/AbstractTerminableCommandTest.php @@ -122,7 +122,7 @@ public function testReceiveSignalBeforeCommandBody(int $signal): void $output = $this->prophesize(OutputInterface::class); $output->writeln(Argument::containingString('Starting'), OutputInterface::VERBOSITY_VERBOSE) ->shouldBeCalledTimes(1) - ->will(function () use ($stubCommand, $signal) { + ->will(function () use ($stubCommand, $signal): void { $stubCommand->handleSignal($signal); }); $output->writeln('Signal received, skipping execution', OutputInterface::VERBOSITY_NORMAL) @@ -146,7 +146,7 @@ public function testGetSubscribedSignals(int $signal): void /** * @return array{0: int}[] */ - public function signalProvider(): array + public static function signalProvider(): array { return [ [SIGINT], From acb6b62bafe0e9551f2bb17e9030fc1dc392ab34 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 30 May 2025 23:39:45 +0200 Subject: [PATCH 3/7] Upgrade to both PHPUnit 10+ & Psalm 6 --- Makefile | 2 +- composer.json | 4 ++-- psalm-baseline.xml | 8 ++++++++ psalm.xml | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 psalm-baseline.xml diff --git a/Makefile b/Makefile index d95d22b..07e6bb3 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,6 @@ phpstan: vendor/bin/phpstan analyse tests: - vendor/bin/phpunit --verbose + vendor/bin/phpunit .PHONY: tests diff --git a/composer.json b/composer.json index dffd1ba..24a735b 100644 --- a/composer.json +++ b/composer.json @@ -40,9 +40,9 @@ "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "2.1.17", "phpstan/phpstan-phpunit": "2.0.6", - "phpunit/phpunit": "^9.6.6", + "phpunit/phpunit": "^10 || ^11 || ^12", "rector/rector": "2.0.17", "symfony/phpunit-bridge": "^6.4 || ^7.0", - "vimeo/psalm": "^4.6 || ^5.0" + "vimeo/psalm": "^6" } } diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 0000000..2724264 --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/psalm.xml b/psalm.xml index 2dc2301..ed45698 100644 --- a/psalm.xml +++ b/psalm.xml @@ -5,6 +5,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" + errorBaseline="psalm-baseline.xml" > @@ -12,4 +13,7 @@ + + + From 4962563d7f06b5f88b10fa1b9b8ce3d467254416 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 30 May 2025 23:42:01 +0200 Subject: [PATCH 4/7] Migrate to PHPUnit attributes --- rector.php | 1 + tests/E2E/TerminateCommandTest.php | 11 +++-------- tests/Unit/AbstractTerminableCommandTest.php | 12 +++--------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/rector.php b/rector.php index c5099f8..f8859fa 100644 --- a/rector.php +++ b/rector.php @@ -14,6 +14,7 @@ ->withTypeCoverageLevel(0) ->withDeadCodeLevel(0) ->withCodeQualityLevel(0) + ->withAttributesSets(phpunit: true) ->withSets([ \Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100, ]) diff --git a/tests/E2E/TerminateCommandTest.php b/tests/E2E/TerminateCommandTest.php index 6fe7a99..0035910 100644 --- a/tests/E2E/TerminateCommandTest.php +++ b/tests/E2E/TerminateCommandTest.php @@ -17,10 +17,9 @@ class TerminateCommandTest extends TestCase private const STUB_COMMAND = 'stub:terminable:sleep'; /** - * @dataProvider commandLineProvider - * * @param string[] $commandLine */ + #[\PHPUnit\Framework\Attributes\DataProvider('commandLineProvider')] public function testStubCommand(array $commandLine): void { $process = new Process($commandLine); @@ -58,9 +57,7 @@ public static function commandLineProvider(): array ]; } - /** - * @dataProvider provideSignals - */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideSignals')] public function testSignalsDuringCommandBody(int $signal, int $exitCode): void { $process = new Process([ @@ -87,9 +84,7 @@ public function testSignalsDuringCommandBody(int $signal, int $exitCode): void $this->assertSame($exitCode, $process->getExitCode()); } - /** - * @dataProvider provideSignals - */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideSignals')] public function testSigTermDuringSleep(int $signal, int $exitCode): void { $process = new Process([ diff --git a/tests/Unit/AbstractTerminableCommandTest.php b/tests/Unit/AbstractTerminableCommandTest.php index 373e894..8a8b429 100644 --- a/tests/Unit/AbstractTerminableCommandTest.php +++ b/tests/Unit/AbstractTerminableCommandTest.php @@ -78,9 +78,7 @@ protected function commandBody(InputInterface $input, OutputInterface $output): $stubCommand->run(new ArrayInput([]), $output->reveal()); } - /** - * @dataProvider signalProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('signalProvider')] public function testReceiveSignalDuringCommandBody(int $signal): void { $stubCommand = new class ($signal) extends AbstractTerminableCommand { @@ -112,9 +110,7 @@ protected function commandBody(InputInterface $input, OutputInterface $output): $this->assertSame(143, $exitCode); } - /** - * @dataProvider signalProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('signalProvider')] public function testReceiveSignalBeforeCommandBody(int $signal): void { $stubCommand = $this->createStubTerminableCommand(); @@ -133,9 +129,7 @@ public function testReceiveSignalBeforeCommandBody(int $signal): void $this->assertSame(143, $exitCode); } - /** - * @dataProvider signalProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('signalProvider')] public function testGetSubscribedSignals(int $signal): void { $stubCommand = $this->createStubTerminableCommand(); From 09c56955c1212c9929bba03ed25b6938a18bac50 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 30 May 2025 23:45:07 +0200 Subject: [PATCH 5/7] Upgrade PHPUnit config --- phpunit.xml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 423615a..a303a29 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,22 +1,22 @@ - + displayDetailsOnPhpunitDeprecations="true" + displayDetailsOnTestsThatTriggerDeprecations="true" + cacheDirectory=".phpunit.cache"> tests - - + src - + From fcb353bc8e20a870cdacb622e77bc5e81ece0d8b Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 30 May 2025 23:47:53 +0200 Subject: [PATCH 6/7] Run Rector in CI --- .github/workflows/static-analysis.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 8f724cb..e657431 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -17,6 +17,8 @@ jobs: script: composer validate - description: Code style script: vendor/bin/php-cs-fixer fix --ansi --verbose --dry-run + - description: Rector + script: vendor/bin/rector --ansi --dry-run - description: PHPStan script: vendor/bin/phpstan analyze - description: Psalm From b80e8d016169275202ec4fcec47f72e1c963939c Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 30 May 2025 23:54:56 +0200 Subject: [PATCH 7/7] Consolidate CI processes --- .github/workflows/{tests.yaml => ci.yaml} | 34 +++++++++++++++++--- .github/workflows/static-analysis.yaml | 38 ----------------------- 2 files changed, 30 insertions(+), 42 deletions(-) rename .github/workflows/{tests.yaml => ci.yaml} (60%) delete mode 100644 .github/workflows/static-analysis.yaml diff --git a/.github/workflows/tests.yaml b/.github/workflows/ci.yaml similarity index 60% rename from .github/workflows/tests.yaml rename to .github/workflows/ci.yaml index 2b0245f..d08ca06 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: Tests +name: CI on: pull_request: null @@ -10,7 +10,7 @@ on: jobs: Tests: - name: PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}${{ matrix.dependencies }} + name: PHP ${{ matrix.php }} Symfony ${{ matrix.symfony }}${{ matrix.description }} runs-on: ubuntu-latest env: SYMFONY_DEPRECATIONS_HELPER: 'max[self]=0' @@ -26,8 +26,7 @@ jobs: php: '8.3' - symfony: '^6.4' php: '8.2' - - description: 'Prefer lowest' - php: '8.2' + - php: '8.2' dependencies: '--prefer-lowest' env: SYMFONY_DEPRECATIONS_HELPER: 'disabled' @@ -57,3 +56,30 @@ jobs: files: './coverage.xml' fail_ci_if_error: true token: ${{ secrets.CODECOV_TOKEN }} + SA: + strategy: + matrix: + include: + - description: Validate composer.json + script: composer validate + - description: Code style + script: vendor/bin/php-cs-fixer fix --ansi --verbose --dry-run + - description: Rector + script: vendor/bin/rector --ansi --dry-run + - description: PHPStan + script: vendor/bin/phpstan analyze + - description: Psalm + script: vendor/bin/psalm + + name: ${{ matrix.description }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + - name: Install dependencies + uses: "ramsey/composer-install@v3" + - run: ${{ matrix.script }} diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml deleted file mode 100644 index e657431..0000000 --- a/.github/workflows/static-analysis.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: Static analysis - -on: - pull_request: ~ - push: - branches: - - master - schedule: - - cron: "45 7 * * 1" - -jobs: - job: - strategy: - matrix: - include: - - description: Validate composer.json - script: composer validate - - description: Code style - script: vendor/bin/php-cs-fixer fix --ansi --verbose --dry-run - - description: Rector - script: vendor/bin/rector --ansi --dry-run - - description: PHPStan - script: vendor/bin/phpstan analyze - - description: Psalm - script: vendor/bin/psalm - - name: ${{ matrix.description }} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - - name: Install dependencies - uses: "ramsey/composer-install@v3" - - run: ${{ matrix.script }}