@@ -378,3 +378,87 @@ class ChildService {}
378378 expect ($ doc ['navId ' ])->toBe ('child-service ' );
379379 expect ($ doc ['navParent ' ])->toBe ('parent-service ' );
380380});
381+
382+ it ('can extract functional documentation from trait docblocks ' , function () {
383+ $ extractor = new FunctionalDocBlockExtractor ;
384+ $ extractor ->setCurrentFilePath ('/test/path/TestTrait.php ' );
385+
386+ $ phpCode = <<<'PHP'
387+ <?php
388+ namespace App\Traits;
389+
390+ /**
391+ * Timestamp handling trait
392+ *
393+ * @functional
394+ * This trait provides timestamp functionality for models.
395+ *
396+ * # Key Features
397+ * - Automatic timestamp management
398+ * - Custom timestamp formats
399+ *
400+ * @nav Traits / Timestamp Handler
401+ * @uses \Carbon\Carbon
402+ * @link https://example.com/traits
403+ */
404+ trait TimestampHandler
405+ {
406+ public function updateTimestamps() {}
407+ }
408+ PHP;
409+
410+ $ parser = (new ParserFactory )->createForNewestSupportedVersion ();
411+ $ traverser = new NodeTraverser ;
412+ $ traverser ->addVisitor ($ extractor );
413+
414+ $ ast = $ parser ->parse ($ phpCode );
415+ $ traverser ->traverse ($ ast );
416+
417+ expect ($ extractor ->foundDocs )->toHaveCount (1 );
418+
419+ $ doc = $ extractor ->foundDocs [0 ];
420+ expect ($ doc ['owner ' ])->toBe ('App\Traits\TimestampHandler ' );
421+ expect ($ doc ['navPath ' ])->toBe ('Traits / Timestamp Handler ' );
422+ expect ($ doc ['description ' ])->toContain ('This trait provides timestamp functionality ' );
423+ expect ($ doc ['uses ' ])->toContain ('\Carbon\Carbon ' );
424+ expect ($ doc ['links ' ])->toContain ('https://example.com/traits ' );
425+ expect ($ doc ['sourceFile ' ])->toBe ('/test/path/TestTrait.php ' );
426+ });
427+
428+ it ('can extract functional documentation from trait methods ' , function () {
429+ $ extractor = new FunctionalDocBlockExtractor ;
430+ $ extractor ->setCurrentFilePath ('/test/path/TestTrait.php ' );
431+
432+ $ phpCode = <<<'PHP'
433+ <?php
434+ namespace App\Traits;
435+
436+ trait TimestampHandler
437+ {
438+ /**
439+ * Update timestamps method
440+ *
441+ * @functional
442+ * This method updates the created_at and updated_at timestamps.
443+ *
444+ * @nav Traits / Update Timestamps Process
445+ * @uses \Carbon\Carbon
446+ */
447+ public function updateTimestamps() {}
448+ }
449+ PHP;
450+
451+ $ parser = (new ParserFactory )->createForNewestSupportedVersion ();
452+ $ traverser = new NodeTraverser ;
453+ $ traverser ->addVisitor ($ extractor );
454+
455+ $ ast = $ parser ->parse ($ phpCode );
456+ $ traverser ->traverse ($ ast );
457+
458+ expect ($ extractor ->foundDocs )->toHaveCount (1 );
459+
460+ $ doc = $ extractor ->foundDocs [0 ];
461+ expect ($ doc ['owner ' ])->toBe ('App\Traits\TimestampHandler::updateTimestamps ' );
462+ expect ($ doc ['navPath ' ])->toBe ('Traits / Update Timestamps Process ' );
463+ expect ($ doc ['description ' ])->toContain ('This method updates the created_at and updated_at timestamps ' );
464+ });
0 commit comments