Skip to content

Commit

Permalink
[e2e] Add e2e for tests removed node display applied rules with retur…
Browse files Browse the repository at this point in the history
…n null (#2320)

* [e2e] Add e2e for tests removed node display applied rules with return null

* update
  • Loading branch information
samsonasik committed May 16, 2022
1 parent 91ffbbb commit c0086b7
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
- 'e2e/plain-views'
- 'e2e/template-extends'
- 'e2e/use-rector-configurator'
- 'e2e/applied-rule-removed-node'

name: End to end test - ${{ matrix.directory }}

Expand Down
1 change: 1 addition & 0 deletions e2e/applied-rule-removed-node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
7 changes: 7 additions & 0 deletions e2e/applied-rule-removed-node/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require": {
"php": "^8.1"
},
"minimum-stability": "dev",
"prefer-stable": true
}
40 changes: 40 additions & 0 deletions e2e/applied-rule-removed-node/expected-output.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
2 files with changes
====================

1) src/DeadConstructor.php:1

---------- begin diff ----------
@@ @@

final class DeadConstructor
{
- public function __construct()
- {
- }
}
----------- end diff -----------

Applied rules:
* RemoveDeadConstructorRector


2) src/AlwaysTrue.php:3

---------- begin diff ----------
@@ @@
{
public function run()
{
- if (1 === 1) {
- }
-
return 'no';
}
}
----------- end diff -----------

Applied rules:
* RemoveAlwaysTrueIfConditionRector


[OK] 2 files would have changed (dry-run) by Rector
16 changes: 16 additions & 0 deletions e2e/applied-rule-removed-node/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector;
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
]);

$rectorConfig->rule(RemoveDeadConstructorRector::class);
$rectorConfig->rule(RemoveAlwaysTrueIfConditionRector::class);
};
12 changes: 12 additions & 0 deletions e2e/applied-rule-removed-node/src/AlwaysTrue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

final class AlwaysTrue
{
public function run()
{
if (1 === 1) {
}

return 'no';
}
}
8 changes: 8 additions & 0 deletions e2e/applied-rule-removed-node/src/DeadConstructor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

final class DeadConstructor
{
public function __construct()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public function refactor(Node $node): If_|null|array

if ($node->stmts === []) {
$this->removeNode($node);
// needed to apply removeNode(), @todo fix in AbstractRector itself
return $node;
return null;
}

return $node->stmts;
Expand Down

0 comments on commit c0086b7

Please sign in to comment.