Skip to content

Commit 5238e5b

Browse files
committed
udpate tests
1 parent 668877f commit 5238e5b

5 files changed

Lines changed: 46 additions & 48 deletions

File tree

‎tests/Skipper/Skipper/Fixture/Element/FifthElement.php‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44

55
namespace Rector\Tests\Skipper\Skipper\Fixture\Element;
66

7-
final class FifthElement
7+
use PhpParser\Node;
8+
use Rector\RuleDoc\RuleDefinition;
9+
10+
final class FifthElement implements \Rector\Contract\Rector\RectorInterface
811
{
12+
public function getRuleDefinition(): RuleDefinition
13+
{
14+
// TODO: Implement getRuleDefinition() method.
15+
}
16+
17+
public function getNodeTypes(): array
18+
{
19+
// TODO: Implement getNodeTypes() method.
20+
}
21+
22+
public function refactor(Node $node)
23+
{
24+
// TODO: Implement refactor() method.
25+
}
926
}

‎tests/Skipper/Skipper/SkipperTest.php‎

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
use PHPUnit\Framework\Attributes\DataProvider;
99
use Rector\Configuration\Option;
1010
use Rector\Configuration\Parameter\SimpleParameterProvider;
11+
use Rector\Contract\Rector\RectorInterface;
1112
use Rector\Skipper\Skipper\Skipper;
1213
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
1314
use Rector\Tests\Skipper\Skipper\Fixture\Element\FifthElement;
14-
use Rector\Tests\Skipper\Skipper\Fixture\Element\ThreeMan;
1515
use Rector\Tests\Skipper\Skipper\Source\AnotherClassToSkip;
16-
use Rector\Tests\Skipper\Skipper\Source\NotSkippedClass;
1716

1817
final class SkipperTest extends AbstractLazyTestCase
1918
{
@@ -69,44 +68,18 @@ public static function provideDataShouldSkipFilePath(): Iterator
6968
yield [__DIR__ . '/Fixture/PathSkippedWithMask/another_file.txt', true];
7069
}
7170

72-
/**
73-
* @param object|class-string $element
74-
*/
75-
#[DataProvider('provideDataShouldSkipElement')]
76-
public function testSkipElement(string|object $element, bool $expectedSkip): void
71+
#[DataProvider('provideRectorAndFile')]
72+
public function testSkipElementAndFilePath(RectorInterface $rector, string $filePath, bool $expectedSkip): void
7773
{
78-
$resultSkip = $this->skipper->shouldSkipElement($element);
79-
$this->assertSame($expectedSkip, $resultSkip);
80-
}
81-
82-
#[DataProvider('provideCheckerAndFile')]
83-
public function testSkipElementAndFilePath(string $element, string $filePath, bool $expectedSkip): void
84-
{
85-
$resolvedSkip = $this->skipper->shouldSkipRectorAndFile($element, $filePath);
74+
$resolvedSkip = $this->skipper->shouldSkipRectorAndFile($rector, $filePath);
8675
$this->assertSame($expectedSkip, $resolvedSkip);
8776
}
8877

89-
/**
90-
* @return Iterator<array<array<int, mixed>, mixed>>
91-
*/
92-
public static function provideCheckerAndFile(): Iterator
78+
public static function provideRectorAndFile(): Iterator
9379
{
94-
yield [FifthElement::class, __DIR__ . '/Fixture', true];
80+
yield [new FifthElement(), __DIR__ . '/Fixture', true];
9581

96-
yield [AnotherClassToSkip::class, __DIR__ . '/Fixture/someFile', true];
97-
yield [AnotherClassToSkip::class, __DIR__ . '/Fixture/someDirectory/anotherFile.php', true];
98-
99-
yield [NotSkippedClass::class, __DIR__ . '/Fixture/someFile', false];
100-
yield [NotSkippedClass::class, __DIR__ . '/Fixture/someOtherFile', false];
101-
}
102-
103-
/**
104-
* @return Iterator<array<array<int, mixed>, mixed>>
105-
*/
106-
public static function provideDataShouldSkipElement(): Iterator
107-
{
108-
yield [ThreeMan::class, false];
109-
yield [FifthElement::class, true];
110-
yield [new FifthElement(), true];
82+
yield [new AnotherClassToSkip(), __DIR__ . '/Fixture/someFile', true];
83+
yield [new AnotherClassToSkip(), __DIR__ . '/Fixture/someDirectory/anotherFile.php', true];
11184
}
11285
}

‎tests/Skipper/Skipper/Source/AnotherClassToSkip.php‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44

55
namespace Rector\Tests\Skipper\Skipper\Source;
66

7-
final class AnotherClassToSkip
7+
use PhpParser\Node;
8+
use Rector\Contract\Rector\RectorInterface;
9+
use Rector\RuleDoc\RuleDefinition;
10+
11+
final class AnotherClassToSkip implements RectorInterface
812
{
13+
public function getRuleDefinition(): RuleDefinition
14+
{
15+
return new RuleDefinition('Skip this class', []);
16+
}
17+
18+
public function getNodeTypes(): array
19+
{
20+
return [];
21+
}
22+
23+
public function refactor(Node $node)
24+
{
25+
return null;
26+
}
927
}

‎tests/Skipper/Skipper/Source/NotSkippedClass.php‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎tests/Skipper/Skipper/UsedSkipCollectorTest.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ protected function tearDown(): void
5050
public function testCollectsOnlyMatchedSkips(): void
5151
{
5252
$this->skipper->shouldSkipFilePath('tests/Skipper/Skipper/Fixture/SomeSkippedPath/any.txt');
53-
$this->skipper->shouldSkipElement(FifthElement::class);
5453

5554
$usedSkips = $this->usedSkipCollector->provide();
5655

@@ -77,7 +76,7 @@ public function testCollectsMatchedPathNotRuleClassForRuleScopedSkip(): void
7776
]);
7877

7978
$this->skipper->shouldSkipRectorAndFile(
80-
AnotherClassToSkip::class,
79+
new AnotherClassToSkip(),
8180
__DIR__ . '/Fixture/someDirectory/anotherFile.php'
8281
);
8382

0 commit comments

Comments
 (0)