run(Command::fromArray(['echo', 'Hello Process!'])); echo "Success: " . ($result->isSuccess() ? 'YES' : 'NO') . "\n"; echo "Output: " . trim($result->stdout) . "\n"; echo "Exit Code: " . $result->exitCode->value . " ({$result->exitCode->getDescription()})\n"; echo "Runtime: " . $result->runtime->toHumanReadable() . "\n"; echo "\n"; // Test 2: Command with array echo "Test 2: Multiple commands\n"; $result = $process->run(Command::fromString('echo "line1" && echo "line2"')); echo "Success: " . ($result->isSuccess() ? 'YES' : 'NO') . "\n"; echo "Output:\n" . $result->stdout; echo "\n"; // Test 3: Working Directory echo "Test 3: Working directory\n"; $tempDir = FilePath::create(sys_get_temp_dir()); $result = $process->run( command: Command::fromString('pwd'), workingDirectory: $tempDir ); echo "Success: " . ($result->isSuccess() ? 'YES' : 'NO') . "\n"; echo "Current Directory: " . trim($result->stdout) . "\n"; echo "\n"; // Test 4: Environment Variables echo "Test 4: Environment variables\n"; $env = EnvironmentVariables::fromArray(['MY_VAR' => 'test_value']); $result = $process->run( command: Command::fromString('echo $MY_VAR'), env: $env ); echo "Success: " . ($result->isSuccess() ? 'YES' : 'NO') . "\n"; echo "MY_VAR value: " . trim($result->stdout) . "\n"; echo "\n"; // Test 5: Failed command echo "Test 5: Failed command (exit 1)\n"; $result = $process->run(Command::fromString('exit 1')); echo "Success: " . ($result->isSuccess() ? 'YES' : 'NO') . "\n"; echo "Is Failed: " . ($result->isFailed() ? 'YES' : 'NO') . "\n"; echo "Exit Code: " . $result->exitCode->value . " ({$result->exitCode->getDescription()})\n"; echo "\n"; // Test 6: Command existence echo "Test 6: Command existence check\n"; $exists = $process->commandExists('echo'); echo "'echo' exists: " . ($exists ? 'YES' : 'NO') . "\n"; $exists = $process->commandExists('nonexistent_cmd_xyz'); echo "'nonexistent_cmd_xyz' exists: " . ($exists ? 'YES' : 'NO') . "\n"; echo "\n"; // Test 7: Async process echo "Test 7: Async process execution\n"; $running = $process->start(Command::fromArray(['sleep', '0.2'])); echo "Process started, PID: " . $running->getPid() . "\n"; echo "Is running: " . ($running->isRunning() ? 'YES' : 'NO') . "\n"; $result = $running->wait(); echo "Process completed\n"; echo "Success: " . ($result->isSuccess() ? 'YES' : 'NO') . "\n"; echo "Runtime: " . $result->runtime->toHumanReadable() . "\n"; echo "\n"; // Test 8: ProcessResult toArray() echo "Test 8: ProcessResult to array\n"; $result = $process->run(Command::fromString('echo "test"')); $array = $result->toArray(); echo "Array keys: " . implode(', ', array_keys($array)) . "\n"; echo "Success in array: " . ($array['success'] ? 'YES' : 'NO') . "\n"; echo "\n"; // Test 9: Value Objects echo "Test 9: Value Objects immutability\n"; $env1 = EnvironmentVariables::fromArray(['A' => '1']); $env2 = $env1->with('B', '2'); echo "env1 has 'B': " . ($env1->has('B') ? 'YES' : 'NO') . "\n"; echo "env2 has 'B': " . ($env2->has('B') ? 'YES' : 'NO') . "\n"; echo "Immutability preserved: " . (! $env1->has('B') && $env2->has('B') ? 'YES' : 'NO') . "\n"; echo "\n"; echo "=== All Tests Complete ===\n";