-
-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge many Skipper tests to one, cleanup phpstan errors (#4806)
- Loading branch information
1 parent
a85997a
commit bbd2e81
Showing
39 changed files
with
154 additions
and
284 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
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
packages-tests/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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Skipper\Skipper\Fixture\Element; | ||
|
||
final class FifthElement | ||
{ | ||
} |
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\Fixture\Element; | ||
|
||
final class ThreeMan | ||
{ | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
packages-tests/Skipper/Skipper/Skip/Source/SomeClassToSkip.php
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
packages-tests/Skipper/Skipper/Skipper/Fixture/Element/FifthElement.php
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
packages-tests/Skipper/Skipper/Skipper/Fixture/Element/SixthSense.php
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
packages-tests/Skipper/Skipper/Skipper/Fixture/Element/ThreeMan.php
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,105 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Skipper\Skipper; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Core\Configuration\Option; | ||
use Rector\Core\Configuration\Parameter\SimpleParameterProvider; | ||
use Rector\Skipper\Skipper\Skipper; | ||
use Rector\Testing\PHPUnit\AbstractLazyTestCase; | ||
use Rector\Tests\Skipper\Skipper\Fixture\Element\FifthElement; | ||
use Rector\Tests\Skipper\Skipper\Fixture\Element\ThreeMan; | ||
use Rector\Tests\Skipper\Skipper\Source\AnotherClassToSkip; | ||
use Rector\Tests\Skipper\Skipper\Source\NotSkippedClass; | ||
|
||
final class SkipperTest extends AbstractLazyTestCase | ||
{ | ||
private Skipper $skipper; | ||
|
||
protected function setUp(): void | ||
{ | ||
SimpleParameterProvider::setParameter(Option::SKIP, [ | ||
// windows like path | ||
'*\SomeSkipped\*', | ||
|
||
// file paths | ||
__DIR__ . '/Fixture/AlwaysSkippedPath', | ||
'*\PathSkippedWithMask\*', | ||
__DIR__ . '/Fixture/SomeSkippedPath', | ||
__DIR__ . '/Fixture/SomeSkippedPathToFile/any.txt', | ||
|
||
// elements | ||
FifthElement::class, | ||
|
||
// classes only in specific paths | ||
AnotherClassToSkip::class => ['Fixture/someFile', '*/someDirectory/*'], | ||
]); | ||
|
||
$this->skipper = $this->make(Skipper::class); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
// cleanup configuration | ||
SimpleParameterProvider::setParameter(Option::SKIP, []); | ||
} | ||
|
||
#[DataProvider('provideDataShouldSkipFilePath')] | ||
public function testSkipFilePath(string $filePath, bool $expectedSkip): void | ||
{ | ||
$filePathResultSkip = $this->skipper->shouldSkipFilePath($filePath); | ||
$this->assertSame($expectedSkip, $filePathResultSkip); | ||
} | ||
|
||
/** | ||
* @return Iterator<string[]|bool[]> | ||
*/ | ||
public static function provideDataShouldSkipFilePath(): Iterator | ||
{ | ||
yield [__DIR__ . '/Fixture/SomeRandom/file.txt', false]; | ||
yield [__DIR__ . '/Fixture/SomeSkipped/any.txt', true]; | ||
yield ['packages-tests/Skipper/Skipper/Fixture/SomeSkippedPath/any.txt', true]; | ||
yield ['packages-tests/Skipper/Skipper/Fixture/SomeSkippedPathToFile/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); | ||
} | ||
|
||
#[DataProvider('provideCheckerAndFile')] | ||
public function testSkipElementAndFilePath(string $element, string $filePath, bool $expectedSkip): void | ||
{ | ||
$resolvedSkip = $this->skipper->shouldSkipElementAndFilePath($element, $filePath); | ||
$this->assertSame($expectedSkip, $resolvedSkip); | ||
} | ||
|
||
public static function provideCheckerAndFile(): Iterator | ||
{ | ||
yield [FifthElement::class, __DIR__ . '/Fixture', true]; | ||
|
||
yield [AnotherClassToSkip::class, __DIR__ . '/Fixture/someFile', true]; | ||
yield [AnotherClassToSkip::class, __DIR__ . '/Fixture/someDirectory/anotherFile.php', true]; | ||
|
||
yield [NotSkippedClass::class, __DIR__ . '/Fixture/someFile', false]; | ||
yield [NotSkippedClass::class, __DIR__ . '/Fixture/someOtherFile', false]; | ||
|
||
yield ['anything', __DIR__ . '/Fixture/AlwaysSkippedPath/some_file.txt', true]; | ||
yield ['anything', __DIR__ . '/Fixture/PathSkippedWithMask/another_file.txt', true]; | ||
} | ||
|
||
public static function provideDataShouldSkipElement(): Iterator | ||
{ | ||
yield [ThreeMan::class, false]; | ||
yield [FifthElement::class, true]; | ||
yield [new FifthElement(), true]; | ||
} | ||
} |
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
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
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
Oops, something went wrong.