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";