From d0502f8f460ed7c5bcc61d30c5ffdb6862d7e61e Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 19 Dec 2022 17:41:17 +0100 Subject: [PATCH] Remove SimpleAnnotationReader --- UPGRADE.md | 1 + .../Annotations/SimpleAnnotationReader.php | 112 -------------- .../SimpleAnnotationReaderTest.php | 140 ------------------ .../Common/Annotations/Ticket/DCOM58Test.php | 11 -- 4 files changed, 1 insertion(+), 263 deletions(-) delete mode 100644 lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php delete mode 100644 tests/Doctrine/Tests/Common/Annotations/SimpleAnnotationReaderTest.php diff --git a/UPGRADE.md b/UPGRADE.md index fcb68b3ab..6e88871cd 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,6 @@ # Upgrade from 1.0.x to 2.0.x +- `SimpleAnnotationReader` has been removed. - `DocLexer::peek()` and `DocLexer::glimpse` now return `Doctrine\Common\Lexer\Token` objects. When using `doctrine/lexer` 2, these implement `ArrayAccess` as a way for you to still be able to treat them as diff --git a/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php b/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php deleted file mode 100644 index cde40dac0..000000000 --- a/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php +++ /dev/null @@ -1,112 +0,0 @@ -parser = new DocParser(); - $this->parser->setIgnoreNotImportedAnnotations(true); - } - - /** - * Adds a namespace in which we will look for annotations. - * - * @return void - */ - public function addNamespace(string $namespace) - { - $this->parser->addNamespace($namespace); - } - - /** - * {@inheritDoc} - */ - public function getClassAnnotations(ReflectionClass $class) - { - return $this->parser->parse($class->getDocComment(), 'class ' . $class->getName()); - } - - /** - * {@inheritDoc} - */ - public function getMethodAnnotations(ReflectionMethod $method) - { - return $this->parser->parse( - $method->getDocComment(), - 'method ' . $method->getDeclaringClass()->name . '::' . $method->getName() . '()' - ); - } - - /** - * {@inheritDoc} - */ - public function getPropertyAnnotations(ReflectionProperty $property) - { - return $this->parser->parse( - $property->getDocComment(), - 'property ' . $property->getDeclaringClass()->name . '::$' . $property->getName() - ); - } - - /** - * {@inheritDoc} - */ - public function getClassAnnotation(ReflectionClass $class, $annotationName) - { - foreach ($this->getClassAnnotations($class) as $annot) { - if ($annot instanceof $annotationName) { - return $annot; - } - } - - return null; - } - - /** - * {@inheritDoc} - */ - public function getMethodAnnotation(ReflectionMethod $method, $annotationName) - { - foreach ($this->getMethodAnnotations($method) as $annot) { - if ($annot instanceof $annotationName) { - return $annot; - } - } - - return null; - } - - /** - * {@inheritDoc} - */ - public function getPropertyAnnotation(ReflectionProperty $property, $annotationName) - { - foreach ($this->getPropertyAnnotations($property) as $annot) { - if ($annot instanceof $annotationName) { - return $annot; - } - } - - return null; - } -} diff --git a/tests/Doctrine/Tests/Common/Annotations/SimpleAnnotationReaderTest.php b/tests/Doctrine/Tests/Common/Annotations/SimpleAnnotationReaderTest.php deleted file mode 100644 index f65861c60..000000000 --- a/tests/Doctrine/Tests/Common/Annotations/SimpleAnnotationReaderTest.php +++ /dev/null @@ -1,140 +0,0 @@ -ignoreIssues(); - parent::testImportDetectsNotImportedAnnotation(); - } - - /** - * Contrary to the behavior of the default annotation reader, we do just ignore - * these in the simple annotation reader (so, no expected exception here). - * - * @doesNotPerformAssertions - */ - public function testImportDetectsNonExistentAnnotation(): void - { - $this->ignoreIssues(); - parent::testImportDetectsNonExistentAnnotation(); - } - - /** - * Contrary to the behavior of the default annotation reader, we do just ignore - * these in the simple annotation reader (so, no expected exception here). - * - * @doesNotPerformAssertions - */ - public function testClassWithInvalidAnnotationTargetAtClassDocBlock(): void - { - $this->ignoreIssues(); - parent::testClassWithInvalidAnnotationTargetAtClassDocBlock(); - } - - /** - * Contrary to the behavior of the default annotation reader, we do just ignore - * these in the simple annotation reader (so, no expected exception here). - * - * @doesNotPerformAssertions - */ - public function testClassWithInvalidAnnotationTargetAtPropertyDocBlock(): void - { - $this->ignoreIssues(); - parent::testClassWithInvalidAnnotationTargetAtPropertyDocBlock(); - } - - /** - * Contrary to the behavior of the default annotation reader, we do just ignore - * these in the simple annotation reader (so, no expected exception here). - * - * @doesNotPerformAssertions - */ - public function testClassWithInvalidNestedAnnotationTargetAtPropertyDocBlock(): void - { - $this->ignoreIssues(); - parent::testClassWithInvalidNestedAnnotationTargetAtPropertyDocBlock(); - } - - /** - * Contrary to the behavior of the default annotation reader, we do just ignore - * these in the simple annotation reader (so, no expected exception here). - * - * @doesNotPerformAssertions - */ - public function testClassWithInvalidAnnotationTargetAtMethodDocBlock(): void - { - $this->ignoreIssues(); - parent::testClassWithInvalidAnnotationTargetAtMethodDocBlock(); - } - - /** - * Contrary to the behavior of the default annotation reader, we do just ignore - * these in the simple annotation reader (so, no expected exception here). - * - * @doesNotPerformAssertions - */ - public function testErrorWhenInvalidAnnotationIsUsed(): void - { - $this->ignoreIssues(); - parent::testErrorWhenInvalidAnnotationIsUsed(); - } - - /** - * The SimpleAnnotationReader doens't include the @IgnoreAnnotation in the results. - */ - public function testInvalidAnnotationUsageButIgnoredClass(): void - { - $reader = $this->getReader(); - $ref = new ReflectionClass(Fixtures\InvalidAnnotationUsageButIgnoredClass::class); - $annots = $reader->getClassAnnotations($ref); - - self::assertCount(1, $annots); - } - - public function testIncludeIgnoreAnnotation(): void - { - $this->markTestSkipped('The simplified annotation reader would always autoload annotations'); - } - - /** - * @group DDC-1660 - * @group regression - * - * Contrary to the behavior of the default annotation reader, @version is not ignored - */ - public function testInvalidAnnotationButIgnored(): void - { - $reader = $this->getReader(); - $class = new ReflectionClass(Fixtures\ClassDDC1660::class); - - self::assertTrue(class_exists(Fixtures\Annotation\Version::class)); - self::assertCount(1, $reader->getClassAnnotations($class)); - self::assertCount(1, $reader->getMethodAnnotations($class->getMethod('bar'))); - self::assertCount(1, $reader->getPropertyAnnotations($class->getProperty('foo'))); - } - - protected function getReader(): Reader - { - $reader = new SimpleAnnotationReader(); - $reader->addNamespace(__NAMESPACE__); - $reader->addNamespace(__NAMESPACE__ . '\Fixtures'); - $reader->addNamespace(__NAMESPACE__ . '\Fixtures\Annotation'); - - return $reader; - } -} diff --git a/tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM58Test.php b/tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM58Test.php index 599b62c72..6ea53287e 100644 --- a/tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM58Test.php +++ b/tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM58Test.php @@ -4,7 +4,6 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\DocParser; -use Doctrine\Common\Annotations\SimpleAnnotationReader; use PHPUnit\Framework\TestCase; use ReflectionClass; @@ -78,16 +77,6 @@ public function testIssueWithNamespacesOrImports(): void self::assertCount(1, $annots); self::assertInstanceOf(\Entity::class, $annots[0]); } - - public function testIssueSimpleAnnotationReader(): void - { - $reader = new SimpleAnnotationReader(); - $reader->addNamespace('Doctrine\Tests\Common\Annotations\Ticket\Doctrine\ORM\Mapping'); - $annots = $reader->getClassAnnotations(new ReflectionClass(__NAMESPACE__ . '\MappedClass')); - - self::assertCount(1, $annots); - self::assertInstanceOf(Doctrine\ORM\Mapping\Entity::class, $annots[0]); - } } /**