Browse Source

allowed endpoint as class target

Eric Schricker 2 years ago
parent
commit
f7636743bd

+ 1 - 1
src/Attributes/Endpoint.php

@@ -4,7 +4,7 @@ namespace Knuckles\Scribe\Attributes;
 
 use Attribute;
 
-#[Attribute(Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD)]
+#[Attribute(Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
 class Endpoint
 {
     public function __construct(

+ 19 - 0
tests/Strategies/Metadata/GetFromMetadataAttributesTest.php

@@ -14,6 +14,7 @@ use Knuckles\Scribe\Tools\DocumentationConfig;
 use PHPUnit\Framework\TestCase;
 use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
 use ReflectionClass;
+use ReflectionMethod;
 
 class UseMetadataAttributesTest extends TestCase
 {
@@ -99,6 +100,15 @@ class UseMetadataAttributesTest extends TestCase
         $this->assertArraySubset([
             "authenticated" => false,
         ], $results);
+
+        $endpoint = $this->endpoint(function (ExtractedEndpointData $e) {
+            $e->controller = new ReflectionClass(MetadataAttributesTestController3::class);
+            $e->method = $e->controller->getMethod('c1');
+        });
+        $results = $this->fetch($endpoint);
+        $this->assertArraySubset([
+            "title" => "Endpoint C"
+        ], $results);
     }
 
     protected function fetch($endpoint): array
@@ -163,3 +173,12 @@ class MetadataAttributesTestController2
     {
     }
 }
+
+
+#[Endpoint("Endpoint C")]
+class MetadataAttributesTestController3
+{
+    public function c1()
+    {
+    }
+}