-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FinalizeClasses: add tests for existing features. (#21)
- Loading branch information
Showing
6 changed files
with
90 additions
and
0 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
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 | ||
{ | ||
} |
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,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\SwissKnife\Tests\NeedsFinalizeAnalyzer\Fixture; | ||
|
||
new class () { | ||
}; |
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\SwissKnife\Tests\NeedsFinalizeAnalyzer\Fixture; | ||
|
||
class ExcludedClass | ||
{ | ||
} |
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\SwissKnife\Tests\NeedsFinalizeAnalyzer\Fixture; | ||
|
||
final class FinalClass | ||
{ | ||
} |
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\SwissKnife\Tests\NeedsFinalizeAnalyzer\Fixture; | ||
|
||
class NonFinalClass | ||
{ | ||
} |
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,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]; | ||
} | ||
} |