- Move 12 markdown files from root to docs/ subdirectories - Organize documentation by category: • docs/troubleshooting/ (1 file) - Technical troubleshooting guides • docs/deployment/ (4 files) - Deployment and security documentation • docs/guides/ (3 files) - Feature-specific guides • docs/planning/ (4 files) - Planning and improvement proposals Root directory cleanup: - Reduced from 16 to 4 markdown files in root - Only essential project files remain: • CLAUDE.md (AI instructions) • README.md (Main project readme) • CLEANUP_PLAN.md (Current cleanup plan) • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements) This improves: ✅ Documentation discoverability ✅ Logical organization by purpose ✅ Clean root directory ✅ Better maintainability
153 lines
4.7 KiB
PHP
153 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
use App\Framework\Console\CommandParameterResolver;
|
|
use App\Framework\Console\ConsoleCommand;
|
|
use App\Framework\Console\Examples\UserRole;
|
|
use App\Framework\Console\ExitCode;
|
|
use App\Framework\Console\MethodSignatureAnalyzer;
|
|
use App\Framework\Console\Parameter;
|
|
|
|
echo "=== Modern Parameter Parsing Test ===\n\n";
|
|
|
|
// Define a test command using the new system
|
|
final readonly class TestModernCommand
|
|
{
|
|
/**
|
|
* Create a user with modern parameter mapping
|
|
*
|
|
* @param string $email User email address
|
|
* @param string $name Full name of the user
|
|
* @param UserRole $role User role
|
|
* @param bool $force Skip confirmation prompts
|
|
* @param bool $notify Send welcome notification
|
|
* @param int $quota Storage quota in MB
|
|
*/
|
|
#[ConsoleCommand('test:user', 'Test user creation with modern parameters')]
|
|
public function createUser(
|
|
#[Parameter('User email address', example: 'user@example.com')]
|
|
string $email,
|
|
#[Parameter('Full name of the user')]
|
|
string $name,
|
|
#[Parameter('User role - admin, user, or moderator')]
|
|
UserRole $role = UserRole::USER,
|
|
#[Parameter('Skip confirmation prompts', shortName: 'f')]
|
|
bool $force = false,
|
|
#[Parameter('Send welcome notification')]
|
|
bool $notify = true,
|
|
#[Parameter('Storage quota in megabytes')]
|
|
int $quota = 100
|
|
): ExitCode {
|
|
echo "Creating user with parameters:\n";
|
|
echo " Email: {$email}\n";
|
|
echo " Name: {$name}\n";
|
|
echo " Role: {$role->value} ({$role->getDescription()})\n";
|
|
echo " Force: " . ($force ? 'Yes' : 'No') . "\n";
|
|
echo " Notify: " . ($notify ? 'Yes' : 'No') . "\n";
|
|
echo " Quota: {$quota} MB\n";
|
|
|
|
return ExitCode::SUCCESS;
|
|
}
|
|
}
|
|
|
|
// Test the parameter analysis and resolution
|
|
echo "Testing parameter analysis:\n";
|
|
echo str_repeat('-', 50) . "\n";
|
|
|
|
$analyzer = new MethodSignatureAnalyzer();
|
|
$resolver = new CommandParameterResolver($analyzer);
|
|
|
|
$method = new ReflectionMethod(TestModernCommand::class, 'createUser');
|
|
|
|
// Generate argument definitions
|
|
$definitions = $analyzer->generateArgumentDefinitions($method);
|
|
|
|
echo "Detected parameters:\n";
|
|
foreach ($definitions as $name => $definition) {
|
|
echo " {$name}:\n";
|
|
echo " Type: {$definition->type->value}\n";
|
|
echo " Required: " . ($definition->required ? 'Yes' : 'No') . "\n";
|
|
echo " Default: " . ($definition->default !== null ? var_export($definition->default, true) : 'None') . "\n";
|
|
echo " Description: {$definition->description}\n";
|
|
echo " Short: " . ($definition->shortName ?: 'None') . "\n";
|
|
if (! empty($definition->allowedValues)) {
|
|
echo " Choices: " . implode(', ', $definition->allowedValues) . "\n";
|
|
}
|
|
echo "\n";
|
|
}
|
|
|
|
// Test command execution with various argument combinations
|
|
echo "Testing command execution:\n";
|
|
echo str_repeat('-', 50) . "\n\n";
|
|
|
|
$testCases = [
|
|
// Basic usage
|
|
['john@example.com', 'John Doe'],
|
|
|
|
// With role
|
|
['jane@example.com', 'Jane Smith', '--role=admin'],
|
|
|
|
// With all parameters
|
|
['bob@example.com', 'Bob Wilson', '--role=moderator', '--force', '--quota=500'],
|
|
|
|
// With short flags
|
|
['alice@example.com', 'Alice Brown', '-f', '--no-notify'],
|
|
|
|
// With enum values
|
|
['charlie@example.com', 'Charlie Davis', '--role=admin', '--quota=1000'],
|
|
];
|
|
|
|
$instance = new TestModernCommand();
|
|
|
|
foreach ($testCases as $i => $args) {
|
|
echo "Test Case " . ($i + 1) . ": " . implode(' ', $args) . "\n";
|
|
|
|
try {
|
|
$resolvedParams = $resolver->resolveParameters($method, $args);
|
|
$result = $method->invokeArgs($instance, $resolvedParams);
|
|
echo " Result: " . $result->name . "\n\n";
|
|
|
|
} catch (Exception $e) {
|
|
echo " ✗ ERROR: " . $e->getMessage() . "\n\n";
|
|
}
|
|
}
|
|
|
|
// Test error cases
|
|
echo "Testing error cases:\n";
|
|
echo str_repeat('-', 50) . "\n\n";
|
|
|
|
$errorCases = [
|
|
// Missing required arguments
|
|
[],
|
|
['john@example.com'], // Missing name
|
|
|
|
// Invalid enum value
|
|
['john@example.com', 'John Doe', '--role=invalid'],
|
|
|
|
// Invalid integer
|
|
['john@example.com', 'John Doe', '--quota=abc'],
|
|
];
|
|
|
|
foreach ($errorCases as $i => $args) {
|
|
echo "Error Case " . ($i + 1) . ": " . (empty($args) ? '[empty]' : implode(' ', $args)) . "\n";
|
|
|
|
try {
|
|
$resolvedParams = $resolver->resolveParameters($method, $args);
|
|
echo " ✗ UNEXPECTED SUCCESS\n\n";
|
|
} catch (Exception $e) {
|
|
echo " ✓ Expected error: " . $e->getMessage() . "\n\n";
|
|
}
|
|
}
|
|
|
|
// Test help generation
|
|
echo "Testing help generation:\n";
|
|
echo str_repeat('-', 50) . "\n\n";
|
|
|
|
$help = $resolver->generateMethodHelp($method, 'test:user');
|
|
echo $help;
|
|
|
|
echo "\n\n=== Test Complete ===\n";
|