requiredString('email', 'User email address') ->requiredString('name', 'Full name') ->choice('role', ['user', 'admin', 'moderator'], false, 'user', 'User role') ->flag('force', 'f', 'Skip confirmations') ->flag('notify', null, 'Send notifications') ->integer('quota', false, 100, 'Storage quota in MB') ->build(); // Test cases $testCases = [ // Basic usage ['john@example.com', 'John Doe'], // With options ['jane@example.com', 'Jane Smith', '--role=admin', '--force'], // With short flags ['bob@example.com', 'Bob Wilson', '-f', '--notify'], // Combined short flags ['alice@example.com', 'Alice Brown', '-f', '--role', 'moderator'], // With integer option ['charlie@example.com', 'Charlie Davis', '--quota=500', '--role=admin'], // All options ['diana@example.com', 'Diana Miller', '--role=admin', '-f', '--notify', '--quota=1000'], ]; echo "Testing argument parsing:\n"; echo str_repeat('-', 50) . "\n\n"; foreach ($testCases as $i => $args) { echo "Test Case " . ($i + 1) . ": " . implode(' ', $args) . "\n"; try { $parsed = $parser->parse($args); echo " Email: " . $parsed->getString('email') . "\n"; echo " Name: " . $parsed->getString('name') . "\n"; echo " Role: " . $parsed->getString('role') . "\n"; echo " Force: " . ($parsed->getBool('force') ? 'true' : 'false') . "\n"; echo " Notify: " . ($parsed->getBool('notify') ? 'true' : 'false') . "\n"; echo " Quota: " . $parsed->getInt('quota') . " MB\n"; echo " ✓ SUCCESS\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 email ['invalid-email', 'John Doe'], // Invalid role ['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 { $parsed = $parser->parse($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"; $output = new ConsoleOutput(); $helpGenerator = new HelpGenerator($output); echo $helpGenerator->generate( 'user:create', $parser->getDefinitions(), 'Create a new user account with email, name, and optional settings.' ); echo "\n\n=== Test Complete ===\n";