-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
e7c96a4
commit 2ffad93
Showing
47 changed files
with
791 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
42 changes: 42 additions & 0 deletions
42
packages-tests/Skipper/FileSystem/FnMatchPathNormalizerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Skipper\FileSystem; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\TestCase; | ||
use Rector\Core\Kernel\RectorKernel; | ||
use Rector\Skipper\FileSystem\FnMatchPathNormalizer; | ||
|
||
final class FnMatchPathNormalizerTest extends TestCase | ||
{ | ||
private FnMatchPathNormalizer $fnMatchPathNormalizer; | ||
|
||
protected function setUp(): void | ||
{ | ||
$rectorKernel = new RectorKernel(); | ||
$container = $rectorKernel->create(); | ||
|
||
$this->fnMatchPathNormalizer = $container->get(FnMatchPathNormalizer::class); | ||
} | ||
|
||
/** | ||
* @dataProvider providePaths | ||
*/ | ||
public function testPaths(string $path, string $expectedNormalizedPath): void | ||
{ | ||
$normalizedPath = $this->fnMatchPathNormalizer->normalizeForFnmatch($path); | ||
$this->assertSame($expectedNormalizedPath, $normalizedPath); | ||
} | ||
|
||
public function providePaths(): Iterator | ||
{ | ||
yield ['path/with/no/asterisk', 'path/with/no/asterisk']; | ||
yield ['*path/with/asterisk/begin', '*path/with/asterisk/begin*']; | ||
yield ['path/with/asterisk/end*', '*path/with/asterisk/end*']; | ||
yield ['*path/with/asterisk/begin/and/end*', '*path/with/asterisk/begin/and/end*']; | ||
yield [__DIR__ . '/Fixture/path/with/../in/it', __DIR__ . '/Fixture/path/in/it']; | ||
yield [__DIR__ . '/Fixture/path/with/../../in/it', __DIR__ . '/Fixture/in/it']; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages-tests/Skipper/SkipCriteriaResolver/SkippedPathsResolver/Fixture/existing_paths.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
you |
30 changes: 30 additions & 0 deletions
30
...ages-tests/Skipper/SkipCriteriaResolver/SkippedPathsResolver/SkippedPathsResolverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Skipper\SkipCriteriaResolver\SkippedPathsResolver; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Rector\Core\Kernel\RectorKernel; | ||
use Rector\Skipper\SkipCriteriaResolver\SkippedPathsResolver; | ||
|
||
final class SkippedPathsResolverTest extends TestCase | ||
{ | ||
private SkippedPathsResolver $skippedPathsResolver; | ||
|
||
protected function setUp(): void | ||
{ | ||
$rectorKernel = new RectorKernel(); | ||
$containerBuilder = $rectorKernel->createFromConfigs([__DIR__ . '/config/config.php']); | ||
|
||
$this->skippedPathsResolver = $containerBuilder->get(SkippedPathsResolver::class); | ||
} | ||
|
||
public function test(): void | ||
{ | ||
$skippedPaths = $this->skippedPathsResolver->resolve(); | ||
$this->assertCount(2, $skippedPaths); | ||
|
||
$this->assertSame('*/Mask/*', $skippedPaths[1]); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
packages-tests/Skipper/SkipCriteriaResolver/SkippedPathsResolver/config/config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->skip([ | ||
// windows slashes | ||
__DIR__ . '\non-existing-path', | ||
__DIR__ . '/../Fixture', | ||
'*\Mask\*', | ||
]); | ||
}; |
1 change: 1 addition & 0 deletions
1
packages-tests/Skipper/Skipper/Skip/Fixture/AlwaysSkippedPath/some_file.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
some content |
1 change: 1 addition & 0 deletions
1
packages-tests/Skipper/Skipper/Skip/Fixture/PathSkippedWithMask/another_file.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
yes, you can |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
function foo() { | ||
if (rand(0,1)) { | ||
return 1; | ||
} else { | ||
return 2; | ||
} | ||
} | ||
|
||
function bar() { | ||
if (rand(0,1)) { | ||
return 1; | ||
} else { | ||
return 2; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages-tests/Skipper/Skipper/Skip/Fixture/someDirectory/anotherFile.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
echo 'hi'; |
Empty file.
5 changes: 5 additions & 0 deletions
5
packages-tests/Skipper/Skipper/Skip/Fixture/someDirectory/someFile.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
echo 'hello'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
some text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
some text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Skipper\Skipper\Skip; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\TestCase; | ||
use Rector\Core\Kernel\RectorKernel; | ||
use Rector\Skipper\Skipper\Skipper; | ||
use Rector\Tests\Skipper\Skipper\Skip\Source\AnotherClassToSkip; | ||
use Rector\Tests\Skipper\Skipper\Skip\Source\NotSkippedClass; | ||
use Rector\Tests\Skipper\Skipper\Skip\Source\SomeClassToSkip; | ||
|
||
final class SkipSkipperTest extends TestCase | ||
{ | ||
private Skipper $skipper; | ||
|
||
protected function setUp(): void | ||
{ | ||
$rectorKernel = new RectorKernel(); | ||
$containerBuilder = $rectorKernel->createFromConfigs([__DIR__ . '/config/config.php']); | ||
|
||
$this->skipper = $containerBuilder->get(Skipper::class); | ||
} | ||
|
||
/** | ||
* @dataProvider provideCheckerAndFile() | ||
* @dataProvider provideAnythingAndFilePath() | ||
*/ | ||
public function test(string $element, string $filePath, bool $expectedSkip): void | ||
{ | ||
$resolvedSkip = $this->skipper->shouldSkipElementAndFileInfo($element, $filePath); | ||
$this->assertSame($expectedSkip, $resolvedSkip); | ||
} | ||
|
||
/** | ||
* @return Iterator<string[]|bool[]|class-string<AnotherClassToSkip>[]|class-string<NotSkippedClass>[]|class-string<SomeClassToSkip>[]> | ||
*/ | ||
public function provideCheckerAndFile(): Iterator | ||
{ | ||
yield [SomeClassToSkip::class, __DIR__ . '/Fixture', true]; | ||
|
||
yield [AnotherClassToSkip::class, __DIR__ . '/Fixture/someFile', true]; | ||
yield [AnotherClassToSkip::class, __DIR__ . '/Fixture/someDirectory/anotherFile.php', true]; | ||
yield [AnotherClassToSkip::class, __DIR__ . '/Fixture/someDirectory/anotherFile.php', true]; | ||
|
||
yield [NotSkippedClass::class, __DIR__ . '/Fixture/someFile', false]; | ||
yield [NotSkippedClass::class, __DIR__ . '/Fixture/someOtherFile', false]; | ||
} | ||
|
||
/** | ||
* @return Iterator<string[]|bool[]> | ||
*/ | ||
public function provideAnythingAndFilePath(): Iterator | ||
{ | ||
yield ['anything', __DIR__ . '/Fixture/AlwaysSkippedPath/some_file.txt', true]; | ||
yield ['anything', __DIR__ . '/Fixture/PathSkippedWithMask/another_file.txt', true]; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages-tests/Skipper/Skipper/Skip/Source/AnotherClassToSkip.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Skipper\Skipper\Skip\Source; | ||
|
||
final class AnotherClassToSkip | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
packages-tests/Skipper/Skipper/Skip/Source/NotSkippedClass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Skipper\Skipper\Skip\Source; | ||
|
||
final class NotSkippedClass | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
packages-tests/Skipper/Skipper/Skip/Source/SomeClassToSkip.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Skipper\Skipper\Skip\Source; | ||
|
||
final class SomeClassToSkip | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Tests\Skipper\Skipper\Skip\Source\AnotherClassToSkip; | ||
use Rector\Tests\Skipper\Skipper\Skip\Source\SomeClassToSkip; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->skip([ | ||
// classes | ||
SomeClassToSkip::class, | ||
|
||
// classes only in specific paths | ||
AnotherClassToSkip::class => ['Fixture/someFile', '*/someDirectory/*'], | ||
|
||
// file paths | ||
__DIR__ . '/../Fixture/AlwaysSkippedPath', | ||
'*\PathSkippedWithMask\*', | ||
]); | ||
}; |
10 changes: 10 additions & 0 deletions
10
packages-tests/Skipper/Skipper/Skipper/Fixture/Element/FifthElement.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Skipper\Skipper\Skipper\Fixture\Element; | ||
|
||
|
||
final class FifthElement | ||
{ | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
packages-tests/Skipper/Skipper/Skipper/Fixture/Element/SixthSense.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Skipper\Skipper\Skipper\Fixture\Element; | ||
|
||
|
||
final class SixthSense | ||
{ | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
packages-tests/Skipper/Skipper/Skipper/Fixture/Element/ThreeMan.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Skipper\Skipper\Skipper\Fixture\Element; | ||
|
||
|
||
final class ThreeMan | ||
{ | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
packages-tests/Skipper/Skipper/Skipper/Fixture/SomeRandom/file.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
some content |
1 change: 1 addition & 0 deletions
1
packages-tests/Skipper/Skipper/Skipper/Fixture/SomeSkipped/any.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
any content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Skipper\Skipper\Skipper; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\TestCase; | ||
use Rector\Core\Kernel\RectorKernel; | ||
use Rector\Skipper\Skipper\Skipper; | ||
use Rector\Tests\Skipper\Skipper\Skipper\Fixture\Element\FifthElement; | ||
use Rector\Tests\Skipper\Skipper\Skipper\Fixture\Element\SixthSense; | ||
use Rector\Tests\Skipper\Skipper\Skipper\Fixture\Element\ThreeMan; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class SkipperTest extends TestCase | ||
{ | ||
private Skipper $skipper; | ||
|
||
protected function setUp(): void | ||
{ | ||
$rectorKernel = new RectorKernel(); | ||
$containerBuilder = $rectorKernel->createFromConfigs([__DIR__ . '/config/config.php']); | ||
|
||
$this->skipper = $containerBuilder->get(Skipper::class); | ||
} | ||
|
||
/** | ||
* @dataProvider provideDataShouldSkipFileInfo() | ||
*/ | ||
public function testSkipFileInfo(string $filePath, bool $expectedSkip): void | ||
{ | ||
$smartFileInfo = new SmartFileInfo($filePath); | ||
|
||
$resultSkip = $this->skipper->shouldSkipFileInfo($smartFileInfo); | ||
$this->assertSame($expectedSkip, $resultSkip); | ||
} | ||
|
||
/** | ||
* @return Iterator<string[]|bool[]> | ||
*/ | ||
public function provideDataShouldSkipFileInfo(): Iterator | ||
{ | ||
yield [__DIR__ . '/Fixture/SomeRandom/file.txt', false]; | ||
yield [__DIR__ . '/Fixture/SomeSkipped/any.txt', true]; | ||
} | ||
|
||
/** | ||
* @param object|class-string $element | ||
* @dataProvider provideDataShouldSkipElement() | ||
*/ | ||
public function testSkipElement(string|object $element, bool $expectedSkip): void | ||
{ | ||
$resultSkip = $this->skipper->shouldSkipElement($element); | ||
$this->assertSame($expectedSkip, $resultSkip); | ||
} | ||
|
||
/** | ||
* @return Iterator<bool[]|class-string<SixthSense>[]|class-string<ThreeMan>[]|FifthElement[]> | ||
*/ | ||
public function provideDataShouldSkipElement(): Iterator | ||
{ | ||
yield [ThreeMan::class, false]; | ||
yield [SixthSense::class, true]; | ||
yield [new FifthElement(), true]; | ||
} | ||
} |
Oops, something went wrong.