From f80962453866020bd9bed7eacb56681f56210078 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 18:18:47 +0700 Subject: [PATCH 1/9] Add test for StmtsAwareInterface --- src/Rector/MakeNewlineAfterIfRector.php | 36 +++++++++++++++++++ .../Fixture/some_if.php.inc | 34 ++++++++++++++++++ .../MakeNewlineAfterIfTest.php | 18 ++++++++++ .../config/configured_rule.php | 9 +++++ 4 files changed, 97 insertions(+) create mode 100644 src/Rector/MakeNewlineAfterIfRector.php create mode 100644 tests/Rector/MakeNewlineAfterIf/Fixture/some_if.php.inc create mode 100644 tests/Rector/MakeNewlineAfterIf/MakeNewlineAfterIfTest.php create mode 100644 tests/Rector/MakeNewlineAfterIf/config/configured_rule.php diff --git a/src/Rector/MakeNewlineAfterIfRector.php b/src/Rector/MakeNewlineAfterIfRector.php new file mode 100644 index 0000000..8dfea09 --- /dev/null +++ b/src/Rector/MakeNewlineAfterIfRector.php @@ -0,0 +1,36 @@ +> + */ + public function getNodeTypes(): array + { + return [StmtsAwareInterface::class]; + } + + /** + * @param StmtsAwareInterface $node + * @return array|null + */ + public function refactor(Node $node): ?array + { + if (! $node instanceof If_) { + return null; + } + + return [$node, new Nop()]; + } +} diff --git a/tests/Rector/MakeNewlineAfterIf/Fixture/some_if.php.inc b/tests/Rector/MakeNewlineAfterIf/Fixture/some_if.php.inc new file mode 100644 index 0000000..c75675f --- /dev/null +++ b/tests/Rector/MakeNewlineAfterIf/Fixture/some_if.php.inc @@ -0,0 +1,34 @@ + +----- + diff --git a/tests/Rector/MakeNewlineAfterIf/MakeNewlineAfterIfTest.php b/tests/Rector/MakeNewlineAfterIf/MakeNewlineAfterIfTest.php new file mode 100644 index 0000000..5927b81 --- /dev/null +++ b/tests/Rector/MakeNewlineAfterIf/MakeNewlineAfterIfTest.php @@ -0,0 +1,18 @@ +doTestFile(__DIR__ . '/Fixture/some_if.php.inc'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Rector/MakeNewlineAfterIf/config/configured_rule.php b/tests/Rector/MakeNewlineAfterIf/config/configured_rule.php new file mode 100644 index 0000000..a93633c --- /dev/null +++ b/tests/Rector/MakeNewlineAfterIf/config/configured_rule.php @@ -0,0 +1,9 @@ +withRules([MakeNewlineAfterIfRector::class]); From 04b22c733ea1e6a16fc1acad3c0d94047f80743b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 19:08:13 +0700 Subject: [PATCH 2/9] update order --- phpunit.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index dc8c3bf..e6c154c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,8 @@ > - tests + tests/Rector + tests/PHPStan From 918656c66f4cd645992fd59ae48fc7fbbdbbef81 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 19:34:17 +0700 Subject: [PATCH 3/9] flip stable and dev --- .github/workflows/compat_tests_global.yaml.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compat_tests_global.yaml.yml b/.github/workflows/compat_tests_global.yaml.yml index e14d0f9..cf3d3b4 100644 --- a/.github/workflows/compat_tests_global.yaml.yml +++ b/.github/workflows/compat_tests_global.yaml.yml @@ -13,19 +13,19 @@ jobs: matrix: actions: - - name: 'Rector dev + PHPUnit 12 global install' + name: 'Rector stable + PHPUnit 12 global install' run: | composer remove --dev phpunit/phpunit -W composer global require --dev "phpunit/phpunit:12.*" -W - composer require --dev "rector/rector:dev-main" -W + composer require --dev "rector/rector:^2.2" -W php: 8.3 - - name: 'Rector stable + PHPUnit 12 global install' + name: 'Rector dev + PHPUnit 12 global install' run: | composer remove --dev phpunit/phpunit -W composer global require --dev "phpunit/phpunit:12.*" -W - composer require --dev "rector/rector:^2.2" -W + composer require --dev "rector/rector:dev-main" -W php: 8.3 name: ${{ matrix.actions.name }} From 03d7e974a587d1a4ddb7fa29053148997b046768 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 19:38:32 +0700 Subject: [PATCH 4/9] make individual run between phpstan and rector --- ...l.yml => compat_tests_global_phpstan.yaml} | 4 +- .../workflows/compat_tests_global_rector.yaml | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) rename .github/workflows/{compat_tests_global.yaml.yml => compat_tests_global_phpstan.yaml} (94%) create mode 100644 .github/workflows/compat_tests_global_rector.yaml diff --git a/.github/workflows/compat_tests_global.yaml.yml b/.github/workflows/compat_tests_global_phpstan.yaml similarity index 94% rename from .github/workflows/compat_tests_global.yaml.yml rename to .github/workflows/compat_tests_global_phpstan.yaml index cf3d3b4..6835f1d 100644 --- a/.github/workflows/compat_tests_global.yaml.yml +++ b/.github/workflows/compat_tests_global_phpstan.yaml @@ -1,4 +1,4 @@ -name: Compat Tests for global install +name: Compat Tests for global install for PHPStan on: pull_request: null @@ -46,6 +46,4 @@ jobs: - run: phpunit tests/PHPStan - - run: phpunit tests/Rector - - run: phpunit diff --git a/.github/workflows/compat_tests_global_rector.yaml b/.github/workflows/compat_tests_global_rector.yaml new file mode 100644 index 0000000..a0fbf5a --- /dev/null +++ b/.github/workflows/compat_tests_global_rector.yaml @@ -0,0 +1,49 @@ +name: Compat Tests for global install for Rector + +on: + pull_request: null + push: + branches: + - main + +jobs: + compat_tests: + strategy: + fail-fast: false + matrix: + actions: + - + name: 'Rector stable + PHPUnit 12 global install' + run: | + composer remove --dev phpunit/phpunit -W + composer global require --dev "phpunit/phpunit:12.*" -W + composer require --dev "rector/rector:^2.2" -W + php: 8.3 + + - + name: 'Rector dev + PHPUnit 12 global install' + run: | + composer remove --dev phpunit/phpunit -W + composer global require --dev "phpunit/phpunit:12.*" -W + composer require --dev "rector/rector:dev-main" -W + php: 8.3 + + name: ${{ matrix.actions.name }} + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.actions.php }} + coverage: none + + - uses: "ramsey/composer-install@v2" + - run: ${{ matrix.actions.run }} + + - run: phpunit tests/Rector + + - run: phpunit From 116995046af26dd064615068e791e30c2d47ad45 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 19:48:27 +0700 Subject: [PATCH 5/9] early run --- .../workflows/compat_tests_global_phpstan.yaml | 18 ++++++++---------- .../workflows/compat_tests_global_rector.yaml | 18 ++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/.github/workflows/compat_tests_global_phpstan.yaml b/.github/workflows/compat_tests_global_phpstan.yaml index 6835f1d..fdccb23 100644 --- a/.github/workflows/compat_tests_global_phpstan.yaml +++ b/.github/workflows/compat_tests_global_phpstan.yaml @@ -13,19 +13,13 @@ jobs: matrix: actions: - - name: 'Rector stable + PHPUnit 12 global install' - run: | - composer remove --dev phpunit/phpunit -W - composer global require --dev "phpunit/phpunit:12.*" -W - composer require --dev "rector/rector:^2.2" -W + name: 'Rector stable + PHPUnit 12 global' + run: composer require --dev "rector/rector:^2.2" -W php: 8.3 - - name: 'Rector dev + PHPUnit 12 global install' - run: | - composer remove --dev phpunit/phpunit -W - composer global require --dev "phpunit/phpunit:12.*" -W - composer require --dev "rector/rector:dev-main" -W + name: 'Rector dev + PHPUnit 12 global' + run: composer require --dev "rector/rector:dev-main" -W php: 8.3 name: ${{ matrix.actions.name }} @@ -42,6 +36,10 @@ jobs: coverage: none - uses: "ramsey/composer-install@v2" + + - run: composer remove --dev phpunit/phpunit -W + - run: composer global require --dev "phpunit/phpunit:12.*" -W + - run: ${{ matrix.actions.run }} - run: phpunit tests/PHPStan diff --git a/.github/workflows/compat_tests_global_rector.yaml b/.github/workflows/compat_tests_global_rector.yaml index a0fbf5a..4f2edfa 100644 --- a/.github/workflows/compat_tests_global_rector.yaml +++ b/.github/workflows/compat_tests_global_rector.yaml @@ -13,19 +13,13 @@ jobs: matrix: actions: - - name: 'Rector stable + PHPUnit 12 global install' - run: | - composer remove --dev phpunit/phpunit -W - composer global require --dev "phpunit/phpunit:12.*" -W - composer require --dev "rector/rector:^2.2" -W + name: 'Rector stable + PHPUnit 12 global' + run: composer require --dev "rector/rector:^2.2" -W php: 8.3 - - name: 'Rector dev + PHPUnit 12 global install' - run: | - composer remove --dev phpunit/phpunit -W - composer global require --dev "phpunit/phpunit:12.*" -W - composer require --dev "rector/rector:dev-main" -W + name: 'Rector dev + PHPUnit 12 global' + run: composer require --dev "rector/rector:dev-main" -W php: 8.3 name: ${{ matrix.actions.name }} @@ -42,6 +36,10 @@ jobs: coverage: none - uses: "ramsey/composer-install@v2" + + - run: composer remove --dev phpunit/phpunit -W + - run: composer global require --dev "phpunit/phpunit:12.*" -W + - run: ${{ matrix.actions.run }} - run: phpunit tests/Rector From 0ac02303d5f5cc2cba417a24e033b9cf4d71719e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 19:49:39 +0700 Subject: [PATCH 6/9] early run --- .github/workflows/compat_tests_global_phpstan.yaml | 4 ++-- .github/workflows/compat_tests_global_rector.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compat_tests_global_phpstan.yaml b/.github/workflows/compat_tests_global_phpstan.yaml index fdccb23..0859b9e 100644 --- a/.github/workflows/compat_tests_global_phpstan.yaml +++ b/.github/workflows/compat_tests_global_phpstan.yaml @@ -13,12 +13,12 @@ jobs: matrix: actions: - - name: 'Rector stable + PHPUnit 12 global' + name: 'Rector stable + PHPUnit 12 global for PHPStan' run: composer require --dev "rector/rector:^2.2" -W php: 8.3 - - name: 'Rector dev + PHPUnit 12 global' + name: 'Rector dev + PHPUnit 12 global for PHPStan' run: composer require --dev "rector/rector:dev-main" -W php: 8.3 diff --git a/.github/workflows/compat_tests_global_rector.yaml b/.github/workflows/compat_tests_global_rector.yaml index 4f2edfa..2a0a7cd 100644 --- a/.github/workflows/compat_tests_global_rector.yaml +++ b/.github/workflows/compat_tests_global_rector.yaml @@ -13,12 +13,12 @@ jobs: matrix: actions: - - name: 'Rector stable + PHPUnit 12 global' + name: 'Rector stable + PHPUnit 12 global for Rector' run: composer require --dev "rector/rector:^2.2" -W php: 8.3 - - name: 'Rector dev + PHPUnit 12 global' + name: 'Rector dev + PHPUnit 12 global for Rector' run: composer require --dev "rector/rector:dev-main" -W php: 8.3 From d998691ad1731812c859288d7dfd26724db980f4 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 19:52:15 +0700 Subject: [PATCH 7/9] set home runner for global test --- .github/workflows/compat_tests_global_phpstan.yaml | 4 ++-- .github/workflows/compat_tests_global_rector.yaml | 4 ++-- composer.json | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/compat_tests_global_phpstan.yaml b/.github/workflows/compat_tests_global_phpstan.yaml index 0859b9e..ef449ff 100644 --- a/.github/workflows/compat_tests_global_phpstan.yaml +++ b/.github/workflows/compat_tests_global_phpstan.yaml @@ -42,6 +42,6 @@ jobs: - run: ${{ matrix.actions.run }} - - run: phpunit tests/PHPStan + - run: /home/runner/.composer/vendor/bin/phpunit tests/PHPStan - - run: phpunit + - run: /home/runner/.composer/vendor/bin/phpunit diff --git a/.github/workflows/compat_tests_global_rector.yaml b/.github/workflows/compat_tests_global_rector.yaml index 2a0a7cd..bf3454a 100644 --- a/.github/workflows/compat_tests_global_rector.yaml +++ b/.github/workflows/compat_tests_global_rector.yaml @@ -42,6 +42,6 @@ jobs: - run: ${{ matrix.actions.run }} - - run: phpunit tests/Rector + - run: /home/runner/.composer/vendor/bin/phpunit tests/Rector - - run: phpunit + - run: /home/runner/.composer/vendor/bin/phpunit diff --git a/composer.json b/composer.json index 1aa3e32..eb71f8c 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,6 @@ "description": "Tests for compatibility with PHPStand and PHPUnit preload magic", "require-dev": { "php": "^8.2", - "phpunit/phpunit": "10.*|11.*|12.*", "rector/rector": "dev-main", "phpstan/phpstan": "^2.1" }, From d388412a8094a9d5b595d76ca6137b84e3034de2 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 19:56:20 +0700 Subject: [PATCH 8/9] roll --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index eb71f8c..1aa3e32 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,7 @@ "description": "Tests for compatibility with PHPStand and PHPUnit preload magic", "require-dev": { "php": "^8.2", + "phpunit/phpunit": "10.*|11.*|12.*", "rector/rector": "dev-main", "phpstan/phpstan": "^2.1" }, From 98501814dba395944560a7d8a2dbd9d77cd5baed Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 21:05:00 +0700 Subject: [PATCH 9/9] rollback to original tests definition --- phpunit.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index e6c154c..dc8c3bf 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,8 +8,7 @@ > - tests/Rector - tests/PHPStan + tests