Skip to content

Commit 6cb502d

Browse files
committed
add test
1 parent 2869153 commit 6cb502d

10 files changed

Lines changed: 250 additions & 35 deletions

File tree

composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
"doctrine/inflector": "^2.1",
2121
"illuminate/container": "^11.46",
2222
"nette/utils": "^4.0",
23-
<<<<<<< HEAD
2423
"nikic/php-parser": "^5.6.2",
25-
=======
26-
"nikic/php-parser": "5.6.1",
27-
>>>>>>> 2a1a5105ab (lock php parser to 5.6.1 to avoid breaking space on attributes)
2824
"ondram/ci-detector": "^4.2",
2925
"phpstan/phpdoc-parser": "^2.3",
3026
"phpstan/phpstan": "^2.1.26",
@@ -85,6 +81,7 @@
8581
"rules-tests",
8682
"tests"
8783
],
84+
"Rector\\Utils\\Tests\\": "utils-tests",
8885
"E2e\\Parallel\\Reflection\\Resolver\\": [
8986
"e2e/parallel-reflection-resolver/src/",
9087
"e2e/no-parallel-reflection-resolver/src"

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,5 @@ parameters:
352352
-
353353
identifier: offsetAccess.invalidOffset
354354
path: src/CustomRules/SimpleNodeDumper.php
355+
356+
- '#Method Rector\\Utils\\Rector\\RemoveRefactorDuplicatedNodeInstanceCheckRector\:\:getInstanceofNodeClass\(\) should return class\-string<PhpParser\\Node>\|null but returns class\-string#'

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<testsuite name="main">
1414
<directory>tests</directory>
1515
<directory>rules-tests</directory>
16+
<directory>utils-tests</directory>
1617
</testsuite>
1718
</testsuites>
1819

rules/CodeQuality/Rector/BooleanNot/ReplaceConstantBooleanNotRector.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ public function getNodeTypes(): array
6969
*/
7070
public function refactor(Node $node): ?Node
7171
{
72-
if (! $node instanceof BooleanNot) {
73-
return null;
74-
}
75-
7672
if ($this->valueResolver->isFalse($node->expr)) {
7773
return new ConstFetch(new Name('true'));
7874
}

rules/CodingStyle/Rector/FuncCall/FunctionFirstClassCallableRector.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@ public function getNodeTypes(): array
6161
return [FuncCall::class];
6262
}
6363

64+
/**
65+
* @param FuncCall $node
66+
*/
6467
public function refactor(Node $node): ?FuncCall
6568
{
66-
if (! $node instanceof FuncCall) {
67-
return null;
68-
}
69-
7069
if (! $node->name instanceof Name) {
7170
return null;
7271
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Rector\Utils\Tests\Rector\RemoveRefactorDuplicatedNodeInstanceCheckRector\Fixture;
4+
5+
use PhpParser\Node;
6+
use Rector\Rector\AbstractRector;
7+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
8+
9+
final class CoverBareGetNodeTypes extends AbstractRector
10+
{
11+
public function getRuleDefinition(): RuleDefinition
12+
{
13+
}
14+
15+
public function getNodeTypes(): array
16+
{
17+
return [Node\Stmt\ClassMethod::class];
18+
}
19+
20+
public function refactor(Node $node)
21+
{
22+
if (! $node instanceof Node\Stmt\ClassMethod) {
23+
return null;
24+
}
25+
}
26+
}
27+
28+
?>
29+
-----
30+
<?php
31+
32+
namespace Rector\Utils\Tests\Rector\RemoveRefactorDuplicatedNodeInstanceCheckRector\Fixture;
33+
34+
use PhpParser\Node;
35+
use Rector\Rector\AbstractRector;
36+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
37+
38+
final class CoverBareGetNodeTypes extends AbstractRector
39+
{
40+
public function getRuleDefinition(): RuleDefinition
41+
{
42+
}
43+
44+
public function getNodeTypes(): array
45+
{
46+
return [Node\Stmt\ClassMethod::class];
47+
}
48+
49+
public function refactor(Node $node)
50+
{
51+
}
52+
}
53+
54+
?>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Rector\Utils\Tests\Rector\RemoveRefactorDuplicatedNodeInstanceCheckRector\Fixture;
4+
5+
use PhpParser\Node;
6+
use Rector\Rector\AbstractRector;
7+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
8+
9+
final class SomeClass extends AbstractRector
10+
{
11+
public function getRuleDefinition(): RuleDefinition
12+
{
13+
}
14+
15+
public function getNodeTypes(): array
16+
{
17+
return [Node\Stmt\ClassMethod::class];
18+
}
19+
20+
/**
21+
* @param Node\Stmt\ClassMethod $node
22+
*/
23+
public function refactor(Node $node)
24+
{
25+
if (! $node instanceof Node\Stmt\ClassMethod) {
26+
return null;
27+
}
28+
}
29+
}
30+
31+
?>
32+
-----
33+
<?php
34+
35+
namespace Rector\Utils\Tests\Rector\RemoveRefactorDuplicatedNodeInstanceCheckRector\Fixture;
36+
37+
use PhpParser\Node;
38+
use Rector\Rector\AbstractRector;
39+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
40+
41+
final class SomeClass extends AbstractRector
42+
{
43+
public function getRuleDefinition(): RuleDefinition
44+
{
45+
}
46+
47+
public function getNodeTypes(): array
48+
{
49+
return [Node\Stmt\ClassMethod::class];
50+
}
51+
52+
/**
53+
* @param Node\Stmt\ClassMethod $node
54+
*/
55+
public function refactor(Node $node)
56+
{
57+
}
58+
}
59+
60+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Utils\Tests\Rector\RemoveRefactorDuplicatedNodeInstanceCheckRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class RemoveRefactorDuplicatedNodeInstanceCheckRectorTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Utils\Rector\RemoveRefactorDuplicatedNodeInstanceCheckRector;
7+
8+
return RectorConfig::configure()
9+
->withRules([
10+
RemoveRefactorDuplicatedNodeInstanceCheckRector::class,
11+
]);

0 commit comments

Comments
 (0)