Skip to content

PHPVM Tests

PHPVM Tests #119

Workflow file for this run

name: PHPVM Tests
on:
push:
branches: [main, development, 'fix/**', 'feature/**']
pull_request:
branches: [main, development]
workflow_dispatch:
schedule:
# Run weekly regression tests
- cron: '0 2 * * 1'
jobs:
# Syntax and Static Analysis
syntax-check:
name: "Syntax & Static Analysis"
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Shell Syntax Check
run: |
bash -n phpvm.sh
if [ -f install.sh ]; then bash -n install.sh; fi
echo "Shell syntax check passed"
- name: ShellCheck Analysis
uses: ludeeus/[email protected]
with:
scandir: '.'
format: gcc
severity: warning
continue-on-error: true
# Core Functionality Testing
core-functionality-test:
name: "Core Functionality (${{ matrix.os }})"
runs-on: ${{ matrix.os }}
needs: syntax-check
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Environment Info
run: |
echo "OS: $(uname -s)"
echo "Shell: $SHELL"
echo "User: $(whoami)"
# Setup Homebrew on Linux if needed
- name: Setup Homebrew (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential curl file git
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew --version
# Set up permissions for the script
- name: Make script executable
run: chmod +x ./phpvm.sh
# Test all version commands (v1.5.0 feature)
- name: Test Version Commands
run: |
echo "=== Testing Version Commands ==="
./phpvm.sh version
echo ""
./phpvm.sh --version
echo ""
./phpvm.sh -v
echo "All version commands work"
# Test help and list commands
- name: Test Basic Commands
run: |
echo "=== Testing Basic Commands ==="
./phpvm.sh help
./phpvm.sh list || echo "List command executed (may show no versions initially)"
echo "Basic commands work"
# Run the integrated self-tests
- name: Run Integrated Self-Tests
run: |
echo "=== Running Integrated Self-Tests ==="
./phpvm.sh test
echo "Self-tests completed"
# Test error handling
- name: Test Error Handling
run: |
echo "=== Testing Error Handling ==="
# Test invalid command
if ./phpvm.sh invalid_command 2>/dev/null; then
echo "Should have failed on invalid command"
exit 1
else
echo "Correctly handles invalid commands"
fi
# Test missing version parameter
if ./phpvm.sh use 2>/dev/null; then
echo "Should have failed on missing version"
exit 1
else
echo "Correctly handles missing version parameter"
fi
echo "Error handling tests completed"
# Test .phpvmrc functionality
- name: Test .phpvmrc Auto-Switch
run: |
echo "=== Testing .phpvmrc Auto-Switch ==="
mkdir -p test_project
echo "8.3" > test_project/.phpvmrc
cd test_project
if [[ "${{ runner.os }}" == "Linux" ]]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" 2>/dev/null || true
fi
../phpvm.sh auto || echo "Auto-switch attempted"
cd ..
echo "Auto-switch test completed"
# Performance check
- name: Performance Check
run: |
echo "=== Performance Check ==="
time ./phpvm.sh version >/dev/null
time ./phpvm.sh help >/dev/null
time ./phpvm.sh list >/dev/null
echo "Performance check completed"
# PHP Installation and Usage Testing
php-usage-test:
name: "PHP Installation & Usage (${{ matrix.os }})"
runs-on: ${{ matrix.os }}
needs: syntax-check
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Homebrew (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential curl file git
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
- name: Test PHP Installation Flow
run: |
chmod +x phpvm.sh
if [[ "${{ runner.os }}" == "Linux" ]]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
echo "=== Testing PHP Installation ==="
./phpvm.sh install 8.3 || echo "PHP 8.3 installation attempted"
- name: Test PHP Version Operations
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
echo "=== Testing Version Operations ==="
./phpvm.sh use 8.3 || echo "Switch to 8.3 attempted"
./phpvm.sh list
./phpvm.sh system || echo "System switch attempted"
- name: Test Project Auto-Switch
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
echo "=== Testing Project Auto-Switch ==="
mkdir -p test_project
echo "8.3" > test_project/.phpvmrc
cd test_project
../phpvm.sh auto || echo "Auto-switch attempted"
cd ..
# Multi-Distribution Compatibility Testing
multi-distribution-test:
name: "Multi-Distribution Test (${{ matrix.scenario }})"
runs-on: ubuntu-latest
needs: syntax-check
strategy:
fail-fast: false
matrix:
include:
# Ubuntu versions
- distro: ubuntu:20.04
scenario: "Ubuntu 20.04 LTS"
package_manager: apt
test_php_versions: "7.4 8.0 8.1"
- distro: ubuntu:22.04
scenario: "Ubuntu 22.04 LTS"
package_manager: apt
test_php_versions: "8.0 8.1 8.2"
- distro: ubuntu:24.04
scenario: "Ubuntu 24.04 LTS"
package_manager: apt
test_php_versions: "8.1 8.2 8.3"
# Debian versions
- distro: debian:11
scenario: "Debian Bullseye"
package_manager: apt
test_php_versions: "7.4 8.0"
- distro: debian:12
scenario: "Debian Bookworm"
package_manager: apt
test_php_versions: "8.1 8.2"
# RHEL/CentOS family
- distro: fedora:38
scenario: "Fedora 38"
package_manager: dnf
test_php_versions: "8.1 8.2"
- distro: fedora:39
scenario: "Fedora 39"
package_manager: dnf
test_php_versions: "8.2 8.3"
- distro: rockylinux:8
scenario: "Rocky Linux 8"
package_manager: dnf
test_php_versions: "7.4 8.0"
- distro: rockylinux:9
scenario: "Rocky Linux 9"
package_manager: dnf
test_php_versions: "8.0 8.1"
- distro: almalinux:8
scenario: "AlmaLinux 8"
package_manager: dnf
test_php_versions: "7.4 8.0"
- distro: almalinux:9
scenario: "AlmaLinux 9"
package_manager: dnf
test_php_versions: "8.0 8.1"
# Arch Linux
- distro: archlinux:latest
scenario: "Arch Linux"
package_manager: pacman
test_php_versions: "8.2 8.3"
# Alpine Linux
- distro: alpine:3.18
scenario: "Alpine 3.18"
package_manager: apk
test_php_versions: "8.1 8.2"
- distro: alpine:3.19
scenario: "Alpine 3.19"
package_manager: apk
test_php_versions: "8.2 8.3"
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Run Extended Tests in Container
run: |
# Use sh for Alpine Linux (bash not available by default), bash for others
if [[ "${{ matrix.distro }}" == alpine* ]]; then
SHELL_CMD="sh"
else
SHELL_CMD="bash"
fi
docker run --rm -v $PWD:/workspace -w /workspace ${{ matrix.distro }} $SHELL_CMD -c "
set -e
echo '=== Setting up ${{ matrix.scenario }} ==='
# Update package manager and install dependencies
case '${{ matrix.package_manager }}' in
apt)
apt-get update -y
# Install essential packages (gawk provides awk functionality)
apt-get install -y curl wget sudo procps grep sed gawk coreutils
;;
dnf)
dnf update -y
# Use --allowerasing to handle coreutils conflicts in RHEL/Rocky/Alma
dnf install -y --allowerasing curl wget sudo procps grep sed gawk coreutils which
;;
pacman)
pacman -Sy --noconfirm
pacman -S --noconfirm curl wget sudo procps grep sed gawk coreutils which
;;
apk)
apk update
# Install bash and other essential tools for Alpine
apk add bash curl wget sudo procps grep sed gawk coreutils
;;
esac
chmod +x ./phpvm.sh
echo '=== System Information ==='
./phpvm.sh info || echo 'Info command executed'
echo '=== Testing Basic Functionality ==='
./phpvm.sh version
./phpvm.sh help
./phpvm.sh list || echo 'List command completed'
echo '=== Running Self-Tests ==='
./phpvm.sh test
echo '=== Testing Input Validation ==='
# Test invalid version formats
if ./phpvm.sh install 'invalid..version' 2>/dev/null; then
echo 'Should have rejected invalid version'
exit 1
else
echo 'Correctly rejected invalid version'
fi
if ./phpvm.sh use 'bad-format' 2>/dev/null; then
echo 'Should have rejected invalid version format'
exit 1
else
echo 'Correctly rejected invalid version format'
fi
echo '=== Testing .phpvmrc Functionality ==='
mkdir -p test_project
echo '8.1' > test_project/.phpvmrc
cd test_project
../phpvm.sh auto || echo 'Auto-switch attempted'
cd ..
# Test corrupted .phpvmrc
mkdir -p bad_project
touch bad_project/.phpvmrc # Empty file
cd bad_project
if ../phpvm.sh auto 2>/dev/null; then
echo 'Should have failed with empty .phpvmrc'
exit 1
else
echo 'Correctly handled empty .phpvmrc'
fi
cd ..
echo '=== Performance Testing ==='
time ./phpvm.sh version >/dev/null
time ./phpvm.sh help >/dev/null
echo 'All extended tests completed successfully for ${{ matrix.scenario }}!'
"
# Performance and Load Testing
performance-test:
name: "Performance & Load Testing"
runs-on: ubuntu-latest
needs: syntax-check
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Performance Benchmarks
run: |
chmod +x ./phpvm.sh
echo "=== Performance Testing ==="
# Test startup time
echo "Measuring startup time (5 iterations):"
for i in {1..5}; do
time ./phpvm.sh version >/dev/null
done
# Test concurrent operations
echo "Testing 10 concurrent operations:"
for i in {1..10}; do
./phpvm.sh version >/dev/null &
done
wait
echo "Performance tests completed"
# End-to-End Integration Testing
integration-test:
name: "End-to-End Integration (${{ matrix.os }})"
runs-on: ${{ matrix.os }}
needs: syntax-check
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Test Installation Script
run: |
echo "=== Testing install.sh Script ==="
# Test syntax
bash -n install.sh
echo "Install script syntax check passed"
# Test installation script components
if grep -q "uname" install.sh; then
echo "Install script includes OS detection"
fi
if grep -q "curl\|wget" install.sh; then
echo "Install script includes download mechanism"
fi
if grep -q "chmod" install.sh; then
echo "Install script includes permission setting"
fi
- name: Simulate Installation Process
run: |
echo "=== Installation Process Simulation ==="
# Create a temporary home directory for testing
TEST_HOME=$(mktemp -d)
export HOME="$TEST_HOME"
# Test phpvm setup after simulated installation
export PHPVM_DIR="$TEST_HOME/.phpvm"
mkdir -p "$PHPVM_DIR"
cp phpvm.sh "$PHPVM_DIR/"
chmod +x "$PHPVM_DIR/phpvm.sh"
# Test if phpvm works after installation simulation
"$PHPVM_DIR/phpvm.sh" version
echo "phpvm works after simulated installation"
- name: Multi-Version Workflow Test
run: |
chmod +x ./phpvm.sh
echo "=== Multi-Version Workflow Testing ==="
# Test typical developer workflow
php_versions=("8.1" "8.2" "8.3")
for version in "${php_versions[@]}"; do
echo "Testing workflow with PHP $version"
# Test version validation
./phpvm.sh install "$version" 2>/dev/null || echo "Install command executed for $version"
# Test switching (in test mode)
./phpvm.sh use "$version" 2>/dev/null || echo "Use command executed for $version"
# Test listing
./phpvm.sh list || echo "List command executed"
# Test system switch
./phpvm.sh system || echo "System switch executed"
done
- name: Project Workflow Simulation
run: |
echo "=== Project Workflow Simulation ==="
# Simulate a typical project workflow
projects=("web-app" "api-service" "legacy-app")
versions=("8.3" "8.2" "8.1")
for i in "${!projects[@]}"; do
project="${projects[$i]}"
version="${versions[$i]}"
echo "Setting up project: $project with PHP $version"
# Create project directory
mkdir -p "$project"
echo "$version" > "$project/.phpvmrc"
# Test auto-switching
cd "$project"
echo "Testing auto-switch for $project:"
../phpvm.sh auto || echo "Auto-switch attempted for $project"
# Test nested directory behavior
mkdir -p "src/controllers"
cd "src/controllers"
echo "Testing auto-switch from nested directory:"
../../../phpvm.sh auto || echo "Auto-switch from nested directory attempted"
cd ../../..
done
- name: Error Recovery Testing
run: |
echo "=== Error Recovery Testing ==="
# Test recovery from various error conditions
# 1. Test with corrupted state
mkdir -p ~/.phpvm
echo "corrupted_data" > ~/.phpvm/active_version
echo "Testing recovery from corrupted state:"
./phpvm.sh list || echo "Handled corrupted state"
# 2. Test with missing directories
rm -rf ~/.phpvm/versions 2>/dev/null || true
echo "Testing recovery from missing directories:"
./phpvm.sh list || echo "Handled missing directories"
# 3. Test with invalid .phpvmrc
mkdir -p error_test
printf '\x00\x01\x02' > error_test/.phpvmrc
cd error_test
echo "Testing recovery from binary .phpvmrc:"
../phpvm.sh auto 2>/dev/null || echo "Handled binary .phpvmrc"
cd ..
- name: Documentation Validation
run: |
chmod +x ./phpvm.sh
echo "=== Help Documentation Validation ==="
# Test help output
help_output=$(./phpvm.sh help)
# Check if help includes all commands
commands=("install" "use" "system" "auto" "list" "help" "test" "info" "version")
for cmd in "${commands[@]}"; do
if echo "$help_output" | grep -q "$cmd"; then
echo "Help includes $cmd command"
else
echo "Help missing $cmd command"
fi
done
# Check if help includes examples
if echo "$help_output" | grep -q "Examples:"; then
echo "Help includes examples section"
else
echo "Help missing examples section"
fi
- name: Error Message Validation
run: |
echo "=== Error Message Validation ==="
# Test that error messages are helpful
error_output=$(./phpvm.sh invalid_command 2>&1 || true)
if echo "$error_output" | grep -q "Unknown command"; then
echo "Helpful error message for unknown command"
else
echo "Poor error message for unknown command"
fi
# Test missing argument error
error_output=$(./phpvm.sh use 2>&1 || true)
if echo "$error_output" | grep -q "Missing.*version"; then
echo "Helpful error message for missing argument"
else
echo "Poor error message for missing argument"
fi
- name: Cross-Platform Compatibility Test
run: |
echo "=== Cross-Platform Compatibility Testing ==="
# Test platform-specific features
if [ "$RUNNER_OS" = "macOS" ]; then
echo "Testing macOS-specific features:"
# Test Homebrew integration
if command -v brew >/dev/null; then
echo "Homebrew available"
# Test Homebrew detection
if ./phpvm.sh info | grep -q "Homebrew:"; then
echo "Homebrew detection working"
else
echo "Homebrew detection failed"
fi
else
echo "Homebrew not available in test environment"
fi
# Test macOS version detection
if ./phpvm.sh info | grep -q "macOS Version:"; then
echo "macOS version detection working"
else
echo "macOS version detection failed"
fi
elif [ "$RUNNER_OS" = "Linux" ]; then
echo "Testing Linux-specific features:"
# Test distribution detection
if ./phpvm.sh info | grep -q "Linux Distribution:"; then
echo "Linux distribution detection working"
else
echo "Linux distribution detection failed"
fi
# Test package manager detection
info_output=$(./phpvm.sh info)
if echo "$info_output" | grep -q "apt-get: Available"; then
echo "apt package manager detected"
fi
if echo "$info_output" | grep -q "update-alternatives: Available"; then
echo "update-alternatives detected"
fi
fi
- name: Final Integration Validation
run: |
echo "=== Final Integration Validation ==="
# Run all major functionalities
echo "1. Version information:"
./phpvm.sh version
echo -e "\n2. System information:"
./phpvm.sh info
echo -e "\n3. Help documentation:"
./phpvm.sh help >/dev/null && echo "Help command successful"
echo -e "\n4. List functionality:"
./phpvm.sh list >/dev/null && echo "List command successful"
echo -e "\n5. Self-tests:"
./phpvm.sh test >/dev/null && echo "Self-tests successful"
echo -e "\n6. Input validation:"
./phpvm.sh install "invalid" 2>/dev/null || echo "Input validation working"
echo -e "\n7. Auto-switch functionality:"
mkdir -p final_test
echo "8.1" > final_test/.phpvmrc
cd final_test
../phpvm.sh auto >/dev/null || echo "Auto-switch tested"
cd ..
echo -e "\nAll integration tests completed successfully!"