Skip to content

Commit

Permalink
Add test fixture for interface require public method to avoid lowerin…
Browse files Browse the repository at this point in the history
…g visibility (#78)
  • Loading branch information
TomasVotruba authored Jul 24, 2023
1 parent ff8fa84 commit 338b243
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace TomasVotruba\UnusedPublic\Tests\Rules\LocalOnlyPublicClassMethodRule\Fixture;

use Rules\LocalOnlyPublicClassMethodRule\Source\SomeParentWithInterface;

final class SkipInterfaceMethod implements SomeParentWithInterface
{
/**
* This method is require by parent interface,
* and should never change visibility
*/
public function neverReport(): void
{
$url = $this->publicFormatUrl('a', 'b');
}

public function publicFormatUrl($path, $type): string
{
return '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use TomasVotruba\UnusedPublic\Tests\Rules\LocalOnlyPublicClassMethodRule\Fixture\CaseInsensitiveMethodName;
use TomasVotruba\UnusedPublic\Tests\Rules\LocalOnlyPublicClassMethodRule\Fixture\LocallyUsedEnumMethod;
use TomasVotruba\UnusedPublic\Tests\Rules\LocalOnlyPublicClassMethodRule\Fixture\LocallyUsedPublicMethod;
use TomasVotruba\UnusedPublic\Tests\Rules\LocalOnlyPublicClassMethodRule\Fixture\SkipInterfaceMethod;

final class LocalOnlyPublicClassMethodRuleTest extends RuleTestCase
{
Expand All @@ -34,6 +35,13 @@ public function testRule(array $filePaths, array $expectedErrorMessagesWithLines

public static function provideData(): Iterator
{
$errorMessage = sprintf(
LocalOnlyPublicClassMethodRule::ERROR_MESSAGE,
SkipInterfaceMethod::class,
'publicFormatUrl'
);
yield [[__DIR__ . '/Fixture/SkipInterfaceMethod.php'], [[$errorMessage, 20, RuleTips::NARROW_SCOPE]]];

$errorMessage = sprintf(
LocalOnlyPublicClassMethodRule::ERROR_MESSAGE,
LocallyUsedPublicMethod::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Rules\LocalOnlyPublicClassMethodRule\Source;

interface SomeParentWithInterface
{
public function neverReport(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule;

use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Fixture\Tests\MethodForTests;
use Iterator;
use PHPStan\Collectors\Collector;
use PHPStan\Rules\Rule;
Expand All @@ -22,6 +21,7 @@
use TomasVotruba\UnusedPublic\Rules\UnusedPublicClassMethodRule;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Fixture\Interface\InterfaceWithExtraMethod;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Fixture\StaticPublicMethod;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Fixture\Tests\MethodForTests;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Fixture\UsedInTestCaseOnly;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Source\Caller2;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Source\SomeEnum;
Expand Down

0 comments on commit 338b243

Please sign in to comment.