Skip to content

Commit

Permalink
Merge many Skipper tests to one, cleanup phpstan errors (#4806)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Aug 17, 2023
1 parent a85997a commit bbd2e81
Show file tree
Hide file tree
Showing 39 changed files with 154 additions and 284 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"symplify/easy-ci": "^11.1.18",
"symplify/easy-coding-standard": "^12.0.5",
"symplify/phpstan-extensions": "^11.2",
"symplify/phpstan-rules": "^12.0",
"symplify/phpstan-rules": "^12.1.4",
"symplify/rule-doc-generator": "^12.0",
"symplify/vendor-patches": "^11.2",
"tomasvotruba/class-leak": "^0.1",
Expand Down
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
{
}
9 changes: 9 additions & 0 deletions packages-tests/Skipper/Skipper/Fixture/Element/ThreeMan.php
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
{
}
69 changes: 0 additions & 69 deletions packages-tests/Skipper/Skipper/Skip/SkipSkipperTest.php

This file was deleted.

10 changes: 0 additions & 10 deletions packages-tests/Skipper/Skipper/Skip/Source/SomeClassToSkip.php

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

81 changes: 0 additions & 81 deletions packages-tests/Skipper/Skipper/Skipper/SkipperTest.php

This file was deleted.

105 changes: 105 additions & 0 deletions packages-tests/Skipper/Skipper/SkipperTest.php
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];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rector\Tests\Skipper\Skipper\Skip\Source;
namespace Rector\Tests\Skipper\Skipper\Source;

final class AnotherClassToSkip
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rector\Tests\Skipper\Skipper\Skip\Source;
namespace Rector\Tests\Skipper\Skipper\Source;

final class NotSkippedClass
{
Expand Down
2 changes: 1 addition & 1 deletion packages/Caching/ValueObject/Storage/FileCacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
) {
}

public function load(string $key, string $variableKey)
public function load(string $key, string $variableKey): mixed
{
return (function (string $key, string $variableKey) {
$cacheFilePaths = $this->getCacheFilePaths($key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class MemoryCacheStorage implements CacheStorageInterface
/**
* @return null|mixed
*/
public function load(string $key, string $variableKey)
public function load(string $key, string $variableKey): mixed
{
if (! isset($this->storage[$key])) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class StmtKeyNodeVisitor extends NodeVisitorAbstract implements ScopeResol
/**
* @param Node[] $nodes
*/
public function beforeTraverse(array $nodes)
public function beforeTraverse(array $nodes): ?array
{
if ($nodes === []) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/PhpDocParser/NodeVisitor/CallableNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(callable $callable)
$this->callable = $callable;
}

public function enterNode(Node $node)
public function enterNode(Node $node): int|Node|null
{
$originalNode = $node;

Expand Down
2 changes: 1 addition & 1 deletion packages/Skipper/Skipper/Skipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* @api
* @see \Rector\Tests\Skipper\Skipper\Skipper\SkipperTest
* @see \Rector\Tests\Skipper\Skipper\SkipperTest
*/
final class Skipper
{
Expand Down
Loading

0 comments on commit bbd2e81

Please sign in to comment.