SimpleAnnotationReaderTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace EasySwoole\DoctrineAnnotation\Tests;
  3. use EasySwoole\DoctrineAnnotation\Reader;
  4. use EasySwoole\DoctrineAnnotation\SimpleAnnotationReader;
  5. use ReflectionClass;
  6. use function class_exists;
  7. class SimpleAnnotationReaderTest extends AbstractReaderTest
  8. {
  9. /**
  10. * Contrary to the behavior of the default annotation reader, we do just ignore
  11. * these in the simple annotation reader (so, no expected exception here).
  12. *
  13. * @doesNotPerformAssertions
  14. */
  15. public function testImportDetectsNotImportedAnnotation(): void
  16. {
  17. $this->ignoreIssues();
  18. parent::testImportDetectsNotImportedAnnotation();
  19. }
  20. /**
  21. * Contrary to the behavior of the default annotation reader, we do just ignore
  22. * these in the simple annotation reader (so, no expected exception here).
  23. *
  24. * @doesNotPerformAssertions
  25. */
  26. public function testImportDetectsNonExistentAnnotation(): void
  27. {
  28. $this->ignoreIssues();
  29. parent::testImportDetectsNonExistentAnnotation();
  30. }
  31. /**
  32. * Contrary to the behavior of the default annotation reader, we do just ignore
  33. * these in the simple annotation reader (so, no expected exception here).
  34. *
  35. * @doesNotPerformAssertions
  36. */
  37. public function testClassWithInvalidAnnotationTargetAtClassDocBlock(): void
  38. {
  39. $this->ignoreIssues();
  40. parent::testClassWithInvalidAnnotationTargetAtClassDocBlock();
  41. }
  42. /**
  43. * Contrary to the behavior of the default annotation reader, we do just ignore
  44. * these in the simple annotation reader (so, no expected exception here).
  45. *
  46. * @doesNotPerformAssertions
  47. */
  48. public function testClassWithInvalidAnnotationTargetAtPropertyDocBlock(): void
  49. {
  50. $this->ignoreIssues();
  51. parent::testClassWithInvalidAnnotationTargetAtPropertyDocBlock();
  52. }
  53. /**
  54. * Contrary to the behavior of the default annotation reader, we do just ignore
  55. * these in the simple annotation reader (so, no expected exception here).
  56. *
  57. * @doesNotPerformAssertions
  58. */
  59. public function testClassWithInvalidNestedAnnotationTargetAtPropertyDocBlock(): void
  60. {
  61. $this->ignoreIssues();
  62. parent::testClassWithInvalidNestedAnnotationTargetAtPropertyDocBlock();
  63. }
  64. /**
  65. * Contrary to the behavior of the default annotation reader, we do just ignore
  66. * these in the simple annotation reader (so, no expected exception here).
  67. *
  68. * @doesNotPerformAssertions
  69. */
  70. public function testClassWithInvalidAnnotationTargetAtMethodDocBlock(): void
  71. {
  72. $this->ignoreIssues();
  73. parent::testClassWithInvalidAnnotationTargetAtMethodDocBlock();
  74. }
  75. /**
  76. * Contrary to the behavior of the default annotation reader, we do just ignore
  77. * these in the simple annotation reader (so, no expected exception here).
  78. *
  79. * @doesNotPerformAssertions
  80. */
  81. public function testErrorWhenInvalidAnnotationIsUsed(): void
  82. {
  83. $this->ignoreIssues();
  84. parent::testErrorWhenInvalidAnnotationIsUsed();
  85. }
  86. /**
  87. * The SimpleAnnotationReader doens't include the @IgnoreAnnotation in the results.
  88. */
  89. public function testInvalidAnnotationUsageButIgnoredClass(): void
  90. {
  91. $reader = $this->getReader();
  92. $ref = new ReflectionClass(Fixtures\InvalidAnnotationUsageButIgnoredClass::class);
  93. $annots = $reader->getClassAnnotations($ref);
  94. self::assertCount(1, $annots);
  95. }
  96. public function testIncludeIgnoreAnnotation(): void
  97. {
  98. $this->markTestSkipped('The simplified annotation reader would always autoload annotations');
  99. }
  100. /**
  101. * @group DDC-1660
  102. * @group regression
  103. *
  104. * Contrary to the behavior of the default annotation reader, @version is not ignored
  105. */
  106. public function testInvalidAnnotationButIgnored(): void
  107. {
  108. $reader = $this->getReader();
  109. $class = new ReflectionClass(Fixtures\ClassDDC1660::class);
  110. self::assertTrue(class_exists(Fixtures\Annotation\Version::class));
  111. self::assertCount(1, $reader->getClassAnnotations($class));
  112. self::assertCount(1, $reader->getMethodAnnotations($class->getMethod('bar')));
  113. self::assertCount(1, $reader->getPropertyAnnotations($class->getProperty('foo')));
  114. }
  115. protected function getReader(): Reader
  116. {
  117. $reader = new SimpleAnnotationReader();
  118. $reader->addNamespace(__NAMESPACE__);
  119. $reader->addNamespace(__NAMESPACE__ . '\Fixtures');
  120. $reader->addNamespace(__NAMESPACE__ . '\Fixtures\Annotation');
  121. return $reader;
  122. }
  123. }