2828use PHPUnit \Framework \TestCase ;
2929use Spiral \Attributes \AnnotationReader ;
3030use Spiral \Attributes \AttributeReader ;
31+ use Spiral \Attributes \Composite \MergeReader ;
3132
3233/**
3334 * AnnotationLoaderTest
@@ -36,6 +37,8 @@ class AnnotationLoaderTest extends TestCase
3637{
3738 protected function setUp (): void
3839 {
40+ require_once __DIR__ . '/Fixtures/Annotation/function.php ' ;
41+
3942 // doctrine/annotations ^1.0 compatibility.
4043 if (\method_exists (AnnotationRegistry::class, 'registerLoader ' )) {
4144 AnnotationRegistry::registerLoader ('\\class_exists ' );
@@ -46,18 +49,18 @@ protected function setUp(): void
4649 * @dataProvider provideAnnotationLoader
4750 * @runInSeparateProcess
4851 */
49- public function testAttach ($ loader ): void
52+ public function testAnnotationListenerWithResource ($ loader ): void
5053 {
5154 $ annotation = new AnnotationLoader (new AnnotationReader (), $ loader );
5255 $ result = $ names = [];
5356
54- $ annotation ->attachListener (new Fixtures \SampleListener ());
55- $ annotation ->attach (...[
57+ $ annotation ->listener (new Fixtures \SampleListener ());
58+ $ annotation ->resource (...[
5659 __DIR__ . '/Fixtures/Annotation/Valid ' ,
5760 'non-existing-file.php ' ,
5861 ]);
5962
60- $ this ->assertCount (1 , $ founds = \iterator_to_array ( $ annotation ->load () ));
63+ $ this ->assertCount (1 , $ founds = $ annotation ->load ());
6164
6265 /** @var Fixtures\SampleCollector $found */
6366 foreach ($ founds as $ found ) {
@@ -115,23 +118,23 @@ public function testAttach($loader): void
115118 ['handler ' => \ReflectionMethod::class, 'priority ' => 323 ],
116119 ['handler ' => \ReflectionProperty::class, 'priority ' => 0 ],
117120 ['handler ' => \ReflectionProperty::class, 'priority ' => 0 ],
118- ['handler ' => Fixtures \ Annotation \ Valid \SingleClass ::class, 'priority ' => 0 ],
121+ ['handler ' => \ReflectionClass ::class, 'priority ' => 0 ],
119122 ], $ result );
120123 }
121124
122125 /**
123126 * @dataProvider provideAnnotationLoader
124127 * @runInSeparateProcess
125128 */
126- public function testAttachAttribute ($ loader ): void
129+ public function testAnnotationLoaderWithAttribute ($ loader ): void
127130 {
128131 $ annotation = new AnnotationLoader (new AttributeReader (), $ loader );
129132 $ result = [];
130133
131- $ annotation ->attachListener (new Fixtures \SampleListener ());
132- $ annotation ->attach (__DIR__ . '/Fixtures/Annotation/Attribute ' );
134+ $ annotation ->listener (new Fixtures \SampleListener ());
135+ $ annotation ->resource (__DIR__ . '/Fixtures/Annotation/Attribute ' );
133136
134- $ this ->assertCount (1 , $ founds = \iterator_to_array ( $ annotation ->load () ));
137+ $ this ->assertCount (1 , $ founds = $ annotation ->load ());
135138
136139 /** @var Fixtures\SampleCollector $found */
137140 foreach ($ founds as $ found ) {
@@ -159,6 +162,33 @@ public function testAttachAttribute($loader): void
159162 ], $ result );
160163 }
161164
165+ /**
166+ * @runInSeparateProcess
167+ */
168+ public function testAnnotationLoaderWithFunction (): void
169+ {
170+ $ annotation = new AnnotationLoader (new MergeReader ([new AnnotationReader (), new AttributeReader ()]));
171+ $ result = $ names = [];
172+
173+ $ annotation ->listener (new Fixtures \SampleListener ());
174+ $ annotation ->resource ('Biurad \\Annotations \\Tests \\Fixtures \\Valid \\annotated_function ' );
175+
176+ /** @var Fixtures\SampleCollector $found */
177+ foreach ($ annotation ->load () as $ found ) {
178+ $ this ->assertInstanceOf (Fixtures \SampleCollector::class, $ found );
179+
180+ $ collected = $ found ->getCollected ();
181+ $ collected ->ksort ();
182+
183+ foreach ($ collected as $ name => $ sample ) {
184+ $ names [] = $ name ;
185+ $ result [] = $ sample ;
186+ }
187+ }
188+
189+ $ this ->assertEquals (['attributed_function ' , 'function_property ' ], $ names );
190+ }
191+
162192 public function provideAnnotationLoader (): array
163193 {
164194 return [
0 commit comments