66use AttributeRegistry \AttributeRegistry ;
77use AttributeRegistry \Collection \AttributeCollection ;
88use AttributeRegistry \Enum \AttributeTargetType ;
9+ use AttributeRegistry \Service \PluginPathResolver ;
910use AttributeRegistry \Test \Data \TestAttributeArgument ;
1011use AttributeRegistry \Test \Data \TestRoute ;
1112use AttributeRegistry \Test \Data \TestWithObject ;
1213use AttributeRegistry \Test \Data \TestWithObjectArray ;
14+ use AttributeRegistry \ValueObject \AttributeInfo ;
1315use Cake \Cache \Cache ;
1416use Cake \TestSuite \TestCase ;
1517
@@ -29,15 +31,18 @@ protected function setUp(): void
2931 ]);
3032
3133 $ this ->loadTestAttributes ();
34+ $ this ->loadTestPlugins ();
3235
33- $ this ->registry = $ this ->createRegistry ('attribute_test ' , true );
36+ // Create registry with both test data and plugin paths
37+ $ this ->registry = $ this ->createRegistryWithPlugins ('attribute_test ' , true );
3438 }
3539
3640 protected function tearDown (): void
3741 {
3842 parent ::tearDown ();
3943 Cache::clear ('attribute_test ' );
4044 Cache::drop ('attribute_test ' );
45+ $ this ->clearPlugins ();
4146 }
4247
4348 public function testAttributeRegistryCanBeCreated (): void
@@ -383,4 +388,51 @@ public function testObjectArgumentsPreservedThroughCaching(): void
383388 $ this ->assertEquals ($ attr1 ->arguments , $ attr2 ->arguments );
384389 }
385390 }
391+
392+ public function testDiscoverIncludesLocalPluginAttributes (): void
393+ {
394+ // Debug: Check if plugin paths are being picked up
395+ $ pluginPathResolver = new PluginPathResolver ();
396+ $ paths = $ pluginPathResolver ->getEnabledPluginPaths ();
397+
398+ // Discover all attributes
399+ $ results = $ this ->registry ->discover ();
400+
401+ // Debug: check all discovered attributes
402+ $ allAttributes = $ results ->toList ();
403+ $ attributeNames = array_map (fn (AttributeInfo $ attr ): string => $ attr ->attributeName , $ allAttributes );
404+
405+ // Filter for LocalPluginRoute attribute from test local plugin
406+ $ localPluginAttributes = $ results
407+ ->attributeContains ('LocalPluginRoute ' )
408+ ->toList ();
409+
410+ // Should find attributes from local plugin
411+ $ this ->assertNotEmpty (
412+ $ localPluginAttributes ,
413+ 'Should discover attributes from local plugin. Plugin paths: ' . implode (', ' , $ paths ) .
414+ '. Found attributes: ' . implode (', ' , $ attributeNames ),
415+ );
416+
417+ // Verify attributes are from the local plugin namespace
418+ foreach ($ localPluginAttributes as $ attr ) {
419+ $ this ->assertStringContainsString ('TestLocalPlugin ' , $ attr ->className );
420+ }
421+ }
422+
423+ public function testDiscoverIncludesLocalPluginController (): void
424+ {
425+ // Discover all attributes from TestLocalController
426+ $ results = $ this ->registry ->discover ()
427+ ->classNameContains ('TestLocalController ' )
428+ ->toList ();
429+
430+ // Should find the controller with attributes
431+ $ this ->assertNotEmpty ($ results , 'Should discover TestLocalController from local plugin ' );
432+
433+ // Verify we got both class and method attributes
434+ $ targetTypes = array_unique (array_map (fn (AttributeInfo $ attr ) => $ attr ->target ->type ->value , $ results ));
435+ $ this ->assertContains ('class ' , $ targetTypes , 'Should have class-level attribute ' );
436+ $ this ->assertContains ('method ' , $ targetTypes , 'Should have method-level attribute ' );
437+ }
386438}
0 commit comments