diff --git a/composer.json b/composer.json index f64ea2804..ca973d656 100644 --- a/composer.json +++ b/composer.json @@ -139,8 +139,7 @@ "spiral/validator": "^1.3", "google/protobuf": "^3.25", "symplify/monorepo-builder": "^10.2.7", - "vimeo/psalm": "^5.9", - "doctrine/annotations": "^1.12 || ^2.0" + "vimeo/psalm": "^5.9" }, "autoload-dev": { "psr-4": { diff --git a/src/AnnotatedRoutes/tests/App/Controller/HomeController.php b/src/AnnotatedRoutes/tests/App/Controller/HomeController.php index f83cfed68..7306f3b63 100644 --- a/src/AnnotatedRoutes/tests/App/Controller/HomeController.php +++ b/src/AnnotatedRoutes/tests/App/Controller/HomeController.php @@ -8,25 +8,15 @@ class HomeController { - /** - * @Route(route="/", name="index", methods="GET") - */ + #[Route(route: '/', name: 'index', methods: 'GET')] public function index(): string { return 'index'; } - /** - * @Route(route="/", name="method", methods="POST") - */ + #[Route(route: '/', name: 'method', methods: 'POST')] public function method(): string { return 'method'; } - - #[Route(route: '/attribute', name: 'attribute', methods: 'GET', group: 'test')] - public function attribute(): string - { - return 'attribute'; - } } diff --git a/src/AnnotatedRoutes/tests/App/Controller/NamelessRoutesController.php b/src/AnnotatedRoutes/tests/App/Controller/NamelessRoutesController.php index 7ea2649e1..6df9d22b5 100644 --- a/src/AnnotatedRoutes/tests/App/Controller/NamelessRoutesController.php +++ b/src/AnnotatedRoutes/tests/App/Controller/NamelessRoutesController.php @@ -8,26 +8,20 @@ class NamelessRoutesController { - /** - * @Route(route="/nameless", methods="GET") - */ - public function index() + #[Route('/nameless', methods: 'GET')] + public function index(): string { return 'index'; } - /** - * @Route(route="/nameless", methods="POST") - */ - public function method() + #[Route(route: '/nameless', methods: 'POST')] + public function method(): string { return 'method'; } - /** - * @Route(route="/nameless/route", methods={"GET", "POST"}) - */ - public function route() + #[Route(route: '/nameless/route', methods: ['GET', 'POST'])] + public function route(): string { return 'route'; } diff --git a/src/AnnotatedRoutes/tests/App/Controller/PageController.php b/src/AnnotatedRoutes/tests/App/Controller/PageController.php index 4e107f7e7..6f6df5f91 100644 --- a/src/AnnotatedRoutes/tests/App/Controller/PageController.php +++ b/src/AnnotatedRoutes/tests/App/Controller/PageController.php @@ -8,18 +8,14 @@ final class PageController { - /** - * @Route("/page/", name="page_get", methods="GET") - */ - public function get($page) + #[Route('/page/', name: 'page_get', methods: 'GET')] + public function get($page): string { - return 'page-'.$page; + return 'page-' . $page; } - /** - * @Route("/page/about", name="page_about", methods="GET", priority=-1) - */ - public function about() + #[Route('/page/about', name: 'page_about', methods: 'GET', priority: -1)] + public function about(): string { return 'about'; } diff --git a/src/AnnotatedRoutes/tests/IntegrationTest.php b/src/AnnotatedRoutes/tests/IntegrationTest.php index 0a5a9934d..c441ef85a 100644 --- a/src/AnnotatedRoutes/tests/IntegrationTest.php +++ b/src/AnnotatedRoutes/tests/IntegrationTest.php @@ -25,12 +25,6 @@ public function testRoute(): void $this->assertStringContainsString('index', $r->getBody()->__toString()); } - public function testAttributeRoute(): void - { - $r = $this->get('/attribute'); - $this->assertStringContainsString('attribute', $r->getBody()->__toString()); - } - public function testRoute2(): void { $r = $this->post('/'); diff --git a/src/Framework/Bootloader/Attributes/AttributesBootloader.php b/src/Framework/Bootloader/Attributes/AttributesBootloader.php index 93e7d9a48..e79fb29bd 100644 --- a/src/Framework/Bootloader/Attributes/AttributesBootloader.php +++ b/src/Framework/Bootloader/Attributes/AttributesBootloader.php @@ -39,7 +39,7 @@ public function init(EnvironmentInterface $env): void AttributesConfig::CONFIG, [ 'annotations' => [ - 'support' => $env->get('SUPPORT_ANNOTATIONS', true), + 'support' => $env->get('SUPPORT_ANNOTATIONS', false), ], 'cache' => [ 'storage' => $env->get('ATTRIBUTES_CACHE_STORAGE', null), @@ -76,12 +76,14 @@ private function initReader( $supportAnnotations = $config->isAnnotationsReaderEnabled(); if ($supportAnnotations) { + /** @psalm-suppress UndefinedClass */ if (!\interface_exists(DoctrineReaderInterface::class)) { throw new InitializationException( 'Doctrine annotations reader is not available, please install "doctrine/annotations" package', ); } + /** @psalm-suppress UndefinedClass, InvalidArgument */ $reader = new SelectiveReader([ $reader, new AnnotationReader(new DoctrineAnnotationReader()), diff --git a/src/Framework/Bootloader/Attributes/AttributesConfig.php b/src/Framework/Bootloader/Attributes/AttributesConfig.php index 62f394702..747c99998 100644 --- a/src/Framework/Bootloader/Attributes/AttributesConfig.php +++ b/src/Framework/Bootloader/Attributes/AttributesConfig.php @@ -18,7 +18,7 @@ final class AttributesConfig extends InjectableConfig */ protected array $config = [ 'annotations' => [ - 'support' => true, + 'support' => false, ], 'cache' => [ 'storage' => null, diff --git a/src/Queue/composer.json b/src/Queue/composer.json index 032ad69be..fea20ede6 100644 --- a/src/Queue/composer.json +++ b/src/Queue/composer.json @@ -51,7 +51,6 @@ } }, "require-dev": { - "doctrine/annotations": "^1.12 || ^2.0", "phpunit/phpunit": "^10.1", "mockery/mockery": "^1.5", "spiral/boot": "^3.12", diff --git a/src/Queue/tests/Attribute/JobHandlerTest.php b/src/Queue/tests/Attribute/JobHandlerTest.php index 00f07c83a..628cb62ce 100644 --- a/src/Queue/tests/Attribute/JobHandlerTest.php +++ b/src/Queue/tests/Attribute/JobHandlerTest.php @@ -9,9 +9,7 @@ use Spiral\Attributes\Factory; use Spiral\Queue\Attribute\JobHandler; use Spiral\Tests\Queue\Attribute\Stub\ExtendedJobHandler; -use Spiral\Tests\Queue\Attribute\Stub\JobHandlerAnnotation; use Spiral\Tests\Queue\Attribute\Stub\JobHandlerAttribute; -use Spiral\Tests\Queue\Attribute\Stub\WithExtendedJobHandlerAnnotation; use Spiral\Tests\Queue\Attribute\Stub\WithExtendedJobHandlerAttribute; use Spiral\Tests\Queue\Attribute\Stub\WithoutJobHandler; @@ -28,9 +26,7 @@ public function testJobHandler(string $class, ?JobHandler $expected): void public static function classesProvider(): \Traversable { yield [WithoutJobHandler::class, null]; - yield [JobHandlerAnnotation::class, new JobHandler('test')]; yield [JobHandlerAttribute::class, new JobHandler('test')]; - yield [WithExtendedJobHandlerAnnotation::class, new ExtendedJobHandler()]; yield [WithExtendedJobHandlerAttribute::class, new ExtendedJobHandler()]; } } diff --git a/src/Queue/tests/Attribute/RetryPolicyTest.php b/src/Queue/tests/Attribute/RetryPolicyTest.php index e335beac9..d8354ea6e 100644 --- a/src/Queue/tests/Attribute/RetryPolicyTest.php +++ b/src/Queue/tests/Attribute/RetryPolicyTest.php @@ -9,12 +9,9 @@ use Spiral\Attributes\Factory; use Spiral\Queue\Attribute\RetryPolicy; use Spiral\Tests\Queue\Attribute\Stub\ExtendedRetryPolicy; -use Spiral\Tests\Queue\Attribute\Stub\WithDefaultRetryPolicyAnnotation; use Spiral\Tests\Queue\Attribute\Stub\WithDefaultRetryPolicyAttribute; -use Spiral\Tests\Queue\Attribute\Stub\WithExtendedRetryPolicyAnnotation; use Spiral\Tests\Queue\Attribute\Stub\WithExtendedRetryPolicyAttribute; use Spiral\Tests\Queue\Attribute\Stub\WithoutRetryPolicy; -use Spiral\Tests\Queue\Attribute\Stub\WithRetryPolicyAnnotation; use Spiral\Tests\Queue\Attribute\Stub\WithRetryPolicyAttribute; final class RetryPolicyTest extends TestCase @@ -30,11 +27,8 @@ public function testRetryPolicy(string $class, ?RetryPolicy $expected): void public static function classesProvider(): \Traversable { yield [WithoutRetryPolicy::class, null]; - yield [WithDefaultRetryPolicyAnnotation::class, new RetryPolicy()]; yield [WithDefaultRetryPolicyAttribute::class, new RetryPolicy()]; - yield [WithRetryPolicyAnnotation::class, new RetryPolicy(5, 3_000, 2.5)]; yield [WithRetryPolicyAttribute::class, new RetryPolicy(5, 3_000, 2.5)]; yield [WithExtendedRetryPolicyAttribute::class, new ExtendedRetryPolicy()]; - yield [WithExtendedRetryPolicyAnnotation::class, new ExtendedRetryPolicy()]; } } diff --git a/src/Queue/tests/Attribute/SerializerTest.php b/src/Queue/tests/Attribute/SerializerTest.php index a93e2b016..ff0c6dda4 100644 --- a/src/Queue/tests/Attribute/SerializerTest.php +++ b/src/Queue/tests/Attribute/SerializerTest.php @@ -9,9 +9,7 @@ use Spiral\Attributes\Factory; use Spiral\Queue\Attribute\Serializer; use Spiral\Tests\Queue\Attribute\Stub\ExtendedSerializer; -use Spiral\Tests\Queue\Attribute\Stub\SerializerAnnotation; use Spiral\Tests\Queue\Attribute\Stub\SerializerAttribute; -use Spiral\Tests\Queue\Attribute\Stub\WithExtendedSerializerAnnotation; use Spiral\Tests\Queue\Attribute\Stub\WithExtendedSerializerAttribute; use Spiral\Tests\Queue\Attribute\Stub\WithoutSerializer; @@ -28,9 +26,7 @@ public function testSerializer(string $class, ?Serializer $expected): void public static function classesProvider(): \Traversable { yield [WithoutSerializer::class, null]; - yield [SerializerAnnotation::class, new Serializer('test')]; yield [SerializerAttribute::class, new Serializer('test')]; - yield [WithExtendedSerializerAnnotation::class, new ExtendedSerializer()]; yield [WithExtendedSerializerAttribute::class, new ExtendedSerializer()]; } } diff --git a/src/Queue/tests/Attribute/Stub/JobHandlerAnnotation.php b/src/Queue/tests/Attribute/Stub/JobHandlerAnnotation.php deleted file mode 100644 index 483292ea2..000000000 --- a/src/Queue/tests/Attribute/Stub/JobHandlerAnnotation.php +++ /dev/null @@ -1,14 +0,0 @@ -assertContainerBoundAsSingleton(ReaderInterface::class, SelectiveReader::class); + $this->assertContainerBoundAsSingleton(ReaderInterface::class, AttributeReader::class); } public function testInstantiatorBinding(): void { - $this->assertContainerBoundAsSingleton(InstantiatorInterface::class, Facade::class); + $this->assertContainerBoundAsSingleton(InstantiatorInterface::class, NamedArgumentsInstantiator::class); } public function testIsCacheEnabledShouldBeFalse(): void diff --git a/tests/Framework/Bootloader/Attributes/AttributesConfigTest.php b/tests/Framework/Bootloader/Attributes/AttributesConfigTest.php index fd3cf1978..959a80f6f 100644 --- a/tests/Framework/Bootloader/Attributes/AttributesConfigTest.php +++ b/tests/Framework/Bootloader/Attributes/AttributesConfigTest.php @@ -11,9 +11,9 @@ final class AttributesConfigTest extends TestCase { public function testIsAnnotationsReaderEnabled(): void { - $this->assertTrue((new AttributesConfig())->isAnnotationsReaderEnabled()); - $this->assertFalse( - (new AttributesConfig(['annotations' => ['support' => false]]))->isAnnotationsReaderEnabled() + $this->assertFalse((new AttributesConfig())->isAnnotationsReaderEnabled()); + $this->assertTrue( + (new AttributesConfig(['annotations' => ['support' => true]]))->isAnnotationsReaderEnabled() ); } diff --git a/tests/Framework/Bootloader/Attributes/AttributesWithoutAnnotationsBootloaderTest.php b/tests/Framework/Bootloader/Attributes/AttributesWithoutAnnotationsBootloaderTest.php index d884c37d3..4f2d62056 100644 --- a/tests/Framework/Bootloader/Attributes/AttributesWithoutAnnotationsBootloaderTest.php +++ b/tests/Framework/Bootloader/Attributes/AttributesWithoutAnnotationsBootloaderTest.php @@ -5,7 +5,6 @@ namespace Framework\Bootloader\Attributes; use Spiral\Attributes\AttributeReader; -use Spiral\Attributes\Composite\SelectiveReader; use Spiral\Attributes\Psr16CachedReader; use Spiral\Attributes\ReaderInterface; use Spiral\Testing\Attribute\Env; @@ -13,7 +12,6 @@ final class AttributesWithoutAnnotationsBootloaderTest extends BaseTestCase { - #[Env('SUPPORT_ANNOTATIONS', 'false')] public function testReaderBindingWithoutCache(): void { $this->assertContainerBoundAsSingleton(ReaderInterface::class, AttributeReader::class); @@ -25,10 +23,4 @@ public function testReaderBindingWithCache(): void { $this->assertContainerBoundAsSingleton(ReaderInterface::class, Psr16CachedReader::class); } - - #[Env('SUPPORT_ANNOTATIONS', 'true')] - public function testSelectiveReaderBinding(): void - { - $this->assertContainerBoundAsSingleton(ReaderInterface::class, SelectiveReader::class); - } } diff --git a/tests/Framework/Interceptor/GuardedTest.php b/tests/Framework/Interceptor/GuardedTest.php index fd83bc52d..7442acb2a 100644 --- a/tests/Framework/Interceptor/GuardedTest.php +++ b/tests/Framework/Interceptor/GuardedTest.php @@ -29,14 +29,6 @@ public function testInvalidAnnotationConfiguration(): void $core->callAction(DemoController::class, 'guardedButNoName', []); } - public function testInvalidAnnotationConfigurationWithAttribute(): void - { - $core = $this->getCore(); - - $this->expectException(InterceptorException::class); - $core->callAction(DemoController::class, 'guardedButNoNameAttribute', []); - } - public function testInvalidAnnotationConfigurationIfEmptyGuarded(): void { $core = $this->getCore(); @@ -104,15 +96,6 @@ public function testAllowed(): void $this->assertSame('ok', $core->callAction(DemoController::class, 'do', [])); } - public function testAllowedWithAttribute(): void - { - $core = $this->getCore(); - - $this->getContainer()->bind(ActorInterface::class, new Actor(['user'])); - - $this->assertSame('ok', $core->callAction(DemoController::class, 'doAttribute', [])); - } - public function testNotAllowed3(): void { $core = $this->getCore(); @@ -130,12 +113,4 @@ public function testAllowed2(): void $this->getContainer()->bind(ActorInterface::class, new Actor(['demo'])); $this->assertSame('ok', $core->callAction(Demo2Controller::class, 'do1', [])); } - - public function testNotAllowed2WithAttribute(): void - { - $core = $this->getCore(); - - $this->getContainer()->bind(ActorInterface::class, new Actor(['demo'])); - $this->assertSame('ok', $core->callAction(Demo2Controller::class, 'do1Attribute', [])); - } } diff --git a/tests/Framework/Interceptor/PipelineInterceptorTest.php b/tests/Framework/Interceptor/PipelineInterceptorTest.php index 5cb8f60d2..8a95e15ea 100644 --- a/tests/Framework/Interceptor/PipelineInterceptorTest.php +++ b/tests/Framework/Interceptor/PipelineInterceptorTest.php @@ -47,34 +47,4 @@ public function testSkipIfFirst(): void $this->getHttp()->get('/intercepted/first') ->assertBodySame('["first","three","two","one"]'); } - - public function testWithAttribute(): void - { - $this->getHttp()->get('/intercepted/withAttribute') - ->assertBodySame('["withAttribute","three","two","one"]'); - } - - public function testMixAttribute(): void - { - $this->getHttp()->get('/intercepted/mixAttribute') - ->assertBodySame('["mixAttribute","six","three","two","one","five","four"]'); - } - - public function testDupAttribute(): void - { - $this->getHttp()->get('/intercepted/dupAttribute') - ->assertBodySame('["dupAttribute","three","two","one","three","two","one"]'); - } - - public function testSkipNextAttribute(): void - { - $this->getHttp()->get('/intercepted/skipAttribute') - ->assertBodySame('["skipAttribute","three","two","one","one"]'); - } - - public function testSkipIfFirstAttribute(): void - { - $this->getHttp()->get('/intercepted/firstAttribute') - ->assertBodySame('["firstAttribute","three","two","one"]'); - } } diff --git a/tests/app/src/Controller/Demo2Controller.php b/tests/app/src/Controller/Demo2Controller.php index 52ab89c39..14c2361e4 100644 --- a/tests/app/src/Controller/Demo2Controller.php +++ b/tests/app/src/Controller/Demo2Controller.php @@ -7,44 +7,28 @@ use Spiral\Domain\Annotation\Guarded; use Spiral\Domain\Annotation\GuardNamespace; -/** - * @GuardNamespace("demo") - */ +#[GuardNamespace('demo')] class Demo2Controller { - /** - * @Guarded("do") - */ - public function do1() - { - return 'ok'; - } - #[Guarded('do')] - public function do1Attribute() + public function do1() { return 'ok'; } - /** - * @Guarded("do", else="notFound") - */ + #[Guarded('do', else: 'notFound')] public function do2() { return 'ok'; } - /** - * @Guarded("do", else="error") - */ + #[Guarded('do', else: 'error')] public function do3() { return 'ok'; } - /** - * @Guarded("do", else="badAction") - */ + #[Guarded('do', else: 'badAction')] public function do4() { return 'ok'; diff --git a/tests/app/src/Controller/Demo3Controller.php b/tests/app/src/Controller/Demo3Controller.php index 49e3c43a6..0b3637514 100644 --- a/tests/app/src/Controller/Demo3Controller.php +++ b/tests/app/src/Controller/Demo3Controller.php @@ -7,16 +7,11 @@ use Spiral\Domain\Annotation\Guarded; use Spiral\Domain\Annotation\GuardNamespace; -/** - * @GuardNamespace(namespace="") - */ +#[GuardNamespace(namespace: '')] class Demo3Controller { - /** - * @Guarded(permission="") - * @return string - */ - public function do() + #[Guarded(permission: '')] + public function do(): string { return 'ok'; } diff --git a/tests/app/src/Controller/DemoController.php b/tests/app/src/Controller/DemoController.php index c0897b4a2..26d12f6a8 100644 --- a/tests/app/src/Controller/DemoController.php +++ b/tests/app/src/Controller/DemoController.php @@ -8,38 +8,14 @@ class DemoController { - /** - * @Guarded() - * @return string - */ - public function guardedButNoName() + #[Guarded] + public function guardedButNoName(): string { return 'ok'; } - /** - * @return string - */ - #[Guarded()] - public function guardedButNoNameAttribute() - { - return 'ok'; - } - - /** - * @Guarded("do") - * @return string - */ - public function do() - { - return 'ok'; - } - - /** - * @return string - */ - #[Guarded(permission: 'do')] - public function doAttribute() + #[Guarded('do')] + public function do(): string { return 'ok'; } diff --git a/tests/app/src/Controller/InterceptedController.php b/tests/app/src/Controller/InterceptedController.php index 5c494d485..872ad48be 100644 --- a/tests/app/src/Controller/InterceptedController.php +++ b/tests/app/src/Controller/InterceptedController.php @@ -14,92 +14,32 @@ public function without(): array return [__FUNCTION__]; } - /** - * @Pipeline(pipeline={Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class}) - * @return array - */ + #[Pipeline(pipeline: [Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class])] public function with(): array { return [__FUNCTION__]; } - /** - * @Pipeline(pipeline={Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class}) - * @return array - */ + #[Pipeline(pipeline: [Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class])] public function mix(): array { return [__FUNCTION__]; } - /** - * @Pipeline(pipeline={Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class}) - * @return array - */ + #[Pipeline(pipeline: [Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class])] public function dup(): array { return [__FUNCTION__]; } - /** - * @Pipeline(pipeline={Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class}, skipNext=true) - * @return array - */ + #[Pipeline(pipeline: [Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class], skipNext: true)] public function skip(): array { return [__FUNCTION__]; } - /** - * @Pipeline(pipeline={Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class}, skipNext=true) - * @return array - */ - public function first(): array - { - return [__FUNCTION__]; - } - - /** - * @return array - */ - #[Pipeline(pipeline: [Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class])] - public function withAttribute(): array - { - return [__FUNCTION__]; - } - - /** - * @return array - */ - #[Pipeline(pipeline: [Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class])] - public function mixAttribute(): array - { - return [__FUNCTION__]; - } - - /** - * @return array - */ - #[Pipeline(pipeline: [Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class])] - public function dupAttribute(): array - { - return [__FUNCTION__]; - } - - /** - * @return array - */ #[Pipeline(pipeline: [Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class], skipNext: true)] - public function skipAttribute(): array - { - return [__FUNCTION__]; - } - - /** - * @return array - */ - #[Pipeline([Interceptor\One::class, Interceptor\Two::class, Interceptor\Three::class], true)] - public function firstAttribute(): array + public function first(): array { return [__FUNCTION__]; }