diff --git a/rector.php b/rector.php index 437e3d36f..29227a82a 100644 --- a/rector.php +++ b/rector.php @@ -11,6 +11,8 @@ use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodParameterRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector; use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector; use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; @@ -104,9 +106,24 @@ // used by Configurator __DIR__ . '/src/Scaffolder/src/Command', ], + + \Rector\PHPUnit\PHPUnit100\Rector\MethodCall\AssertIssetToAssertObjectHasPropertyRector::class => [ + // ArrayAccess usage + __DIR__ . '/src/Session/tests/SessionTest.php', + ], + + // nullable @template usage, see https://github.com/rectorphp/rector-src/pull/6409 + // can be re-enabled on next rector release + RemoveUselessParamTagRector::class => [ + __DIR__ . '/src/Interceptors/src/Context/Target.php', + ], + + RemoveUselessReturnTagRector::class => [ + __DIR__ . '/src/Interceptors/src/Context/TargetInterface.php', + ], ]) ->withPhpSets(php81: true) - ->withPreparedSets(deadCode: true) + ->withPreparedSets(deadCode: true, phpunit: true) ->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [ ClassPropertyAssignToConstructorPromotionRector::RENAME_PROPERTY => false, ]); diff --git a/src/Core/tests/InjectableConfigTest.php b/src/Core/tests/InjectableConfigTest.php index 722257064..974df8443 100644 --- a/src/Core/tests/InjectableConfigTest.php +++ b/src/Core/tests/InjectableConfigTest.php @@ -12,6 +12,7 @@ use Spiral\Tests\Core\Fixtures\IntKeysConfig; use Spiral\Tests\Core\Fixtures\TestConfig; +#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Core\InjectableConfig::class)] class InjectableConfigTest extends TestCase { use AliasTrait; @@ -101,9 +102,6 @@ public function testGetError(): void $config['keyC']; } - /** - * @covers \Spiral\Core\InjectableConfig::__set_state() - */ public function testSerialize(): void { $config = new TestConfig([ diff --git a/src/Distribution/tests/ManagerTestCase.php b/src/Distribution/tests/ManagerTestCase.php index 135b673c5..c01bc5f59 100644 --- a/src/Distribution/tests/ManagerTestCase.php +++ b/src/Distribution/tests/ManagerTestCase.php @@ -7,9 +7,7 @@ use Spiral\Distribution\Manager; use Spiral\Distribution\Resolver\StaticResolver; -/** - * @group unit - */ +#[\PHPUnit\Framework\Attributes\Group('unit')] class ManagerTestCase extends TestCase { /** diff --git a/src/Distribution/tests/TestCase.php b/src/Distribution/tests/TestCase.php index bb90c87af..db126f608 100644 --- a/src/Distribution/tests/TestCase.php +++ b/src/Distribution/tests/TestCase.php @@ -8,9 +8,7 @@ use PHPUnit\Framework\TestCase as BaseTestCase; use Psr\Http\Message\UriInterface; -/** - * @group unit - */ +#[\PHPUnit\Framework\Attributes\Group('unit')] abstract class TestCase extends BaseTestCase { protected function uri(string $uri): UriInterface diff --git a/src/Encrypter/tests/EncrypterFactoryTest.php b/src/Encrypter/tests/EncrypterFactoryTest.php index b0d0d10ab..f326033e0 100644 --- a/src/Encrypter/tests/EncrypterFactoryTest.php +++ b/src/Encrypter/tests/EncrypterFactoryTest.php @@ -14,6 +14,7 @@ use Spiral\Encrypter\EncryptionInterface; use Spiral\Encrypter\Exception\EncrypterException; +#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Encrypter\EncrypterFactory::class)] class EncrypterFactoryTest extends TestCase { public function testInjection(): void @@ -79,9 +80,6 @@ public function testExceptionKey(): void echo $factory->getKey(); } - /** - * @covers \Spiral\Encrypter\EncrypterFactory::generateKey - */ public function testGenerateKey(): void { $key = Key::CreateNewRandomKey()->saveToAsciiSafeString(); diff --git a/src/Encrypter/tests/EncrypterTest.php b/src/Encrypter/tests/EncrypterTest.php index b4209701a..68a365abc 100644 --- a/src/Encrypter/tests/EncrypterTest.php +++ b/src/Encrypter/tests/EncrypterTest.php @@ -10,6 +10,7 @@ use Spiral\Encrypter\Exception\DecryptException; use Spiral\Encrypter\Exception\EncrypterException; +#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Encrypter\Encrypter::class)] class EncrypterTest extends TestCase { public function testImmutable(): void @@ -23,9 +24,6 @@ public function testImmutable(): void $this->assertEquals($keyB, $new->getKey()); } - /** - * @covers \Spiral\Encrypter\Encrypter::encrypt - */ public function testEncryption(): void { $encrypter = new Encrypter(Key::CreateNewRandomKey()->saveToAsciiSafeString()); diff --git a/src/Scaffolder/tests/Config/ScaffolderConfigTest.php b/src/Scaffolder/tests/Config/ScaffolderConfigTest.php index e34a46451..ad70928a7 100644 --- a/src/Scaffolder/tests/Config/ScaffolderConfigTest.php +++ b/src/Scaffolder/tests/Config/ScaffolderConfigTest.php @@ -115,9 +115,7 @@ public function testPartialOverrideDefaultDeclaration(): void $this->assertSame(BootloaderDeclaration::class, $ref->invoke($config, BootloaderDeclaration::TYPE, 'class')); } - /** - * @dataProvider declarationDirectoryDataProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('declarationDirectoryDataProvider')] public function testDeclarationDirectory(array $config, string $expected): void { $config = new ScaffolderConfig($config); @@ -125,9 +123,7 @@ public function testDeclarationDirectory(array $config, string $expected): void $this->assertSame($expected, $config->declarationDirectory('some')); } - /** - * @dataProvider classFilenameDataProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('classFilenameDataProvider')] public function testClassFilename(array $config, string $expected, string $namespace): void { $config = new ScaffolderConfig($config); diff --git a/src/Security/tests/GuardTest.php b/src/Security/tests/GuardTest.php index f5add45ec..c7359f8ef 100644 --- a/src/Security/tests/GuardTest.php +++ b/src/Security/tests/GuardTest.php @@ -17,12 +17,12 @@ class GuardTest extends TestCase public const CONTEXT = []; /** - * @var \PHPUnit_Framework_MockObject_MockObject|PermissionsInterface + * @var \PHPUnit\Framework\MockObject\MockObject|PermissionsInterface */ private $permission; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ActorInterface + * @var \PHPUnit\Framework\MockObject\MockObject|ActorInterface */ private $actor; diff --git a/src/Security/tests/RuleTest.php b/src/Security/tests/RuleTest.php index b3aabe436..59be1a6df 100644 --- a/src/Security/tests/RuleTest.php +++ b/src/Security/tests/RuleTest.php @@ -22,17 +22,17 @@ class RuleTest extends TestCase public const CONTEXT = []; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ActorInterface + * @var \PHPUnit\Framework\MockObject\MockObject|ActorInterface */ private $actor; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ResolverInterface + * @var \PHPUnit\Framework\MockObject\MockObject|ResolverInterface */ private $resolver; /** - * @var \PHPUnit_Framework_MockObject_MockObject|Rule + * @var \PHPUnit\Framework\MockObject\MockObject|Rule */ private $rule; diff --git a/src/Security/tests/Rules/CallableRuleTest.php b/src/Security/tests/Rules/CallableRuleTest.php index 1af470bb4..881101d74 100644 --- a/src/Security/tests/Rules/CallableRuleTest.php +++ b/src/Security/tests/Rules/CallableRuleTest.php @@ -20,7 +20,7 @@ public function testAllow(): void $actor = $this->createMock(ActorInterface::class); $context = []; - /** @var \PHPUnit_Framework_MockObject_MockObject|callable $callable */ + /** @var \PHPUnit\Framework\MockObject\MockObject|callable $callable */ $callable = $this->getMockBuilder(\stdClass::class) ->addMethods(['__invoke']) ->getMock(); diff --git a/src/Security/tests/Rules/CompositeRuleTest.php b/src/Security/tests/Rules/CompositeRuleTest.php index 29eb8426a..23a925451 100644 --- a/src/Security/tests/Rules/CompositeRuleTest.php +++ b/src/Security/tests/Rules/CompositeRuleTest.php @@ -19,7 +19,7 @@ class CompositeRuleTest extends TestCase public const CONTEXT = []; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ActorInterface $callable + * @var \PHPUnit\Framework\MockObject\MockObject|ActorInterface $callable */ private $actor; @@ -56,7 +56,7 @@ public static function allowsProvider(): \Traversable private function createRepository(array $rules): RulesInterface { - /** @var \PHPUnit_Framework_MockObject_MockObject|RulesInterface $repository */ + /** @var \PHPUnit\Framework\MockObject\MockObject|RulesInterface $repository */ $repository = $this->createMock(RulesInterface::class); $repository->method('get') diff --git a/src/Security/tests/Traits/GuardedTraitTest.php b/src/Security/tests/Traits/GuardedTraitTest.php index f55f4689d..74659177c 100644 --- a/src/Security/tests/Traits/GuardedTraitTest.php +++ b/src/Security/tests/Traits/GuardedTraitTest.php @@ -20,17 +20,17 @@ class GuardedTraitTest extends TestCase public const CONTEXT = []; /** - * @var \PHPUnit_Framework_MockObject_MockObject|GuardedTrait + * @var \PHPUnit\Framework\MockObject\MockObject|GuardedTrait */ private $trait; /** - * @var \PHPUnit_Framework_MockObject_MockObject|GuardInterface + * @var \PHPUnit\Framework\MockObject\MockObject|GuardInterface */ private $guard; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ContainerInterface + * @var \PHPUnit\Framework\MockObject\MockObject|ContainerInterface */ private $container; diff --git a/src/Stempler/tests/TraverserTest.php b/src/Stempler/tests/TraverserTest.php index 5dad5187d..884eff724 100644 --- a/src/Stempler/tests/TraverserTest.php +++ b/src/Stempler/tests/TraverserTest.php @@ -118,6 +118,7 @@ public function leaveNode(mixed $node, VisitorContext $ctx): mixed ); } + #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] public function testVisitorContext(): void { $doc = $this->parse('hello'); diff --git a/src/Storage/tests/FileTestCase.php b/src/Storage/tests/FileTestCase.php index d59a8b15d..b5b8d5c13 100644 --- a/src/Storage/tests/FileTestCase.php +++ b/src/Storage/tests/FileTestCase.php @@ -6,9 +6,7 @@ use Spiral\Storage\Visibility; -/** - * @group unit - */ +#[\PHPUnit\Framework\Attributes\Group('unit')] class FileTestCase extends TestCase { public function testPathname(): void diff --git a/src/Storage/tests/ManagerTestCase.php b/src/Storage/tests/ManagerTestCase.php index 64b70a1e3..db6179f0b 100644 --- a/src/Storage/tests/ManagerTestCase.php +++ b/src/Storage/tests/ManagerTestCase.php @@ -10,9 +10,7 @@ use Spiral\Storage\Bucket; use Spiral\Storage\Visibility; -/** - * @group unit - */ +#[\PHPUnit\Framework\Attributes\Group('unit')] class ManagerTestCase extends TestCase { /** diff --git a/src/Storage/tests/StorageTestCase.php b/src/Storage/tests/StorageTestCase.php index d099d05bb..4fd30328d 100644 --- a/src/Storage/tests/StorageTestCase.php +++ b/src/Storage/tests/StorageTestCase.php @@ -8,9 +8,7 @@ use Spiral\Storage\Bucket; use Spiral\Storage\Visibility; -/** - * @group unit - */ +#[\PHPUnit\Framework\Attributes\Group('unit')] class StorageTestCase extends TestCase { public function testCreate(): void diff --git a/src/Translator/tests/TraitTest.php b/src/Translator/tests/TraitTest.php index d0045c51b..d83119409 100644 --- a/src/Translator/tests/TraitTest.php +++ b/src/Translator/tests/TraitTest.php @@ -27,7 +27,7 @@ class TraitTest extends TestCase use TranslatorTrait; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ContainerInterface + * @var \PHPUnit\Framework\MockObject\MockObject|ContainerInterface */ private $container; diff --git a/tests/Framework/Command/CleanCommandTest.php b/tests/Framework/Command/CleanCommandTest.php index bc119bd56..4a1d196cf 100644 --- a/tests/Framework/Command/CleanCommandTest.php +++ b/tests/Framework/Command/CleanCommandTest.php @@ -9,9 +9,7 @@ use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; -/** - * @covers \Spiral\Command\CleanCommand - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Command\CleanCommand::class)] final class CleanCommandTest extends ConsoleTestCase { public int $defaultVerbosityLevel = OutputInterface::VERBOSITY_DEBUG; diff --git a/tests/Framework/Command/Views/CompileCommandTest.php b/tests/Framework/Command/Views/CompileCommandTest.php index aeb986f49..1fb24bf7e 100644 --- a/tests/Framework/Command/Views/CompileCommandTest.php +++ b/tests/Framework/Command/Views/CompileCommandTest.php @@ -8,10 +8,8 @@ use Spiral\Tests\Framework\ConsoleTestCase; use Symfony\Component\Console\Output\OutputInterface; -/** - * @covers \Spiral\Command\Views\ResetCommand - * @covers \Spiral\Command\Views\CompileCommand - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Command\Views\ResetCommand::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Command\Views\CompileCommand::class)] final class CompileCommandTest extends ConsoleTestCase { public int $defaultVerbosityLevel = OutputInterface::VERBOSITY_DEBUG; diff --git a/tests/Framework/Http/ErrorHandler/PlainRendererTest.php b/tests/Framework/Http/ErrorHandler/PlainRendererTest.php index 645bf0599..a40706794 100644 --- a/tests/Framework/Http/ErrorHandler/PlainRendererTest.php +++ b/tests/Framework/Http/ErrorHandler/PlainRendererTest.php @@ -11,9 +11,7 @@ use Psr\Http\Message\ResponseFactoryInterface; use Spiral\Http\ErrorHandler\PlainRenderer; -/** - * @coversDefaultClass \Spiral\Http\ErrorHandler\PlainRenderer - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Http\ErrorHandler\PlainRenderer::class)] final class PlainRendererTest extends TestCase { public function testContentTypeApplicationJson(): void