Skip to content

Commit

Permalink
[Testing] Deprecate FileInfoParser, use existing TestingParser instead (
Browse files Browse the repository at this point in the history
#5501)

* [Testing] Deprecate FileInfoParser, use existing TestingParser instead

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user authored Jan 25, 2024
1 parent d09ae74 commit 174656a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/Console/Command/CustomRuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static function (string $answer) : string {
if ($answer === '') {
throw new ShouldNotHappenException('Rector name cannot be empty');
}

return $answer;
}
);
Expand Down
4 changes: 3 additions & 1 deletion src/FileSystemRector/Parser/FileInfoParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
use Rector\ValueObject\Application\File;

/**
* Only for testing, @todo move to testing
* @deprecated use \Rector\Testing\TestingParser\TestingParser instead
*
* Only for testing
*/
final readonly class FileInfoParser
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
use Rector\BetterPhpDocParser\Printer\PhpDocInfoPrinter;
use Rector\Exception\ShouldNotHappenException;
use Rector\FileSystem\FilePathHelper;
use Rector\FileSystemRector\Parser\FileInfoParser;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\Testing\Fixture\FixtureFileFinder;
use Rector\Testing\Fixture\FixtureSplitter;
use Rector\Testing\Fixture\FixtureTempFileDumper;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\Testing\TestingParser\TestingParser;

final class TagValueNodeReprintTest extends AbstractLazyTestCase
{
private FileInfoParser $fileInfoParser;
private TestingParser $testingParser;

private BetterNodeFinder $betterNodeFinder;

Expand All @@ -34,7 +34,7 @@ final class TagValueNodeReprintTest extends AbstractLazyTestCase

protected function setUp(): void
{
$this->fileInfoParser = $this->make(FileInfoParser::class);
$this->testingParser = $this->make(TestingParser::class);
$this->filePathHelper = $this->make(FilePathHelper::class);
$this->betterNodeFinder = $this->make(BetterNodeFinder::class);
$this->phpDocInfoPrinter = $this->make(PhpDocInfoPrinter::class);
Expand Down Expand Up @@ -109,7 +109,7 @@ private function splitListByEOL(string $content): array
*/
private function parseFileAndGetFirstNodeOfType(string $filePath, string $nodeType): Node
{
$nodes = $this->fileInfoParser->parseFileInfoToNodesAndDecorate($filePath);
$nodes = $this->testingParser->parseFileToDecoratedNodes($filePath);

$node = $this->betterNodeFinder->findFirstInstanceOf($nodes, $nodeType);
if (! $node instanceof Node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
use Rector\BetterPhpDocParser\Printer\PhpDocInfoPrinter;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
use Rector\Exception\ShouldNotHappenException;
use Rector\FileSystemRector\Parser\FileInfoParser;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\Testing\Fixture\FixtureSplitter;
use Rector\Testing\Fixture\FixtureTempFileDumper;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\Testing\TestingParser\TestingParser;

final class TestModifyReprintTest extends AbstractLazyTestCase
{
private FileInfoParser $fileInfoParser;
private TestingParser $testingParser;

private BetterNodeFinder $betterNodeFinder;

Expand All @@ -33,7 +33,7 @@ final class TestModifyReprintTest extends AbstractLazyTestCase

protected function setUp(): void
{
$this->fileInfoParser = $this->make(FileInfoParser::class);
$this->testingParser = $this->make(TestingParser::class);
$this->betterNodeFinder = $this->make(BetterNodeFinder::class);
$this->phpDocInfoPrinter = $this->make(PhpDocInfoPrinter::class);
$this->phpDocInfoFactory = $this->make(PhpDocInfoFactory::class);
Expand Down Expand Up @@ -71,7 +71,7 @@ public function test(): void
private function parseFileAndGetFirstNodeOfType(string $fileContents, string $nodeType): PhpDocInfo
{
$fixtureFilePath = FixtureTempFileDumper::dump($fileContents);
$nodes = $this->fileInfoParser->parseFileInfoToNodesAndDecorate($fixtureFilePath);
$nodes = $this->testingParser->parseFileToDecoratedNodes($fixtureFilePath);

FileSystem::delete($fixtureFilePath);

Expand Down
8 changes: 4 additions & 4 deletions tests/Comments/CommentRemover/CommentRemoverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
use Nette\Utils\FileSystem;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Comments\CommentRemover;
use Rector\FileSystemRector\Parser\FileInfoParser;
use Rector\PhpParser\Printer\BetterStandardPrinter;
use Rector\Testing\Fixture\FixtureFileFinder;
use Rector\Testing\Fixture\FixtureSplitter;
use Rector\Testing\Fixture\FixtureTempFileDumper;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\Testing\TestingParser\TestingParser;

final class CommentRemoverTest extends AbstractLazyTestCase
{
private CommentRemover $commentRemover;

private FileInfoParser $fileInfoParser;
private TestingParser $testingParser;

private BetterStandardPrinter $betterStandardPrinter;

protected function setUp(): void
{
$this->commentRemover = $this->make(CommentRemover::class);
$this->fileInfoParser = $this->make(FileInfoParser::class);
$this->testingParser = $this->make(TestingParser::class);
$this->betterStandardPrinter = $this->make(BetterStandardPrinter::class);
}

Expand All @@ -36,7 +36,7 @@ public function test(string $filePath): void
[$inputContents, $expectedOutputContents] = FixtureSplitter::split($filePath);
$inputFilePath = FixtureTempFileDumper::dump($inputContents);

$nodes = $this->fileInfoParser->parseFileInfoToNodesAndDecorate($inputFilePath);
$nodes = $this->testingParser->parseFileToDecoratedNodes($inputFilePath);

FileSystem::delete($inputFilePath);

Expand Down

0 comments on commit 174656a

Please sign in to comment.