Skip to content

Commit

Permalink
Merge pull request #1059 from spiral/annotations-require-dev
Browse files Browse the repository at this point in the history
Remove doctrine/annotations
  • Loading branch information
butschster committed Jan 11, 2024
2 parents 13b1963 + 2a6e8ac commit a3c133e
Show file tree
Hide file tree
Showing 29 changed files with 44 additions and 349 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
14 changes: 2 additions & 12 deletions src/AnnotatedRoutes/tests/App/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
14 changes: 5 additions & 9 deletions src/AnnotatedRoutes/tests/App/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@

final class PageController
{
/**
* @Route("/page/<page>", name="page_get", methods="GET")
*/
public function get($page)
#[Route('/page/<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';
}
Expand Down
6 changes: 0 additions & 6 deletions src/AnnotatedRoutes/tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand Down
4 changes: 3 additions & 1 deletion src/Framework/Bootloader/Attributes/AttributesBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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()),
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/Bootloader/Attributes/AttributesConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class AttributesConfig extends InjectableConfig
*/
protected array $config = [
'annotations' => [
'support' => true,
'support' => false,
],
'cache' => [
'storage' => null,
Expand Down
1 change: 0 additions & 1 deletion src/Queue/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
}
},
"require-dev": {
"doctrine/annotations": "^1.12 || ^2.0",
"phpunit/phpunit": "^10.1",
"mockery/mockery": "^1.5",
"spiral/boot": "^3.12",
Expand Down
4 changes: 0 additions & 4 deletions src/Queue/tests/Attribute/JobHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()];
}
}
6 changes: 0 additions & 6 deletions src/Queue/tests/Attribute/RetryPolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()];
}
}
4 changes: 0 additions & 4 deletions src/Queue/tests/Attribute/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()];
}
}
14 changes: 0 additions & 14 deletions src/Queue/tests/Attribute/Stub/JobHandlerAnnotation.php

This file was deleted.

4 changes: 1 addition & 3 deletions src/Queue/tests/Attribute/Stub/Queueable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use Spiral\Queue\Attribute\Queueable as QueueableAttribute;

/**
* @QueueableAttribute
*/
#[QueueableAttribute]
final class Queueable
{
}
4 changes: 1 addition & 3 deletions src/Queue/tests/Attribute/Stub/QueueableWithQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use Spiral\Queue\Attribute\Queueable;

/**
* @Queueable(queue="test")
*/
#[Queueable(queue: 'test')]
final class QueueableWithQueue
{
}
14 changes: 0 additions & 14 deletions src/Queue/tests/Attribute/Stub/SerializerAnnotation.php

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions src/Queue/tests/Attribute/Stub/WithRetryPolicyAnnotation.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@

namespace Framework\Bootloader\Attributes;

use Spiral\Attributes\Composite\SelectiveReader;
use Spiral\Attributes\Internal\Instantiator\Facade;
use Spiral\Attributes\AttributeReader;
use Spiral\Attributes\Internal\Instantiator\InstantiatorInterface;
use Spiral\Attributes\Internal\Instantiator\NamedArgumentsInstantiator;
use Spiral\Attributes\ReaderInterface;
use Spiral\Bootloader\Attributes\AttributesConfig;
use Spiral\Bootloader\Attributes\Factory;
use Spiral\Tests\Framework\BaseTestCase;

final class AttributesBootloaderTest extends BaseTestCase
{
public function testReaderBinding(): void
{
$this->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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down
Loading

0 comments on commit a3c133e

Please sign in to comment.