-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NodeTypeResolver] Handle isObjectType() on new $class dynamic variab…
…le should return false compare to Object FQCN (#4936) * [NodeTypeResolver] Handle isObjectType() on new $class dynamic variable should return false compare to Object FQCN * Fixed 🎉 * use equal check * return false directly, ObjectWithoutClassType is not ObjectType * Fix * failing fixture * Fix phpstan * Fixed 🎉 * Fixed 🎉 * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <actions@github.com>
- Loading branch information
1 parent
2be5a4d
commit e4f1f1b
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
packages-tests/NodeTypeResolver/PerNodeTypeResolver/NewTypeResolver/NewTypeResolverTest.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,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\NewTypeResolver; | ||
|
||
use Iterator; | ||
use PhpParser\Node\Expr\New_; | ||
use PHPStan\Type\ObjectType; | ||
use PHPStan\Type\ObjectWithoutClassType; | ||
use PHPStan\Type\Type; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\NodeTypeResolver\PHPStan\ObjectWithoutClassTypeWithParentTypes; | ||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; | ||
use Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\AbstractNodeTypeResolverTestCase; | ||
|
||
/** | ||
* @see \Rector\NodeTypeResolver\NodeTypeResolver\NewTypeResolver | ||
*/ | ||
final class NewTypeResolverTest extends AbstractNodeTypeResolverTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $file, int $nodePosition, Type $expectedType, bool $isObjectType): void | ||
{ | ||
$newNodes = $this->getNodesForFileOfType($file, New_::class); | ||
|
||
$resolvedType = $this->nodeTypeResolver->getType($newNodes[$nodePosition]); | ||
$this->assertEquals($expectedType, $resolvedType); | ||
|
||
$this->assertEquals( | ||
$isObjectType, | ||
$this->nodeTypeResolver->isObjectType( | ||
$newNodes[$nodePosition], | ||
new ObjectType('Symfony\Bundle\TwigBundle\Loader\FilesystemLoader') | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @return Iterator<int[]|string[]|ObjectWithoutClassType[]|ObjectWithoutClassTypeWithParentTypes[]|bool[]> | ||
*/ | ||
public static function provideData(): Iterator | ||
{ | ||
$objectWithoutClassType = new ObjectWithoutClassType(); | ||
|
||
# test new | ||
yield [__DIR__ . '/Source/NewDynamicNew.php', 0, $objectWithoutClassType, false]; | ||
|
||
$objectWithoutClassTypeWithParentTypes = new ObjectWithoutClassTypeWithParentTypes( | ||
[ | ||
new FullyQualifiedObjectType('Symfony\Bundle\TwigBundle\Loader\FilesystemLoader') | ||
] | ||
); | ||
yield [__DIR__ . '/Source/NewDynamicNewExtends.php', 0, $objectWithoutClassTypeWithParentTypes, true]; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages-tests/NodeTypeResolver/PerNodeTypeResolver/NewTypeResolver/Source/NewDynamicNew.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,11 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\NewTypeResolver\Source; | ||
|
||
class NewDynamicNew | ||
{ | ||
public function run($class) | ||
{ | ||
new $class; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ests/NodeTypeResolver/PerNodeTypeResolver/NewTypeResolver/Source/NewDynamicNewExtends.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,11 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\NewTypeResolver\Source; | ||
|
||
class NewDynamicNewExtends | ||
{ | ||
public function run() | ||
{ | ||
new class extends \Symfony\Bundle\TwigBundle\Loader\FilesystemLoader {}; | ||
} | ||
} |
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