Skip to content

Commit

Permalink
FinalizeClasses: add tests for existing features. (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnutix committed Apr 4, 2024
1 parent 11d1287 commit ba8f8d3
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/NeedsFinalizeAnalyzer/Fixture/abstract_class.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Rector\SwissKnife\Tests\NeedsFinalizeAnalyzer\Fixture;

abstract class AbstractClass
{
}
8 changes: 8 additions & 0 deletions tests/NeedsFinalizeAnalyzer/Fixture/anonymous_class.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

namespace Rector\SwissKnife\Tests\NeedsFinalizeAnalyzer\Fixture;

new class () {
};
9 changes: 9 additions & 0 deletions tests/NeedsFinalizeAnalyzer/Fixture/excluded_class.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Rector\SwissKnife\Tests\NeedsFinalizeAnalyzer\Fixture;

class ExcludedClass
{
}
9 changes: 9 additions & 0 deletions tests/NeedsFinalizeAnalyzer/Fixture/final_class.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Rector\SwissKnife\Tests\NeedsFinalizeAnalyzer\Fixture;

final class FinalClass
{
}
9 changes: 9 additions & 0 deletions tests/NeedsFinalizeAnalyzer/Fixture/non_final_class.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Rector\SwissKnife\Tests\NeedsFinalizeAnalyzer\Fixture;

class NonFinalClass
{
}
46 changes: 46 additions & 0 deletions tests/NeedsFinalizeAnalyzer/NeedsFinalizeAnalyzerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Rector\SwissKnife\Tests\NeedsFinalizeAnalyzer;

use PHPUnit\Framework\Attributes\DataProvider;
use Rector\SwissKnife\Analyzer\NeedsFinalizeAnalyzer;
use Rector\SwissKnife\PhpParser\CachedPhpParser;
use Rector\SwissKnife\Tests\AbstractTestCase;

final class NeedsFinalizeAnalyzerTest extends AbstractTestCase
{
private NeedsFinalizeAnalyzer $needsFinalizeAnalyzer;

protected function setUp(): void
{
parent::setUp();

$this->needsFinalizeAnalyzer = new NeedsFinalizeAnalyzer(
excludedClasses: [
'Rector\SwissKnife\Tests\NeedsFinalizeAnalyzer\Fixture\ExcludedClass',
],
cachedPhpParser: $this->make(CachedPhpParser::class),
);
}

#[DataProvider('provideData')]
public function test(string $filePath, bool $expected): void
{
$this->assertSame($expected, $this->needsFinalizeAnalyzer->isNeeded($filePath));
}

/**
* @return iterable<array{string, bool}>
*/
public static function provideData(): iterable
{
yield [__DIR__ . '/Fixture/excluded_class.php.inc', false];
yield [__DIR__ . '/Fixture/final_class.php.inc', false];
yield [__DIR__ . '/Fixture/abstract_class.php.inc', false];
yield [__DIR__ . '/Fixture/anonymous_class.php.inc', false];

yield [__DIR__ . '/Fixture/non_final_class.php.inc', true];
}
}

0 comments on commit ba8f8d3

Please sign in to comment.