diff --git a/config/sets/composer-based.php b/config/sets/composer-based.php new file mode 100644 index 00000000..6f9ea7f0 --- /dev/null +++ b/config/sets/composer-based.php @@ -0,0 +1,57 @@ +rules([ + TicketAnnotationToAttributeRector::class, + TestWithAnnotationToAttributeRector::class, + DataProviderAnnotationToAttributeRector::class, + CoversAnnotationWithValueToAttributeRector::class, + RequiresAnnotationWithValueToAttributeRector::class, + DependsAnnotationWithValueToAttributeRector::class, + ]); + + // both attributes were added in PHPUnit 10.0 + $rectorConfig->ruleWithConfigurationComposerVersionBound(AnnotationWithValueToAttributeRector::class, [ + // the PHPUnit 10 spelling of the "backupStaticAttributes" annotation + new AnnotationWithValueToAttribute( + 'backupStaticProperties', + 'PHPUnit\Framework\Attributes\BackupStaticProperties', + [ + 'enabled' => true, + 'disabled' => false, + ] + ), + new AnnotationWithValueToAttribute( + 'excludeGlobalVariableFromBackup', + 'PHPUnit\Framework\Attributes\ExcludeGlobalVariableFromBackup' + ), + ], 'phpunit/phpunit', '>=10.0'); + + // the RunClassInSeparateProcess attribute was added in PHPUnit 10.0 and removed in PHPUnit 13.0 + $rectorConfig->ruleWithConfigurationComposerVersionBound(AnnotationToAttributeRector::class, [ + new AnnotationToAttribute( + 'runClassInSeparateProcess', + 'PHPUnit\Framework\Attributes\RunClassInSeparateProcess' + ), + ], 'phpunit/phpunit', '>=10.0 <13.0'); +}; diff --git a/rules/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php index 735c4e58..51d8a6e5 100644 --- a/rules/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php @@ -22,14 +22,16 @@ use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; use Rector\ValueObject\PhpVersion; +use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface; use Rector\VersionBonding\Contract\MinPhpVersionInterface; +use Rector\VersionBonding\ValueObject\ComposerPackageConstraint; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\ClassMethod\DataProviderAnnotationToAttributeRector\DataProviderAnnotationToAttributeRectorTest */ -final class DataProviderAnnotationToAttributeRector extends AbstractRector implements MinPhpVersionInterface +final class DataProviderAnnotationToAttributeRector extends AbstractRector implements MinPhpVersionInterface, ComposerPackageConstraintInterface { public function __construct( private readonly TestsNodeAnalyzer $testsNodeAnalyzer, @@ -84,6 +86,11 @@ public function getNodeTypes(): array return [ClassMethod::class]; } + public function provideComposerPackageConstraint(): ComposerPackageConstraint + { + return new ComposerPackageConstraint('phpunit/phpunit', '>=10.0'); + } + public function provideMinPhpVersion(): int { /** diff --git a/rules/AnnotationsToAttributes/Rector/ClassMethod/DependsAnnotationWithValueToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/ClassMethod/DependsAnnotationWithValueToAttributeRector.php index 547f7a4a..8d2e6a7c 100644 --- a/rules/AnnotationsToAttributes/Rector/ClassMethod/DependsAnnotationWithValueToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/ClassMethod/DependsAnnotationWithValueToAttributeRector.php @@ -18,14 +18,16 @@ use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; +use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface; use Rector\VersionBonding\Contract\MinPhpVersionInterface; +use Rector\VersionBonding\ValueObject\ComposerPackageConstraint; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\ClassMethod\DependsAnnotationWithValueToAttributeRector\DependsAnnotationWithValueToAttributeRectorTest */ -final class DependsAnnotationWithValueToAttributeRector extends AbstractRector implements MinPhpVersionInterface +final class DependsAnnotationWithValueToAttributeRector extends AbstractRector implements MinPhpVersionInterface, ComposerPackageConstraintInterface { private const string DEPENDS_ATTRIBUTE = 'PHPUnit\Framework\Attributes\Depends'; @@ -85,6 +87,11 @@ public function getNodeTypes(): array return [Class_::class]; } + public function provideComposerPackageConstraint(): ComposerPackageConstraint + { + return new ComposerPackageConstraint('phpunit/phpunit', '>=10.0'); + } + public function provideMinPhpVersion(): int { return PhpVersionFeature::ATTRIBUTES; diff --git a/rules/AnnotationsToAttributes/Rector/ClassMethod/TestWithAnnotationToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/ClassMethod/TestWithAnnotationToAttributeRector.php index 763cfda7..3751915d 100644 --- a/rules/AnnotationsToAttributes/Rector/ClassMethod/TestWithAnnotationToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/ClassMethod/TestWithAnnotationToAttributeRector.php @@ -18,7 +18,9 @@ use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; +use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface; use Rector\VersionBonding\Contract\MinPhpVersionInterface; +use Rector\VersionBonding\ValueObject\ComposerPackageConstraint; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -28,7 +30,7 @@ * * @see \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\ClassMethod\TestWithAnnotationToAttributeRector\TestWithAnnotationToAttributeRectorTest */ -final class TestWithAnnotationToAttributeRector extends AbstractRector implements MinPhpVersionInterface +final class TestWithAnnotationToAttributeRector extends AbstractRector implements MinPhpVersionInterface, ComposerPackageConstraintInterface { private const string TEST_WITH_ATTRIBUTE = 'PHPUnit\Framework\Attributes\TestWith'; @@ -148,6 +150,11 @@ public function refactor(Node $node): ?Node return $node; } + public function provideComposerPackageConstraint(): ComposerPackageConstraint + { + return new ComposerPackageConstraint('phpunit/phpunit', '>=10.0'); + } + public function provideMinPhpVersion(): int { return PhpVersionFeature::ATTRIBUTES; diff --git a/rules/AnnotationsToAttributes/Rector/Class_/AnnotationWithValueToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/Class_/AnnotationWithValueToAttributeRector.php index f206d943..66c7ac5b 100644 --- a/rules/AnnotationsToAttributes/Rector/Class_/AnnotationWithValueToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/Class_/AnnotationWithValueToAttributeRector.php @@ -19,7 +19,9 @@ use Rector\PHPUnit\ValueObject\AnnotationWithValueToAttribute; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; +use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface; use Rector\VersionBonding\Contract\MinPhpVersionInterface; +use Rector\VersionBonding\ValueObject\ComposerPackageConstraint; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Webmozart\Assert\Assert; @@ -27,7 +29,7 @@ /** * @see \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\AnnotationWithValueToAttributeRector\AnnotationWithValueToAttributeRectorTest */ -final class AnnotationWithValueToAttributeRector extends AbstractRector implements ConfigurableRectorInterface, MinPhpVersionInterface +final class AnnotationWithValueToAttributeRector extends AbstractRector implements ConfigurableRectorInterface, MinPhpVersionInterface, ComposerPackageConstraintInterface { /** * @var AnnotationWithValueToAttribute[] @@ -89,6 +91,11 @@ public function getNodeTypes(): array return [Class_::class]; } + public function provideComposerPackageConstraint(): ComposerPackageConstraint + { + return new ComposerPackageConstraint('phpunit/phpunit', '>=10.0'); + } + public function provideMinPhpVersion(): int { return PhpVersionFeature::ATTRIBUTES; diff --git a/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php index aa1cd15f..d4ad0ed0 100644 --- a/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php @@ -19,14 +19,16 @@ use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; +use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface; use Rector\VersionBonding\Contract\MinPhpVersionInterface; +use Rector\VersionBonding\ValueObject\ComposerPackageConstraint; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\CoversAnnotationWithValueToAttributeRectorTest */ -final class CoversAnnotationWithValueToAttributeRector extends AbstractRector implements MinPhpVersionInterface +final class CoversAnnotationWithValueToAttributeRector extends AbstractRector implements MinPhpVersionInterface, ComposerPackageConstraintInterface { private const string COVERS_FUNCTION_ATTRIBUTE = 'PHPUnit\Framework\Attributes\CoversFunction'; @@ -94,6 +96,11 @@ public function getNodeTypes(): array return [Class_::class, ClassMethod::class]; } + public function provideComposerPackageConstraint(): ComposerPackageConstraint + { + return new ComposerPackageConstraint('phpunit/phpunit', '>=10.0'); + } + public function provideMinPhpVersion(): int { return PhpVersionFeature::ATTRIBUTES; diff --git a/rules/AnnotationsToAttributes/Rector/Class_/RequiresAnnotationWithValueToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/Class_/RequiresAnnotationWithValueToAttributeRector.php index 402517f3..7d081e31 100644 --- a/rules/AnnotationsToAttributes/Rector/Class_/RequiresAnnotationWithValueToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/Class_/RequiresAnnotationWithValueToAttributeRector.php @@ -17,14 +17,16 @@ use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; +use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface; use Rector\VersionBonding\Contract\MinPhpVersionInterface; +use Rector\VersionBonding\ValueObject\ComposerPackageConstraint; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\RequiresAnnotationWithValueToAttributeRector\RequiresAnnotationWithValueToAttributeRectorTest */ -final class RequiresAnnotationWithValueToAttributeRector extends AbstractRector implements MinPhpVersionInterface +final class RequiresAnnotationWithValueToAttributeRector extends AbstractRector implements MinPhpVersionInterface, ComposerPackageConstraintInterface { public function __construct( private readonly PhpDocTagRemover $phpDocTagRemover, @@ -84,6 +86,11 @@ public function getNodeTypes(): array return [Class_::class, ClassMethod::class]; } + public function provideComposerPackageConstraint(): ComposerPackageConstraint + { + return new ComposerPackageConstraint('phpunit/phpunit', '>=10.0'); + } + public function provideMinPhpVersion(): int { return PhpVersionFeature::ATTRIBUTES; diff --git a/rules/AnnotationsToAttributes/Rector/Class_/TicketAnnotationToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/Class_/TicketAnnotationToAttributeRector.php index 2e18c3ae..b978b9ad 100644 --- a/rules/AnnotationsToAttributes/Rector/Class_/TicketAnnotationToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/Class_/TicketAnnotationToAttributeRector.php @@ -22,7 +22,9 @@ use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; +use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface; use Rector\VersionBonding\Contract\MinPhpVersionInterface; +use Rector\VersionBonding\ValueObject\ComposerPackageConstraint; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -31,7 +33,7 @@ * * @see \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\TicketAnnotationToAttributeRector\TicketAnnotationToAttributeRectorTest */ -final class TicketAnnotationToAttributeRector extends AbstractRector implements MinPhpVersionInterface +final class TicketAnnotationToAttributeRector extends AbstractRector implements MinPhpVersionInterface, ComposerPackageConstraintInterface { private const string TICKET_CLASS = 'PHPUnit\Framework\Attributes\Ticket'; @@ -81,6 +83,11 @@ public function getNodeTypes(): array return [Class_::class, ClassMethod::class]; } + public function provideComposerPackageConstraint(): ComposerPackageConstraint + { + return new ComposerPackageConstraint('phpunit/phpunit', '>=10.0'); + } + public function provideMinPhpVersion(): int { return PhpVersionFeature::ATTRIBUTES; diff --git a/src/Set/PHPUnitSetList.php b/src/Set/PHPUnitSetList.php index b1d64ead..f24a9952 100644 --- a/src/Set/PHPUnitSetList.php +++ b/src/Set/PHPUnitSetList.php @@ -36,4 +36,6 @@ final class PHPUnitSetList public const string PHPUNIT_NARROW_ASSERTS = __DIR__ . '/../../config/sets/phpunit-narrow-asserts.php'; public const string ANNOTATIONS_TO_ATTRIBUTES = __DIR__ . '/../../config/sets/annotations-to-attributes.php'; + + public const string COMPOSER_BASED = __DIR__ . '/../../config/sets/composer-based.php'; } diff --git a/tests/ComposerBased/ComposerBasedTest.php b/tests/ComposerBased/ComposerBasedTest.php new file mode 100644 index 00000000..eec4477d --- /dev/null +++ b/tests/ComposerBased/ComposerBasedTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/composer_based.php'; + } +} diff --git a/tests/ComposerBased/Fixture/backup_static_properties.php.inc b/tests/ComposerBased/Fixture/backup_static_properties.php.inc new file mode 100644 index 00000000..dc0b3123 --- /dev/null +++ b/tests/ComposerBased/Fixture/backup_static_properties.php.inc @@ -0,0 +1,41 @@ + +----- + diff --git a/tests/ComposerBased/Fixture/skip_run_class_in_separate_process.php.inc b/tests/ComposerBased/Fixture/skip_run_class_in_separate_process.php.inc new file mode 100644 index 00000000..70ac5621 --- /dev/null +++ b/tests/ComposerBased/Fixture/skip_run_class_in_separate_process.php.inc @@ -0,0 +1,13 @@ +sets([PHPUnitSetList::COMPOSER_BASED]); +};