Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DX] Inline symplify/astral to use only active classes (#2851)
- Loading branch information
1 parent
ad7cdc7
commit bb59a7c
Showing
110 changed files
with
1,690 additions
and
163 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
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
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
10 changes: 10 additions & 0 deletions
10
packages-tests/PhpDocParser/NodeValue/Fixture/SomeClassWithConstant.php
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\PhpDocParser\NodeValue\Fixture; | ||
|
||
final class SomeClassWithConstant | ||
{ | ||
public const NAME = 'value'; | ||
} |
57 changes: 57 additions & 0 deletions
57
packages-tests/PhpDocParser/NodeValue/NodeValueResolverTest.php
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,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\PhpDocParser\NodeValue; | ||
|
||
use Iterator; | ||
use PhpParser\Node\Arg; | ||
use PhpParser\Node\Expr; | ||
use PhpParser\Node\Expr\BinaryOp\Concat; | ||
use PhpParser\Node\Expr\ClassConstFetch; | ||
use PhpParser\Node\Expr\ConstFetch; | ||
use PhpParser\Node\Expr\FuncCall; | ||
use PhpParser\Node\Name; | ||
use PhpParser\Node\Name\FullyQualified; | ||
use PhpParser\Node\Scalar\MagicConst\Dir; | ||
use PhpParser\Node\Scalar\MagicConst\File; | ||
use PhpParser\Node\Scalar\String_; | ||
use Rector\PhpDocParser\NodeValue\NodeValueResolver; | ||
use Rector\Testing\PHPUnit\AbstractTestCase; | ||
use Rector\Tests\PhpDocParser\NodeValue\Fixture\SomeClassWithConstant; | ||
|
||
final class NodeValueResolverTest extends AbstractTestCase | ||
{ | ||
private NodeValueResolver $nodeValueResolver; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->boot(); | ||
$this->nodeValueResolver = $this->getService(NodeValueResolver::class); | ||
} | ||
|
||
/** | ||
* @dataProvider provideData() | ||
* @param string|class-string<\Rector\Tests\PhpDocParser\NodeValue\NodeValueResolverTest>|bool $expectedValue | ||
*/ | ||
public function test(Expr $expr, string|bool $expectedValue): void | ||
{ | ||
$resolvedValue = $this->nodeValueResolver->resolve($expr, __FILE__); | ||
$this->assertSame($expectedValue, $resolvedValue); | ||
} | ||
|
||
/** | ||
* @return Iterator<mixed[]|Expr[]> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
yield [new String_('value'), 'value']; | ||
yield [new ClassConstFetch(new FullyQualified(self::class), 'class'), self::class]; | ||
yield [new ClassConstFetch(new FullyQualified(SomeClassWithConstant::class), 'NAME'), 'value']; | ||
yield [new Dir(), __DIR__]; | ||
yield [new ConstFetch(new Name('true')), true]; | ||
yield [new Concat(new Dir(), new String_('/example.latte')), __DIR__ . '/example.latte']; | ||
$args = [new Arg(new String_('.php')), new Arg(new String_('.latte')), new Arg(new File())]; | ||
yield [new FuncCall(new Name('str_replace'), $args), __DIR__ . '/NodeValueResolverTest.latte']; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...sts/PhpDocParser/PhpDocParser/PhpDocNodeVisitor/ParentConnectingPhpDocNodeVisitorTest.php
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,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\PhpDocParser\PhpDocParser\PhpDocNodeVisitor; | ||
|
||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; | ||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; | ||
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser; | ||
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\ParentConnectingPhpDocNodeVisitor; | ||
use Rector\PhpDocParser\PhpDocParser\ValueObject\PhpDocAttributeKey; | ||
use Rector\Testing\PHPUnit\AbstractTestCase; | ||
|
||
final class ParentConnectingPhpDocNodeVisitorTest extends AbstractTestCase | ||
{ | ||
private PhpDocNodeTraverser $phpDocNodeTraverser; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->boot(); | ||
|
||
$this->phpDocNodeTraverser = $this->getService(PhpDocNodeTraverser::class); | ||
|
||
/** @var ParentConnectingPhpDocNodeVisitor $parentConnectingPhpDocNodeVisitor */ | ||
$parentConnectingPhpDocNodeVisitor = $this->getService(ParentConnectingPhpDocNodeVisitor::class); | ||
$this->phpDocNodeTraverser->addPhpDocNodeVisitor($parentConnectingPhpDocNodeVisitor); | ||
} | ||
|
||
public function testTypeNode(): void | ||
{ | ||
$phpDocNode = $this->createPhpDocNode(); | ||
$this->phpDocNodeTraverser->traverse($phpDocNode); | ||
|
||
/** @var PhpDocTagNode $phpDocChildNode */ | ||
$phpDocChildNode = $phpDocNode->children[0]; | ||
|
||
$returnTagValueNode = $phpDocChildNode->value; | ||
|
||
$this->assertInstanceOf(ReturnTagValueNode::class, $returnTagValueNode); | ||
|
||
/** @var ReturnTagValueNode $returnTagValueNode */ | ||
$returnParent = $returnTagValueNode->getAttribute(PhpDocAttributeKey::PARENT); | ||
$this->assertSame($phpDocChildNode, $returnParent); | ||
|
||
$returnTypeParent = $returnTagValueNode->type->getAttribute(PhpDocAttributeKey::PARENT); | ||
$this->assertSame($returnTagValueNode, $returnTypeParent); | ||
|
||
// test child + parent node | ||
$phpDocChildNode = $phpDocNode->children[0]; | ||
$this->assertInstanceOf(PhpDocTagNode::class, $phpDocChildNode); | ||
|
||
$childParent = $phpDocChildNode->getAttribute(PhpDocAttributeKey::PARENT); | ||
$this->assertSame($phpDocNode, $childParent); | ||
} | ||
|
||
private function createPhpDocNode(): PhpDocNode | ||
{ | ||
$returnTagValueNode = new ReturnTagValueNode(new IdentifierTypeNode('string'), ''); | ||
|
||
return new PhpDocNode([ | ||
new PhpDocTagNode('@return', $returnTagValueNode), | ||
new PhpDocTextNode('some text'), | ||
]); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...ges-tests/PhpDocParser/PhpDocParser/SimplePhpDocNodeTraverser/PhpDocNodeTraverserTest.php
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\PhpDocParser\PhpDocParser\SimplePhpDocNodeTraverser; | ||
|
||
use PHPStan\PhpDocParser\Ast\Node; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; | ||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; | ||
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser; | ||
use Rector\Testing\PHPUnit\AbstractTestCase; | ||
|
||
final class PhpDocNodeTraverserTest extends AbstractTestCase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private const SOME_DESCRIPTION = 'some description'; | ||
|
||
private PhpDocNodeTraverser $phpDocNodeTraverser; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->boot(); | ||
$this->phpDocNodeTraverser = $this->getService(PhpDocNodeTraverser::class); | ||
} | ||
|
||
public function test(): void | ||
{ | ||
$varTagValueNode = new VarTagValueNode(new IdentifierTypeNode('string'), '', ''); | ||
$phpDocNode = new PhpDocNode([new PhpDocTagNode('@var', $varTagValueNode)]); | ||
|
||
$this->phpDocNodeTraverser->traverseWithCallable($phpDocNode, '', static function (Node $node): Node { | ||
if (! $node instanceof VarTagValueNode) { | ||
return $node; | ||
} | ||
|
||
$node->description = self::SOME_DESCRIPTION; | ||
return $node; | ||
}); | ||
|
||
$varTagValueNodes = $phpDocNode->getVarTagValues(); | ||
$this->assertSame(self::SOME_DESCRIPTION, $varTagValueNodes[0]->description); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages-tests/PhpDocParser/PhpDocParser/SimplePhpDocParser/Fixture/param_string_name.txt
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,3 @@ | ||
/** | ||
* @param string $name | ||
*/ |
3 changes: 3 additions & 0 deletions
3
packages-tests/PhpDocParser/PhpDocParser/SimplePhpDocParser/Fixture/var_int.txt
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,3 @@ | ||
/** | ||
* @var int | ||
*/ |
47 changes: 47 additions & 0 deletions
47
packages-tests/PhpDocParser/PhpDocParser/SimplePhpDocParser/SimplePhpDocParserTest.php
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\PhpDocParser\PhpDocParser\SimplePhpDocParser; | ||
|
||
use Nette\Utils\FileSystem; | ||
use Rector\PhpDocParser\PhpDocParser\SimplePhpDocParser; | ||
use Rector\PhpDocParser\PhpDocParser\ValueObject\Ast\PhpDoc\SimplePhpDocNode; | ||
use Rector\Testing\PHPUnit\AbstractTestCase; | ||
|
||
final class SimplePhpDocParserTest extends AbstractTestCase | ||
{ | ||
private SimplePhpDocParser $simplePhpDocParser; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->boot(); | ||
|
||
$this->simplePhpDocParser = $this->getService(SimplePhpDocParser::class); | ||
} | ||
|
||
public function testVar(): void | ||
{ | ||
$fileContents = FileSystem::read(__DIR__ . '/Fixture/var_int.txt'); | ||
|
||
$simplePhpDocNode = $this->simplePhpDocParser->parseDocBlock($fileContents); | ||
$this->assertInstanceOf(SimplePhpDocNode::class, $simplePhpDocNode); | ||
|
||
$varTagValues = $simplePhpDocNode->getVarTagValues(); | ||
$this->assertCount(1, $varTagValues); | ||
} | ||
|
||
public function testParam(): void | ||
{ | ||
$fileContents = FileSystem::read(__DIR__ . '/Fixture/param_string_name.txt'); | ||
|
||
$simplePhpDocNode = $this->simplePhpDocParser->parseDocBlock($fileContents); | ||
$this->assertInstanceOf(SimplePhpDocNode::class, $simplePhpDocNode); | ||
|
||
// DX friendly | ||
$paramType = $simplePhpDocNode->getParamType('name'); | ||
$withDollarParamType = $simplePhpDocNode->getParamType('$name'); | ||
|
||
$this->assertSame($paramType, $withDollarParamType); | ||
} | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.