Files
michaelschiemer/tests/debug/test-enhanced-argument-parsing.php
Michael Schiemer 5050c7d73a docs: consolidate documentation into organized structure
- 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
2025-10-05 11:05:04 +02:00

110 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\Console\ArgumentParser;
use App\Framework\Console\ConsoleOutput;
use App\Framework\Console\HelpGenerator;
echo "=== Enhanced Argument Parsing Test ===\n\n";
// Create parser with various argument types
$parser = ArgumentParser::create()
->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";