Skip to content

Commit 2eb2fd2

Browse files
authored
Add test for StmtsAwareInterface (#4)
* Add test for StmtsAwareInterface * update order * flip stable and dev * make individual run between phpstan and rector * early run * early run * set home runner for global test * roll * rollback to original tests definition
1 parent 69a346e commit 2eb2fd2

File tree

6 files changed

+155
-15
lines changed

6 files changed

+155
-15
lines changed

.github/workflows/compat_tests_global.yaml.yml renamed to .github/workflows/compat_tests_global_phpstan.yaml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Compat Tests for global install
1+
name: Compat Tests for global install for PHPStan
22

33
on:
44
pull_request: null
@@ -13,19 +13,13 @@ jobs:
1313
matrix:
1414
actions:
1515
-
16-
name: 'Rector dev + PHPUnit 12 global install'
17-
run: |
18-
composer remove --dev phpunit/phpunit -W
19-
composer global require --dev "phpunit/phpunit:12.*" -W
20-
composer require --dev "rector/rector:dev-main" -W
16+
name: 'Rector stable + PHPUnit 12 global for PHPStan'
17+
run: composer require --dev "rector/rector:^2.2" -W
2118
php: 8.3
2219

2320
-
24-
name: 'Rector stable + PHPUnit 12 global install'
25-
run: |
26-
composer remove --dev phpunit/phpunit -W
27-
composer global require --dev "phpunit/phpunit:12.*" -W
28-
composer require --dev "rector/rector:^2.2" -W
21+
name: 'Rector dev + PHPUnit 12 global for PHPStan'
22+
run: composer require --dev "rector/rector:dev-main" -W
2923
php: 8.3
3024

3125
name: ${{ matrix.actions.name }}
@@ -42,10 +36,12 @@ jobs:
4236
coverage: none
4337

4438
- uses: "ramsey/composer-install@v2"
45-
- run: ${{ matrix.actions.run }}
4639

47-
- run: phpunit tests/PHPStan
40+
- run: composer remove --dev phpunit/phpunit -W
41+
- run: composer global require --dev "phpunit/phpunit:12.*" -W
42+
43+
- run: ${{ matrix.actions.run }}
4844

49-
- run: phpunit tests/Rector
45+
- run: /home/runner/.composer/vendor/bin/phpunit tests/PHPStan
5046

51-
- run: phpunit
47+
- run: /home/runner/.composer/vendor/bin/phpunit
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Compat Tests for global install for Rector
2+
3+
on:
4+
pull_request: null
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
compat_tests:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
actions:
15+
-
16+
name: 'Rector stable + PHPUnit 12 global for Rector'
17+
run: composer require --dev "rector/rector:^2.2" -W
18+
php: 8.3
19+
20+
-
21+
name: 'Rector dev + PHPUnit 12 global for Rector'
22+
run: composer require --dev "rector/rector:dev-main" -W
23+
php: 8.3
24+
25+
name: ${{ matrix.actions.name }}
26+
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
-
33+
uses: shivammathur/setup-php@v2
34+
with:
35+
php-version: ${{ matrix.actions.php }}
36+
coverage: none
37+
38+
- uses: "ramsey/composer-install@v2"
39+
40+
- run: composer remove --dev phpunit/phpunit -W
41+
- run: composer global require --dev "phpunit/phpunit:12.*" -W
42+
43+
- run: ${{ matrix.actions.run }}
44+
45+
- run: /home/runner/.composer/vendor/bin/phpunit tests/Rector
46+
47+
- run: /home/runner/.composer/vendor/bin/phpunit
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\RectorCompatTests\Rector;
6+
7+
use PhpParser\Node;
8+
use PhpParser\Node\Stmt\Class_;
9+
use PhpParser\Node\Stmt\If_;
10+
use PhpParser\Node\Stmt\Nop;
11+
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
12+
use Rector\Rector\AbstractRector;
13+
14+
final class MakeNewlineAfterIfRector extends AbstractRector
15+
{
16+
/**
17+
* @return array<class-string<Class_>>
18+
*/
19+
public function getNodeTypes(): array
20+
{
21+
return [StmtsAwareInterface::class];
22+
}
23+
24+
/**
25+
* @param StmtsAwareInterface $node
26+
* @return array<Node>|null
27+
*/
28+
public function refactor(Node $node): ?array
29+
{
30+
if (! $node instanceof If_) {
31+
return null;
32+
}
33+
34+
return [$node, new Nop()];
35+
}
36+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Rector\RectorCompatTests\Tests\Rector\MakeClassFinalRector\Fixture;
4+
5+
class SomeIf
6+
{
7+
public function run()
8+
{
9+
if (true) {
10+
echo 'test';
11+
}
12+
echo 'done';
13+
}
14+
}
15+
16+
?>
17+
-----
18+
<?php
19+
20+
namespace Rector\RectorCompatTests\Tests\Rector\MakeClassFinalRector\Fixture;
21+
22+
class SomeIf
23+
{
24+
public function run()
25+
{
26+
if (true) {
27+
echo 'test';
28+
}
29+
30+
echo 'done';
31+
}
32+
}
33+
34+
?>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\RectorCompatTests\Tests\Rector\MakeNewlineAfterIf;
4+
5+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
6+
7+
final class MakeNewlineAfterIfTest extends AbstractRectorTestCase
8+
{
9+
public function test(): void
10+
{
11+
$this->doTestFile(__DIR__ . '/Fixture/some_if.php.inc');
12+
}
13+
14+
public function provideConfigFilePath(): string
15+
{
16+
return __DIR__ . '/config/configured_rule.php';
17+
}
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\RectorCompatTests\Rector\MakeNewlineAfterIfRector;
7+
8+
return RectorConfig::configure()
9+
->withRules([MakeNewlineAfterIfRector::class]);

0 commit comments

Comments
 (0)