@@ -460,4 +460,134 @@ pest --testsuite=tddraft --group=feature
460460
461461# Run all unit drafts
462462pest --testsuite=tddraft --group=unit
463- ```
463+ ```
464+
465+ ## tdd: promote
466+
467+ Promote a TDDraft test to the CI test suite (tests/Feature or tests/Unit) with automated file management and reference preservation.
468+
469+ ### Usage
470+
471+ ``` bash
472+ # Basic promotion (auto-detects target directory based on test type)
473+ php artisan tdd:promote tdd-20250718142530-Abc123
474+
475+ # Promote to specific directory
476+ php artisan tdd:promote tdd-20250718142530-Abc123 --target=Unit
477+ php artisan tdd:promote tdd-20250718142530-Abc123 --target=Feature
478+
479+ # Create new file with custom name
480+ php artisan tdd:promote tdd-20250718142530-Abc123 --new-file=UserRegistrationTest
481+
482+ # Append to existing file
483+ php artisan tdd:promote tdd-20250718142530-Abc123 --file=ExistingTest.php
484+
485+ # Specify custom class name
486+ php artisan tdd:promote tdd-20250718142530-Abc123 --class=CustomTestClass
487+
488+ # Keep original draft file after promotion
489+ php artisan tdd:promote tdd-20250718142530-Abc123 --keep-draft
490+
491+ # Force overwrite without confirmation
492+ php artisan tdd:promote tdd-20250718142530-Abc123 --force
493+ ```
494+
495+ ### Options
496+
497+ - ` reference ` (required): The unique reference ID of the TDDraft test to promote
498+ - ` --target=Feature|Unit ` : Target directory (Feature or Unit). If not specified, uses the test type from the draft
499+ - ` --file= ` : Existing file to append the test to (optional)
500+ - ` --new-file= ` : New file name to create (optional, without .php extension)
501+ - ` --class= ` : Custom test class name (optional)
502+ - ` --force ` : Overwrite existing files without confirmation
503+ - ` --keep-draft ` : Keep the original draft file after promotion
504+
505+ ### What it Does
506+
507+ 1 . ** Finds Draft Test** : Locates the TDDraft test file using the unique reference
508+ 2 . ** Parses Test Content** : Extracts test metadata, content, and structure
509+ 3 . ** Determines Target** : Automatically selects target directory based on test type or provided options
510+ 4 . ** Handles File Operations** : Creates new files or appends to existing ones as specified
511+ 5 . ** Updates Test Content** :
512+ - Removes TDDraft-specific comments and metadata
513+ - Removes ` tddraft ` group but preserves the unique reference for audit trails
514+ - Updates class names and namespaces if needed
515+ 6 . ** Updates Status** : Marks test as "promoted" in the status tracking system
516+ 7 . ** Cleanup** : Removes the draft file unless ` --keep-draft ` is specified
517+
518+ ### Promotion Process
519+
520+ When you promote a test, the following transformations occur:
521+
522+ ** Before Promotion (Draft):**
523+ ``` php
524+ /**
525+ * TDDraft Test: User can register
526+ *
527+ * Reference: tdd-20250718142530-Abc123
528+ * Type: feature
529+ * Created: 2025-07-18 14:25:30
530+ */
531+
532+ it('user can register', function (): void {
533+ // Test implementation
534+ })
535+ ->group('tddraft', 'feature', 'tdd-20250718142530-Abc123')
536+ ->todo('Implement the test scenario for: user can register');
537+ ```
538+
539+ ** After Promotion (CI Suite):**
540+ ``` php
541+ it('user can register', function (): void {
542+ // Test implementation
543+ })
544+ ->group('feature', 'tdd-20250718142530-Abc123'); // Reference preserved for audit
545+ ```
546+
547+ ### Target Directory Selection
548+
549+ - ** Auto-detection** : Uses the ` Type: ` field from the draft test metadata
550+ - ** Manual override** : Use ` --target=Feature ` or ` --target=Unit ` to specify
551+ - ** Path creation** : Automatically creates target directories if they don't exist
552+
553+ ### Example Output
554+
555+ ```
556+ π Found draft test: tests/TDDraft/UserCanRegisterTest.php
557+ β
Successfully promoted test to: tests/Feature/UserCanRegisterTest.php
558+ π― Test class: UserCanRegisterTest
559+ ποΈ Removed draft file: tests/TDDraft/UserCanRegisterTest.php
560+ ```
561+
562+ ### Advanced Promotion Examples
563+
564+ ``` bash
565+ # Organize promoted tests in subdirectories
566+ php artisan tdd:promote tdd-20250718142530-Abc123 --target=Feature --new-file=Auth/UserRegistrationTest
567+
568+ # Append multiple draft tests to a comprehensive test file
569+ php artisan tdd:promote tdd-20250718142530-Abc123 --file=UserManagementTest.php
570+ php artisan tdd:promote tdd-20250718142531-Def456 --file=UserManagementTest.php
571+
572+ # Keep drafts for reference during code review
573+ php artisan tdd:promote tdd-20250718142530-Abc123 --keep-draft
574+
575+ # Batch promotion workflow
576+ php artisan tdd:list --type=feature # Find tests ready for promotion
577+ php artisan tdd:promote tdd-20250718142530-Abc123
578+ php artisan tdd:promote tdd-20250718142531-Def456
579+ ```
580+
581+ ### Error Handling
582+
583+ - ** Test Not Found** : Shows error if the reference doesn't match any draft test
584+ - ** File Conflicts** : Asks for confirmation before overwriting existing files (unless ` --force ` is used)
585+ - ** Invalid Options** : Validates option combinations and shows helpful error messages
586+ - ** Directory Creation** : Automatically creates target directories if they don't exist
587+
588+ ### Integration with Status Tracking
589+
590+ The promote command automatically:
591+ - Updates the test status to "promoted"
592+ - Maintains the status history for audit trails
593+ - Preserves the unique reference in the promoted test for lineage tracking
0 commit comments