Skip to content

Commit

Permalink
Added basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Dec 16, 2024
1 parent 037ca99 commit 3424976
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

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

final class SkipLocallyUsedProtectedMethod
{
protected function runHere()
{
}

private function run()
{
$this->runHere();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

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

final class StaticProtectedMethod
{
protected static function runHere()
{
}

protected static function anotherMethod()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Source;

use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Fixture\StaticProtectedMethod;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Fixture\StaticPublicMethod;

final class StaticProtectedCalls
{
private function go()
{
return StaticProtectedMethod::anotherMethod();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use TomasVotruba\UnusedPublic\Enum\RuleTips;
use TomasVotruba\UnusedPublic\Rules\UnusedPublicClassMethodRule;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Fixture\Interface\InterfaceWithExtraMethod;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Fixture\StaticProtectedMethod;
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;
Expand All @@ -35,6 +36,7 @@ final class UnusedPublicClassMethodRuleTest extends RuleTestCase
#[DataProvider('provideData')]
#[DataProvider('provideDataTests')]
#[DataProvider('provideDataSymfony')]
#[DataProvider('provideProtectedMethodData')]
public function testRule(array $filePaths, array $expectedErrorMessagesWithLines): void
{
$this->analyse($filePaths, $expectedErrorMessagesWithLines);
Expand Down Expand Up @@ -76,6 +78,17 @@ public static function provideDataSymfony(): Iterator
], []];
}

public static function provideProtectedMethodData(): Iterator
{
yield [[__DIR__ . '/Fixture/SkipLocallyUsedProtectedMethod.php'], []];

$errorMessage = sprintf(UnusedPublicClassMethodRule::ERROR_MESSAGE, StaticProtectedMethod::class, 'runHere');
yield [[
__DIR__ . '/Source/StaticProtectedCalls.php',
__DIR__ . '/Fixture/StaticProtectedMethod.php',
], [[$errorMessage, 9, RuleTips::SOLUTION_MESSAGE]]];
}

public static function provideData(): Iterator
{
yield [[__DIR__ . '/Fixture/SkipLocallyUsedPublicMethod.php'], []];
Expand Down

0 comments on commit 3424976

Please sign in to comment.