[PHPUnit] Fix AddSeeTestAnnotationRector for same short name, but different namespace (#4488)

* [PHPUnit] Fix AddSeeTestAnnotationRector for same short name, but different namespace

* correct namespaces
This commit is contained in:
Tomas Votruba 2020-10-27 01:42:04 +01:00 committed by GitHub
parent 7a1ea1328b
commit a6e85fe69a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 277 additions and 359 deletions

View File

@ -10,10 +10,10 @@ use Rector\DoctrineCodeQuality\Rector\Class_\MoveRepositoryFromParentToConstruct
use Rector\Generic\Rector\Class_\AddPropertyByParentRector;
use Rector\Generic\Rector\Class_\RemoveParentRector;
use Rector\Generic\Rector\ClassLike\RemoveAnnotationRector;
use Rector\Generic\Rector\MethodCall\ReplaceParentCallByPropertyCallRector;
use Rector\Generic\ValueObject\AddPropertyByParent;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\Transform\Rector\MethodCall\MethodCallToPropertyFetchRector;
use Rector\Transform\Rector\MethodCall\ReplaceParentCallByPropertyCallRector;
use Rector\Transform\ValueObject\ReplaceParentCallByPropertyCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

View File

@ -23,7 +23,7 @@
- [DowngradePhp80](#downgradephp80) (6)
- [DynamicTypeAnalysis](#dynamictypeanalysis) (3)
- [FileSystemRector](#filesystemrector) (1)
- [Generic](#generic) (36)
- [Generic](#generic) (35)
- [JMS](#jms) (2)
- [Laravel](#laravel) (3)
- [Legacy](#legacy) (4)
@ -72,7 +72,7 @@
- [SymfonyCodeQuality](#symfonycodequality) (1)
- [SymfonyPHPUnit](#symfonyphpunit) (1)
- [SymfonyPhpConfig](#symfonyphpconfig) (3)
- [Transform](#transform) (11)
- [Transform](#transform) (12)
- [Twig](#twig) (1)
- [TypeDeclaration](#typedeclaration) (9)
@ -4288,7 +4288,7 @@ Change database type "bigint" for @var/type declaration to string
### `ChangeQuerySetParametersMethodParameterFromArrayToArrayCollectionRector`
- class: [`Rector\DoctrineCodeQuality\Rector\MethodCall\ChangeQuerySetParametersMethodParameterFromArrayToArrayCollectionRector`](/rules/doctrine-code-quality/src/Rector/MethodCall/ChangeQuerySetParametersMethodParameterFromArrayToArrayCollectionRector.php)
- [test fixtures](/rules/doctrine-code-quality/tests/Rector/MethodCall/ChangeQuerySetParametersMethodParameterFromArrayToArrayCollection/Fixture)
- [test fixtures](/rules/doctrine-code-quality/tests/Rector/MethodCall/ChangeQuerySetParametersMethodParameterFromArrayToArrayCollectionRector/Fixture)
Change array to ArrayCollection in setParameters method of query builder
@ -4464,7 +4464,7 @@ Make nullability in setter class method with respect to property
### `MoveCurrentDateTimeDefaultInEntityToConstructorRector`
- class: [`Rector\DoctrineCodeQuality\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector`](/rules/doctrine-code-quality/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php)
- [test fixtures](/rules/doctrine-code-quality/tests/Rector/Property/MoveCurrentDateTimeDefaultInEntityToConstructorRector/Fixture)
- [test fixtures](/rules/doctrine-code-quality/tests/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector/Fixture)
Move default value for entity property to constructor, the safest place
@ -6581,7 +6581,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
### `NormalToFluentRector`
- class: [`Rector\Generic\Rector\ClassMethod\NormalToFluentRector`](/rules/generic/src/Rector/ClassMethod/NormalToFluentRector.php)
- [test fixtures](/rules/generic/tests/Rector/MethodCall/NormalToFluentRector/Fixture)
- [test fixtures](/rules/generic/tests/Rector/ClassMethod/NormalToFluentRector/Fixture)
Turns fluent interface calls to classic ones.
@ -6915,50 +6915,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
<br><br>
### `ReplaceParentCallByPropertyCallRector`
- class: [`Rector\Generic\Rector\MethodCall\ReplaceParentCallByPropertyCallRector`](/rules/generic/src/Rector/MethodCall/ReplaceParentCallByPropertyCallRector.php)
- [test fixtures](/rules/transform/tests/Rector/MethodCall/ReplaceParentCallByPropertyCallRector/Fixture)
Changes method calls in child of specific types to defined property method call
```php
<?php
declare(strict_types=1);
use Rector\Generic\Rector\MethodCall\ReplaceParentCallByPropertyCallRector;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\Transform\ValueObject\ReplaceParentCallByPropertyCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ReplaceParentCallByPropertyCallRector::class)
->call('configure', [[
ReplaceParentCallByPropertyCallRector::PARENT_CALLS_TO_PROPERTIES => inline_value_objects([
new ReplaceParentCallByPropertyCall('SomeTypeToReplace', 'someMethodCall', 'someProperty'),
]),
]]);
};
```
```diff
final class SomeClass
{
public function run(SomeTypeToReplace $someTypeToReplace)
{
- $someTypeToReplace->someMethodCall();
+ $this->someProperty->someMethodCall();
}
}
```
<br><br>
### `ReplaceVariableByPropertyFetchRector`
- class: [`Rector\Generic\Rector\Variable\ReplaceVariableByPropertyFetchRector`](/rules/generic/src/Rector/Variable/ReplaceVariableByPropertyFetchRector.php)
@ -8975,7 +8931,7 @@ Changes event names from Nette ones to Symfony ones
### `RouterListToControllerAnnotationsRector`
- class: [`Rector\NetteToSymfony\Rector\ClassMethod\RouterListToControllerAnnotationsRector`](/rules/nette-to-symfony/src/Rector/ClassMethod/RouterListToControllerAnnotationsRector.php)
- [test fixtures](/rules/nette-to-symfony/tests/Rector/ClassMethod/RouterListToControllerAnnotationsRetor/Fixture)
- [test fixtures](/rules/nette-to-symfony/tests/Rector/ClassMethod/RouterListToControllerAnnotationsRector/Fixture)
Change new `Route()` from RouteFactory to @Route annotation above controller method
@ -11909,7 +11865,6 @@ Changes heredoc/nowdoc that contains closing word to safe wrapper name
### `SetCookieRector`
- class: [`Rector\Php73\Rector\FuncCall\SetCookieRector`](/rules/php73/src/Rector/FuncCall/SetCookieRector.php)
- [test fixtures](/rules/php73/tests/Rector/FuncCall/SetcookieRector/Fixture)
Convert `setcookie` argument to PHP7.3 option array
@ -15997,6 +15952,50 @@ return static function (ContainerConfigurator $containerConfigurator): void {
<br><br>
### `ReplaceParentCallByPropertyCallRector`
- class: [`Rector\Transform\Rector\MethodCall\ReplaceParentCallByPropertyCallRector`](/rules/transform/src/Rector/MethodCall/ReplaceParentCallByPropertyCallRector.php)
- [test fixtures](/rules/transform/tests/Rector/MethodCall/ReplaceParentCallByPropertyCallRector/Fixture)
Changes method calls in child of specific types to defined property method call
```php
<?php
declare(strict_types=1);
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\Transform\Rector\MethodCall\ReplaceParentCallByPropertyCallRector;
use Rector\Transform\ValueObject\ReplaceParentCallByPropertyCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ReplaceParentCallByPropertyCallRector::class)
->call('configure', [[
ReplaceParentCallByPropertyCallRector::PARENT_CALLS_TO_PROPERTIES => inline_value_objects([
new ReplaceParentCallByPropertyCall('SomeTypeToReplace', 'someMethodCall', 'someProperty'),
]),
]]);
};
```
```diff
final class SomeClass
{
public function run(SomeTypeToReplace $someTypeToReplace)
{
- $someTypeToReplace->someMethodCall();
+ $this->someProperty->someMethodCall();
}
}
```
<br><br>
### `ServiceGetterToConstructorInjectionRector`
- class: [`Rector\Transform\Rector\MethodCall\ServiceGetterToConstructorInjectionRector`](/rules/transform/src/Rector/MethodCall/ServiceGetterToConstructorInjectionRector.php)

View File

@ -1,122 +0,0 @@
<?php
namespace Rector\DeadCode\Tests\Rector\FunctionLike\RemoveOverriddenValuesRector\Fixture;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\Node\Manipulator\IfManipulator;
use Rector\PhpParser\Node\Manipulator\StmtsManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
/**
* @see https://engineering.helpscout.com/reducing-complexity-with-guard-clauses-in-php-and-javascript-74600fd865c7
*
* @see \Rector\SOLID\Tests\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector\ChangeIfElseValueAssignToEarlyReturnRectorTest
*/
final class ChangeIfElseValueAssignToEarlyReturnRector extends AbstractRector
{
/**
* @var IfManipulator
*/
private $ifManipulator;
/**
* @var StmtsManipulator
*/
private $stmtsManipulator;
public function __construct(IfManipulator $ifManipulator, StmtsManipulator $stmtsManipulator)
{
$this->ifManipulator = $ifManipulator;
$this->stmtsManipulator = $stmtsManipulator;
}
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Change if/else value to early return', [
new CodeSample(
<<<'PHP'
class SomeClass
{
public function run()
{
if ($this->hasDocBlock($tokens, $index)) {
$docToken = $tokens[$this->getDocBlockIndex($tokens, $index)];
} else {
$docToken = null;
}
return $docToken;
}
}
PHP
,
<<<'PHP'
class SomeClass
{
public function run()
{
if ($this->hasDocBlock($tokens, $index)) {
return $tokens[$this->getDocBlockIndex($tokens, $index)];
}
return null;
}
}
PHP
),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [If_::class];
}
/**
* @param If_ $node
*/
public function refactor(Node $node): ?Node
{
$nextNode = $node->getAttribute(AttributeKey::NEXT_NODE);
if (! $nextNode instanceof Return_) {
return null;
}
if ($nextNode->expr === null) {
return null;
}
if (! $this->ifManipulator->isIfAndElseWithSameVariableAssignAsLastStmts($node, $nextNode->expr)) {
return null;
}
$lastIfStmtKey = array_key_last($node->stmts);
/** @var Assign $assign */
$assign = $this->stmtsManipulator->getUnwrappedLastStmt($node->stmts);
$node->stmts[$lastIfStmtKey] = new Return_($assign->expr);
/** @var Assign $assign */
$assign = $this->stmtsManipulator->getUnwrappedLastStmt($node->else->stmts);
$lastElseStmtKey = array_key_last($node->else->stmts);
$elseStmts = $node->else->stmts;
$elseStmts[$lastElseStmtKey] = new Return_($assign->expr);
$node->else = null;
$this->addNodesAfterNode($elseStmts, $node);
$this->removeNode($nextNode);
return $node;
}
}

View File

@ -22,7 +22,7 @@ use Rector\DoctrineCodeQuality\NodeManipulator\ConstructorManipulator;
*
* @see https://stackoverflow.com/a/7698687/1348344
*
* @see \Rector\DoctrineCodeQuality\Tests\Rector\Property\MoveCurrentDateTimeDefaultInEntityToConstructorRector\MoveCurrentDateTimeDefaultInEntityToConstructorRectorTest
* @see \Rector\DoctrineCodeQuality\Tests\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector\MoveCurrentDateTimeDefaultInEntityToConstructorRectorTest
*/
final class MoveCurrentDateTimeDefaultInEntityToConstructorRector extends AbstractRector
{

View File

@ -20,8 +20,7 @@ use Rector\NodeTypeResolver\Node\AttributeKey;
/**
* @see https://github.com/doctrine/orm/blob/2.7/UPGRADE.md#query-querybuilder-and-nativequery-parameters-bc-break
*
* @see \Rector\DoctrineCodeQuality\Tests\Rector\MethodCall\ChangeQuerySetParametersMethodParameterFromArrayToArrayCollection\ChangeQuerySetParametersMethodParameterFromArrayToArrayCollectionRectorTest
* @see \Rector\DoctrineCodeQuality\Tests\Rector\MethodCall\ChangeQuerySetParametersMethodParameterFromArrayToArrayCollectionRector\ChangeQuerySetParametersMethodParameterFromArrayToArrayCollectionRectorTest
*/
final class ChangeQuerySetParametersMethodParameterFromArrayToArrayCollectionRector extends AbstractRector
{

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\DoctrineCodeQuality\Tests\Rector\Property\MoveCurrentDateTimeDefaultInEntityToConstructorRector\Fixture;
namespace Rector\DoctrineCodeQuality\Tests\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector\Fixture;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
@ -27,7 +27,7 @@ class AlreadyConstructor
-----
<?php
namespace Rector\DoctrineCodeQuality\Tests\Rector\Property\MoveCurrentDateTimeDefaultInEntityToConstructorRector\Fixture;
namespace Rector\DoctrineCodeQuality\Tests\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector\Fixture;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\DoctrineCodeQuality\Tests\Rector\Property\MoveCurrentDateTimeDefaultInEntityToConstructorRector\Fixture;
namespace Rector\DoctrineCodeQuality\Tests\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector\Fixture;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
@ -22,7 +22,7 @@ class User
-----
<?php
namespace Rector\DoctrineCodeQuality\Tests\Rector\Property\MoveCurrentDateTimeDefaultInEntityToConstructorRector\Fixture;
namespace Rector\DoctrineCodeQuality\Tests\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector\Fixture;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\DoctrineCodeQuality\Tests\Rector\Property\MoveCurrentDateTimeDefaultInEntityToConstructorRector\Fixture;
namespace Rector\DoctrineCodeQuality\Tests\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector\Fixture;
use DateTime;
use DateTimeInterface;

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\DoctrineCodeQuality\Tests\Rector\Property\MoveCurrentDateTimeDefaultInEntityToConstructorRector\Fixture;
namespace Rector\DoctrineCodeQuality\Tests\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector\Fixture;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\DoctrineCodeQuality\Tests\Rector\Property\MoveCurrentDateTimeDefaultInEntityToConstructorRector;
namespace Rector\DoctrineCodeQuality\Tests\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector;
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\DoctrineCodeQuality\Tests\Rector\MethodCall\ChangeQuerySetParametersMethodParameterFromArrayToArrayCollection;
namespace Rector\DoctrineCodeQuality\Tests\Rector\MethodCall\ChangeQuerySetParametersMethodParameterFromArrayToArrayCollectionRector;
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\DoctrineCodeQuality\Tests\Rector\MethodCall\ChangeQuerySetParametersMethodParameterFromArrayToArrayCollection\Fixture;
namespace Rector\DoctrineCodeQuality\Tests\Rector\MethodCall\ChangeQuerySetParametersMethodParameterFromArrayToArrayCollectionRector\Fixture;
use Doctrine\ORM\EntityRepository;
@ -24,7 +24,7 @@ class SomeRepository extends EntityRepository
-----
<?php
namespace Rector\DoctrineCodeQuality\Tests\Rector\MethodCall\ChangeQuerySetParametersMethodParameterFromArrayToArrayCollection\Fixture;
namespace Rector\DoctrineCodeQuality\Tests\Rector\MethodCall\ChangeQuerySetParametersMethodParameterFromArrayToArrayCollectionRector\Fixture;
use Doctrine\ORM\EntityRepository;

View File

@ -10,7 +10,6 @@ use Rector\Core\RectorDefinition\RectorDefinition;
/**
* @see \Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\DowngradeTypedPropertyRectorTest
* @see \Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\DowngradeTypedPropertyRectorTest
*/
final class DowngradeTypedPropertyRector extends AbstractDowngradeTypedPropertyRector
{

View File

@ -0,0 +1,25 @@
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\FixtureNoDocBlock;
use Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\SourceNoDocBlock\AnotherClass;
class ClassNameNullableTypeClass
{
private ?AnotherClass $property;
}
?>
-----
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\FixtureNoDocBlock;
use Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\SourceNoDocBlock\AnotherClass;
class ClassNameNullableTypeClass
{
private $property;
}
?>

View File

@ -0,0 +1,19 @@
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\FixtureNoDocBlock;
class ClassNameClass {
private \Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\SourceNoDocBlock\AnotherClass $property;
}
?>
-----
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\FixtureNoDocBlock;
class ClassNameClass {
private $property;
}
?>

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Fixture;
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\FixtureNoDocBlock;
class DocBlockExists {
/**
@ -13,7 +13,7 @@ class DocBlockExists {
-----
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Fixture;
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\FixtureNoDocBlock;
class DocBlockExists {
/**

View File

@ -0,0 +1,21 @@
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\FixtureNoDocBlock;
class SomeClass
{
private string $property;
}
?>
-----
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\FixtureNoDocBlock;
class SomeClass
{
private $property;
}
?>

View File

@ -0,0 +1,19 @@
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\FixtureNoDocBlock;
class NullableTypeClass {
private ?string $property;
}
?>
-----
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\FixtureNoDocBlock;
class NullableTypeClass {
private $property;
}
?>

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector;
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector;
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
@ -10,7 +10,7 @@ use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector;
use Symplify\SmartFileSystem\SmartFileInfo;
final class DowngradeTypedPropertyRectorTest extends AbstractRectorTestCase
final class NoDocBlockTest extends AbstractRectorTestCase
{
/**
* @requires PHP 7.4
@ -23,7 +23,7 @@ final class DowngradeTypedPropertyRectorTest extends AbstractRectorTestCase
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureNoDocBlock');
}
/**

View File

@ -1,9 +1,7 @@
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\Source;
class AnotherClass
{

View File

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\SourceNoDocBlock;
final class AnotherClass
{
}

View File

@ -1,25 +0,0 @@
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Fixture;
use Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Source\AnotherClass;
class ClassNameNullableTypeClass
{
private ?AnotherClass $property;
}
?>
-----
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Fixture;
use Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Source\AnotherClass;
class ClassNameNullableTypeClass
{
private $property;
}
?>

View File

@ -1,19 +0,0 @@
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Fixture;
class ClassNameClass {
private \Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Source\AnotherClass $property;
}
?>
-----
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Fixture;
class ClassNameClass {
private $property;
}
?>

View File

@ -1,21 +0,0 @@
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Fixture;
class SomeClass
{
private string $property;
}
?>
-----
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Fixture;
class SomeClass
{
private $property;
}
?>

View File

@ -1,19 +0,0 @@
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Fixture;
class NullableTypeClass {
private ?string $property;
}
?>
-----
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Fixture;
class NullableTypeClass {
private $property;
}
?>

View File

@ -1,10 +0,0 @@
<?php
namespace Rector\DowngradePhp74\Tests\Rector\Property\NoDocBlockDowngradeTypedPropertyRector\Source;
class AnotherClass
{
}

View File

@ -17,7 +17,7 @@ use Rector\Generic\ValueObject\NormalToFluent;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\NormalToFluentRectorTest
* @see \Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\NormalToFluentRectorTest
*/
final class NormalToFluentRector extends AbstractRector implements ConfigurableRectorInterface
{

View File

@ -1,8 +1,8 @@
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Fixture;
namespace Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Source\FluentInterfaceClass;
use Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Source\FluentInterfaceClass;
class ActionClass
{
@ -18,9 +18,9 @@ class ActionClass
-----
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Fixture;
namespace Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Source\FluentInterfaceClass;
use Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Source\FluentInterfaceClass;
class ActionClass
{

View File

@ -1,8 +1,8 @@
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Fixture;
namespace Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Source\FluentInterfaceClass;
use Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Source\FluentInterfaceClass;
class ActionClass2
{
@ -18,9 +18,9 @@ class ActionClass2
-----
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Fixture;
namespace Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Source\FluentInterfaceClass;
use Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Source\FluentInterfaceClass;
class ActionClass2
{

View File

@ -1,8 +1,8 @@
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Fixture;
namespace Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Source\FluentInterfaceClass;
use Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Source\FluentInterfaceClass;
class ActionClass3
{
@ -19,9 +19,9 @@ class ActionClass3
-----
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Fixture;
namespace Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Source\FluentInterfaceClass;
use Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Source\FluentInterfaceClass;
class ActionClass3
{

View File

@ -1,8 +1,8 @@
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Fixture;
namespace Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Source\FluentInterfaceClass;
use Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Source\FluentInterfaceClass;
class ActionClass4
{
@ -19,9 +19,9 @@ class ActionClass4
-----
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Fixture;
namespace Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Source\FluentInterfaceClass;
use Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Source\FluentInterfaceClass;
class ActionClass4
{

View File

@ -2,12 +2,12 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector;
namespace Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector;
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Generic\Rector\ClassMethod\NormalToFluentRector;
use Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Source\FluentInterfaceClass;
use Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Source\FluentInterfaceClass;
use Rector\Generic\ValueObject\NormalToFluent;
use Symplify\SmartFileSystem\SmartFileInfo;

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassMethod\NormalToFluentRector\Source;
final class FluentInterfaceClass
{
}

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\MethodCall\NormalToFluentRector\Source;
final class FluentInterfaceClass
{
}

View File

@ -29,7 +29,7 @@ use ReflectionMethod;
* @see https://doc.nette.org/en/2.4/routing
* @see https://symfony.com/doc/current/routing.html
*
* @see \Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor\RouterListToControllerAnnotationsRectorTest
* @see \Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRector\RouterListToControllerAnnotationsRectorTest
*/
final class RouterListToControllerAnnotationsRector extends AbstractRector
{

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor\Fixture;
namespace Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRector\Fixture;
use Nette\Application\Routers\Route;
use Nette\Application\Routers\RouteList;
@ -31,7 +31,7 @@ final class GeneralMethodNamedRoutesSomePresenter
-----
<?php
namespace Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor\Fixture;
namespace Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRector\Fixture;
use Symfony\Component\Routing\Annotation\Route;
use Nette\Application\Routers\RouteList;

View File

@ -3,7 +3,7 @@
namespace Rector\NetteToSymfony\Tests\Rector\MethodCall\RouterListToControllerAnnotationsRetor\Fixture;
use Nette\Application\Routers\RouteList;
use Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor\Source\RouteFactory;
use Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRector\Source\RouteFactory;
final class StaticRouterFactory
{
@ -33,7 +33,7 @@ namespace Rector\NetteToSymfony\Tests\Rector\MethodCall\RouterListToControllerAn
use Symfony\Component\Routing\Annotation\Route;
use Nette\Application\Routers\RouteList;
use Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor\Source\RouteFactory;
use Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRector\Source\RouteFactory;
final class StaticRouterFactory
{

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor;
namespace Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRector;
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor\Source;
namespace Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRector\Source;
final class Route
{

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor\Source;
namespace Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRector\Source;
use Nette\Application\Routers\Route;

View File

@ -97,6 +97,8 @@ CODE_SAMPLE
$seeTagNode = $this->createSeePhpDocTagNode($testCaseClassName);
$phpDocInfo->addPhpDocTagNode($seeTagNode);
$this->notifyNodeFileInfo($node);
return $node;
}

View File

@ -43,16 +43,38 @@ final class TestClassResolver
return $className . self::TEST;
}
$shortClassName = Strings::after($className, '\\', -1);
$shortClassName = $this->resolveShortClassName($className);
$testShortClassName = $shortClassName . self::TEST;
$phpUnitTestCaseClasses = $this->phpUnitTestCaseClassesProvider->provide();
sort($phpUnitTestCaseClasses);
foreach ($phpUnitTestCaseClasses as $declaredClass) {
if (Strings::endsWith($declaredClass, '\\' . $testShortClassName)) {
return $declaredClass;
$classNamespaceParts = $this->resolveNamespaceParts($className);
$classNamespaceParts[] = 'Tests';
sort($classNamespaceParts);
foreach ($phpUnitTestCaseClasses as $phpUnitTestCaseClass) {
// 1. is short class match
if (! Strings::endsWith($phpUnitTestCaseClass, '\\' . $testShortClassName)) {
continue;
}
// 2. is namespace match
$phpUnitTestNamespaceParts = $this->resolveNamespaceParts($phpUnitTestCaseClass);
sort($phpUnitTestNamespaceParts);
$nestedPhpUnitTestNamespaceParts = array_merge($classNamespaceParts, [$shortClassName]);
sort($nestedPhpUnitTestNamespaceParts);
if ($classNamespaceParts === $phpUnitTestNamespaceParts) {
return $phpUnitTestCaseClass;
}
if ($nestedPhpUnitTestNamespaceParts === $phpUnitTestNamespaceParts) {
return $phpUnitTestCaseClass;
}
return null;
}
return null;
@ -67,4 +89,18 @@ final class TestClassResolver
return $this->resolveFromClassName($className);
}
private function resolveShortClassName(string $className): ?string
{
return Strings::after($className, '\\', -1);
}
/**
* @return string[]
*/
private function resolveNamespaceParts(string $className): array
{
$namespacePart = (string) Strings::before($className, '\\', -1);
return explode('\\', $namespacePart);
}
}

View File

@ -1,26 +0,0 @@
<?php
namespace Rector\PHPUnit\Tests\Rector\Class_\AddSeeTestAnnotationRector\Fixture;
/**
* This is here
*/
class DifferentNamespace
{
}
?>
-----
<?php
namespace Rector\PHPUnit\Tests\Rector\Class_\AddSeeTestAnnotationRector\Fixture;
/**
* This is here
* @see \Rector\PHPUnit\Tests\Rector\Class_\AddSeeTestAnnotationRector\Source\DifferentNamespaceTest
*/
class DifferentNamespace
{
}
?>

View File

@ -0,0 +1,10 @@
<?php
namespace Rector\PHPUnit\Tests\Rector\Class_\AddSeeTestAnnotationRector\Fixture;
/**
* This is here
*/
class SkipDifferentNamespace
{
}

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Rector\PHPUnit\Tests\TestClassResolver\Source;
final class SeeSomeClass
{
}

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Rector\PHPUnit\Tests\TestClassResolver\Source;
use PHPUnit\Framework\TestCase;
final class SeeSomeClassTest extends TestCase
{
}

View File

@ -11,6 +11,8 @@ use Rector\DowngradePhp74\Tests\Rector\Property\DowngradeTypedPropertyRector\Dow
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\TypedPropertyRectorTest;
use Rector\PHPUnit\TestClassResolver\TestClassResolver;
use Rector\PHPUnit\Tests\TestClassResolver\Source\SeeSomeClass;
use Rector\PHPUnit\Tests\TestClassResolver\Source\SeeSomeClassTest;
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
final class TestClassResolverTest extends AbstractKernelTestCase
@ -37,6 +39,7 @@ final class TestClassResolverTest extends AbstractKernelTestCase
public function provideData(): Iterator
{
yield [SeeSomeClass::class, SeeSomeClassTest::class];
yield [TypedPropertyRector::class, TypedPropertyRectorTest::class];
yield [DowngradeTypedPropertyRector::class, DowngradeTypedPropertyRectorTest::class];
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\MethodCall;
namespace Rector\Transform\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;

View File

@ -6,7 +6,7 @@ namespace Rector\Transform\Tests\Rector\MethodCall\ReplaceParentCallByPropertyCa
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Generic\Rector\MethodCall\ReplaceParentCallByPropertyCallRector;
use Rector\Transform\Rector\MethodCall\ReplaceParentCallByPropertyCallRector;
use Rector\Transform\Tests\Rector\MethodCall\ReplaceParentCallByPropertyCallRector\Source\TypeClassToReplaceMethodCallBy;
use Rector\Transform\ValueObject\ReplaceParentCallByPropertyCall;
use Symplify\SmartFileSystem\SmartFileInfo;