Skip to content

Commit c146ad5

Browse files
authored
Merge pull request #17 from Grazulex/copilot/fix-16
πŸ”„ Complete documentation and examples update for first production version
2 parents 7672670 + 17d95d9 commit c146ad5

File tree

5 files changed

+155
-21
lines changed

5 files changed

+155
-21
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,12 @@ declare(strict_types=1);
401401
it('should fail initially - this is normal for TDDraft', function (): void {
402402
// This test intentionally fails to demonstrate the TDD "red" phase
403403
expect(false)->toBeTrue('This draft needs implementation!');
404-
})->group('tddraft');
404+
})->group('tddraft', 'feature', 'example-red-phase');
405405

406406
it('can be promoted when ready', function (): void {
407407
// When this passes, you can promote it to your main test suite
408408
expect(true)->toBeTrue();
409-
})->group('tddraft');
409+
})->group('tddraft', 'feature', 'example-green-phase');
410410
```
411411

412412
## πŸ“š Documentation

β€Ždocs/best-practices.mdβ€Ž

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,35 +169,37 @@ it('allows user registration with valid data', function (): void {
169169
]);
170170

171171
$response->assertStatus(201);
172-
})->group('tddraft');
172+
})->group('tddraft', 'feature', 'tdd-20250718142530-Abc123');
173173
```
174174

175-
### Use the `tddraft` Group
175+
### Use the `tddraft` Group with References
176176

177-
Always mark draft tests with the appropriate group:
177+
Always mark draft tests with the appropriate groups including the unique reference for tracking:
178178

179179
```php
180180
it('describes the behavior', function (): void {
181181
// Test implementation
182-
})->group('tddraft');
182+
})->group('tddraft', 'feature', 'tdd-20250718142530-Abc123');
183183
```
184184

185+
**Best Practice:** Use `php artisan tdd:make` to automatically generate tests with proper grouping and unique references. Manual test creation should follow the same pattern.
186+
185187
### Write Descriptive Test Names
186188

187189
Test names should read like specifications:
188190

189191
```php
190192
it('prevents registration with duplicate email', function (): void {
191193
// ...
192-
})->group('tddraft');
194+
})->group('tddraft', 'feature', 'tdd-20250718142530-Abc123');
193195

194196
it('sends welcome email after successful registration', function (): void {
195197
// ...
196-
})->group('tddraft');
198+
})->group('tddraft', 'feature', 'tdd-20250718142531-Def456');
197199

198200
it('redirects to dashboard after login', function (): void {
199201
// ...
200-
})->group('tddraft');
202+
})->group('tddraft', 'feature', 'tdd-20250718142532-Ghi789');
201203
```
202204

203205
### Focus on One Behavior Per Test
@@ -214,12 +216,12 @@ it('validates email format during registration', function (): void {
214216

215217
$response->assertStatus(422)
216218
->assertJsonValidationErrors(['email']);
217-
})->group('tddraft');
219+
})->group('tddraft', 'feature', 'tdd-20250718142534-Mno345');
218220

219221
// Avoid: Testing multiple behaviors
220222
it('handles registration validation', function (): void {
221223
// Don't test email, password, name validation all in one test
222-
})->group('tddraft');
224+
})->group('tddraft', 'feature', 'tdd-20250718142535-Pqr678');
223225
```
224226

225227
## TDD Workflow

β€Ždocs/commands.mdβ€Ž

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,134 @@ pest --testsuite=tddraft --group=feature
460460

461461
# Run all unit drafts
462462
pest --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

β€Ždocs/configuration.mdβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ Status tracking is automatically enabled and works with the `tdd:test` command:
146146
php artisan tdd:test
147147

148148
# Status is tracked in tests/TDDraft/.status.json
149-
# View status through tdd:list command (coming in future versions)
149+
# View status through tdd:list command
150+
php artisan tdd:list
151+
php artisan tdd:list --details
150152
```
151153

152154
**Benefits of Status Tracking:**

β€Žexamples/basic-usage.phpβ€Ž

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,16 @@
284284
echo "10. Configuration Options\n";
285285
echo "-------------------------\n";
286286
echo "The config/tddraft.php file contains:\n";
287-
echo " - Package enablement settings\n";
288-
echo " - Default timeouts and retry attempts\n";
289-
echo " - Caching configuration\n";
290-
echo " - Logging settings\n\n";
287+
echo " - Status tracking configuration (NEW)\n";
288+
echo " - Test result history management\n";
289+
echo " - File path settings for status storage\n";
290+
echo " - Environment-specific controls\n\n";
291291

292292
echo "Environment variables:\n";
293-
echo " LARAVEL_TDDRAFT_ENABLED=true\n";
294-
echo " LARAVEL_TDDRAFT_LOGGING_ENABLED=false\n";
295-
echo " LARAVEL_TDDRAFT_LOG_CHANNEL=stack\n";
296-
echo " LARAVEL_TDDRAFT_LOG_LEVEL=info\n\n";
293+
echo " LARAVEL_TDDRAFT_STATUS_TRACKING_ENABLED=true\n";
294+
echo " LARAVEL_TDDRAFT_STATUS_FILE=tests/TDDraft/.status.json\n";
295+
echo " LARAVEL_TDDRAFT_TRACK_HISTORY=true\n";
296+
echo " LARAVEL_TDDRAFT_MAX_HISTORY=50\n\n";
297297

298298
echo "βœ… That's the complete TDDraft workflow!\n";
299299
echo "Key benefits:\n";

0 commit comments

Comments
Β (0)