diff --git a/install.sh b/install.sh index fcfacec..42369a2 100644 --- a/install.sh +++ b/install.sh @@ -1,25 +1,25 @@ -#!/usr/bin/env bash - -{ # Ensure the entire script is downloaded and executed - - set -euo pipefail +#!/bin/sh +{ + # Ensure the entire script is downloaded and executed + set -e phpvm_has() { - type "$1" >/dev/null 2>&1 + command -v "$1" >/dev/null 2>&1 } phpvm_echo() { - command printf "\e[32m%s\e[0m\n" "$*" + printf "\033[32m%s\033[0m\n" "$*" } phpvm_err() { - command >&2 printf "\e[31mError: %s\e[0m\n" "$*" + printf "\033[31mError: %s\033[0m\n" "$*" >&2 } phpvm_warn() { - command >&2 printf "\e[33mWarning: %s\e[0m\n" "$*" + printf "\033[33mWarning: %s\033[0m\n" "$*" >&2 } + # Default installation directory PHPVM_DIR="${PHPVM_DIR:-$HOME/.phpvm}" PHPVM_SCRIPT="$PHPVM_DIR/phpvm.sh" GITHUB_REPO_URL="https://raw.githubusercontent.com/Thavarshan/phpvm/main/phpvm.sh" @@ -36,7 +36,8 @@ if phpvm_has "curl"; then curl --fail --compressed -q "$@" elif phpvm_has "wget"; then - wget "$@" + # Adding -O- to output to stdout for wget + wget -O- "$@" else phpvm_err "curl or wget is required to install phpvm." exit 1 @@ -49,11 +50,20 @@ return fi - local DETECTED_PROFILE='' - if [ "${SHELL#*zsh}" != "$SHELL" ]; then - if [ -f "$HOME/.zshrc" ]; then DETECTED_PROFILE="$HOME/.zshrc"; fi - elif [ "${SHELL#*bash}" != "$SHELL" ]; then - if [ -f "$HOME/.bashrc" ]; then DETECTED_PROFILE="$HOME/.bashrc"; fi + local DETECTED_PROFILE="" + local SHELL_NAME="" + + # Get the shell from PS1 or SHELL variable + SHELL_NAME="$(basename "$SHELL")" + + if [ "$SHELL_NAME" = "zsh" ]; then + if [ -f "$HOME/.zshrc" ]; then + DETECTED_PROFILE="$HOME/.zshrc" + fi + elif [ "$SHELL_NAME" = "bash" ]; then + if [ -f "$HOME/.bashrc" ]; then + DETECTED_PROFILE="$HOME/.bashrc" + fi fi if [ -z "$DETECTED_PROFILE" ]; then @@ -71,10 +81,14 @@ install_phpvm_as_script() { local INSTALL_DIR INSTALL_DIR="$(phpvm_install_dir)" - mkdir -p "$INSTALL_DIR/bin" + phpvm_echo "Downloading phpvm script from $GITHUB_REPO_URL..." - phpvm_download -fsSL "$GITHUB_REPO_URL" -o "$INSTALL_DIR/phpvm.sh" + phpvm_download "$GITHUB_REPO_URL" >"$INSTALL_DIR/phpvm.sh" || { + phpvm_err "Failed to download phpvm script" + exit 1 + } + chmod +x "$INSTALL_DIR/phpvm.sh" ln -sf "$INSTALL_DIR/phpvm.sh" "$INSTALL_DIR/bin/phpvm" } @@ -86,19 +100,23 @@ local PROFILE PROFILE="$(phpvm_detect_profile)" - if [ -n "$PROFILE" ] && ! grep -qc 'phpvm.sh' "$PROFILE"; then + if [ -n "$PROFILE" ] && ! grep -q 'phpvm.sh' "$PROFILE"; then phpvm_echo "Appending phpvm source to $PROFILE" - echo -e "\nexport PHPVM_DIR=\"$(phpvm_install_dir)\"\nexport PATH=\"\$PHPVM_DIR/bin:\$PATH\"\n[ -s \"\$PHPVM_DIR/phpvm.sh\" ] && \\. \"\$PHPVM_DIR/phpvm.sh\"" >>"$PROFILE" + printf "\nexport PHPVM_DIR=\"%s\"\nexport PATH=\"\$PHPVM_DIR/bin:\$PATH\"\n[ -s \"\$PHPVM_DIR/phpvm.sh\" ] && . \"\$PHPVM_DIR/phpvm.sh\"\n" "$(phpvm_install_dir)" >>"$PROFILE" fi phpvm_echo "Applying changes..." export PATH="$PHPVM_DIR/bin:$PATH" - source "$PROFILE" || true + + # Only source the profile if it exists + if [ -f "$PROFILE" ]; then + # Use . instead of source for POSIX compatibility + . "$PROFILE" || true + fi phpvm_echo "phpvm installation complete!" phpvm_echo "Run: phpvm use 8.4" } phpvm_do_install - } # End of script diff --git a/phpvm.sh b/phpvm.sh index 9faf8c0..12d855f 100755 --- a/phpvm.sh +++ b/phpvm.sh @@ -1,19 +1,19 @@ #!/bin/sh -# phpvm - A PHP Version Manager written in Shell +# phpvm - A PHP Version Manager for macOS and Linux PHPVM_DIR="$HOME/.phpvm" PHPVM_VERSIONS_DIR="$PHPVM_DIR/versions" PHPVM_ACTIVE_VERSION_FILE="$PHPVM_DIR/active_version" PHPVM_CURRENT_SYMLINK="$PHPVM_DIR/current" -HOMEBREW_PHP_CELLAR="/opt/homebrew/Cellar" -HOMEBREW_PHP_BIN="/opt/homebrew/bin" DEBUG=false # Set to true to enable debug logs -# Create the required directory and exit if it fails. -mkdir -p "$PHPVM_VERSIONS_DIR" || { - echo "Error: Failed to create directory $PHPVM_VERSIONS_DIR" >&2 - exit 1 +# Create the required directory structure +create_directories() { + mkdir -p "$PHPVM_VERSIONS_DIR" || { + echo "Error: Failed to create directory $PHPVM_VERSIONS_DIR" >&2 + exit 1 + } } # ANSI color codes @@ -28,102 +28,212 @@ phpvm_err() { printf "%sError: %s%s\n" "$RED" "$*" "$RESET" >&2; } phpvm_warn() { printf "%sWarning: %s%s\n" "$YELLOW" "$*" "$RESET" >&2; } phpvm_debug() { [ "$DEBUG" = "true" ] && echo "Debug: $*"; } -# Helper function to check if Homebrew is installed -is_brew_installed() { - command -v brew >/dev/null 2>&1 -} - -# Ensure Homebrew is installed before proceeding -if ! is_brew_installed; then - phpvm_err "Homebrew is not installed. Please install Homebrew first." - exit 1 -fi - -# Helper function to install PHP using Homebrew -brew_install_php() { - version="$1" - phpvm_debug "Attempting to install PHP $version using Homebrew..." - if ! brew install php@"$version"; then - phpvm_warn "php@$version is not available in Homebrew. Trying latest version..." - if ! brew install php; then - phpvm_err "Failed to install PHP." - return 1 +# Detect the system's package manager and OS +detect_system() { + if [ "$(uname)" = "Darwin" ]; then + PKG_MANAGER="brew" + if ! command -v brew >/dev/null 2>&1; then + phpvm_err "Homebrew is not installed. Please install Homebrew first." + exit 1 fi + HOMEBREW_PREFIX="/opt/homebrew" + PHP_BIN_PATH="$HOMEBREW_PREFIX/bin" + return 0 fi - return 0 -} -# Helper function to get the installed PHP version -get_installed_php_version() { - phpvm_debug "Getting installed PHP version..." - if command -v php-config >/dev/null 2>&1; then - php-config --version + # Detect Linux package manager + if command -v apt-get >/dev/null 2>&1; then + PKG_MANAGER="apt" + PHP_BIN_PATH="/usr/bin" + elif command -v dnf >/dev/null 2>&1; then + PKG_MANAGER="dnf" + PHP_BIN_PATH="/usr/bin" + elif command -v yum >/dev/null 2>&1; then + PKG_MANAGER="yum" + PHP_BIN_PATH="/usr/bin" + elif command -v pacman >/dev/null 2>&1; then + PKG_MANAGER="pacman" + PHP_BIN_PATH="/usr/bin" + elif command -v brew >/dev/null 2>&1; then + PKG_MANAGER="brew" + # Detect Linuxbrew path + if [ -d "/home/linuxbrew/.linuxbrew" ]; then + HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew" + elif [ -d "$HOME/.linuxbrew" ]; then + HOMEBREW_PREFIX="$HOME/.linuxbrew" + else + HOMEBREW_PREFIX="/usr/local" # Fallback location + fi + PHP_BIN_PATH="$HOMEBREW_PREFIX/bin" else - php -v | awk '/^PHP/ {print $2}' + phpvm_err "No supported package manager found (apt, dnf, yum, pacman, or brew)." + exit 1 fi } +# Install PHP using the detected package manager install_php() { version="$1" [ -z "$version" ] && { phpvm_err "No PHP version specified for installation." return 1 } + phpvm_echo "Installing PHP $version..." - brew_install_php "$version" || return 1 + + case "$PKG_MANAGER" in + brew) + if ! brew install php@"$version"; then + phpvm_warn "php@$version is not available in Homebrew. Trying latest version..." + if ! brew install php; then + phpvm_err "Failed to install PHP." + return 1 + fi + fi + ;; + apt) + # Check if we need sudo + if [ "$(id -u)" -ne 0 ]; then + SUDO="sudo" + else + SUDO="" + fi + + $SUDO apt-get update + if ! $SUDO apt-get install -y php"$version"; then + phpvm_err "Failed to install PHP $version. Package php$version may not exist." + return 1 + fi + ;; + dnf | yum) + # Check if we need sudo + if [ "$(id -u)" -ne 0 ]; then + SUDO="sudo" + else + SUDO="" + fi + + if ! $SUDO $PKG_MANAGER install -y php"$version"; then + # Try with full version format for some repos + if ! $SUDO $PKG_MANAGER install -y php-"$version".0; then + phpvm_err "Failed to install PHP $version. Package php$version may not exist." + return 1 + fi + fi + ;; + pacman) + # Check if we need sudo + if [ "$(id -u)" -ne 0 ]; then + SUDO="sudo" + else + SUDO="" + fi + + $SUDO pacman -Sy + if ! $SUDO pacman -S --noconfirm php"$version"; then + phpvm_err "Failed to install PHP $version. Package php$version may not exist." + return 1 + fi + ;; + esac + phpvm_echo "PHP $version installed." return 0 } +# Helper function to get the installed PHP version +get_installed_php_version() { + phpvm_debug "Getting installed PHP version..." + if command -v php-config >/dev/null 2>&1; then + php-config --version + else + php -v | awk '/^PHP/ {print $2}' + fi +} + use_php_version() { version="$1" [ -z "$version" ] && { phpvm_err "No PHP version specified to switch." return 1 } + phpvm_echo "Switching to PHP $version..." - phpvm_debug "Unlinking any existing PHP version..." - brew unlink php >/dev/null 2>&1 || phpvm_warn "Failed to unlink current PHP version." - if [ -d "$HOMEBREW_PHP_CELLAR/php@$version" ]; then - phpvm_debug "Linking PHP $version..." - brew link php@"$version" --force --overwrite || { - phpvm_err "Failed to link PHP $version." + + case "$PKG_MANAGER" in + brew) + phpvm_debug "Unlinking any existing PHP version..." + brew unlink php >/dev/null 2>&1 || phpvm_warn "Failed to unlink current PHP version." + + if [ -d "$HOMEBREW_PREFIX/Cellar/php@$version" ]; then + phpvm_debug "Linking PHP $version..." + brew link php@"$version" --force --overwrite || { + phpvm_err "Failed to link PHP $version." + return 1 + } + elif [ -d "$HOMEBREW_PREFIX/Cellar/php" ]; then + installed_version=$(get_installed_php_version) + if [ "$installed_version" = "$version" ]; then + phpvm_echo "Using PHP $version installed as 'php'." + else + phpvm_err "PHP version $version is not installed. Installed version: $installed_version" + return 1 + fi + else + phpvm_err "PHP version $version is not installed." return 1 - } - elif [ -d "$HOMEBREW_PHP_CELLAR/php" ]; then - installed_version=$(get_installed_php_version) - if [ "$installed_version" = "$version" ]; then - phpvm_echo "Using PHP $version installed as 'php'." + fi + ;; + apt | dnf | yum | pacman) + # For Linux package managers, we use update-alternatives if available + if command -v update-alternatives >/dev/null 2>&1; then + # Check if we need sudo + if [ "$(id -u)" -ne 0 ]; then + SUDO="sudo" + else + SUDO="" + fi + + if [ -f "/usr/bin/php$version" ]; then + $SUDO update-alternatives --set php "/usr/bin/php$version" || { + phpvm_err "Failed to switch to PHP $version using update-alternatives." + return 1 + } + else + phpvm_err "PHP binary for version $version not found at /usr/bin/php$version" + return 1 + fi else - phpvm_err "PHP version $version is not installed. Installed version: $installed_version" + phpvm_err "update-alternatives command not found. Cannot switch PHP versions on this system." return 1 fi - else - phpvm_err "PHP version $version is not installed." - return 1 - } + ;; + esac + phpvm_debug "Updating symlink to PHP $version..." rm -f "$PHPVM_CURRENT_SYMLINK" - ln -s "$HOMEBREW_PHP_BIN/php" "$PHPVM_CURRENT_SYMLINK" || { + ln -s "$PHP_BIN_PATH/php" "$PHPVM_CURRENT_SYMLINK" || { phpvm_err "Failed to update symlink." return 1 } + echo "$version" >"$PHPVM_ACTIVE_VERSION_FILE" || { phpvm_err "Failed to write active version." return 1 } + phpvm_echo "Switched to PHP $version." + return 0 } auto_switch_php_version() { - local current_dir="$PWD" - local found=0 - local depth=0 - local max_depth=5 + current_dir="$PWD" + found=0 + depth=0 + max_depth=5 while [ "$current_dir" != "/" ] && [ $depth -lt $max_depth ]; do if [ -f "$current_dir/.phpvmrc" ]; then - local version if ! version=$(tr -d '[:space:]' <"$current_dir/.phpvmrc"); then phpvm_err "Failed to read $current_dir/.phpvmrc" return 1 @@ -152,34 +262,106 @@ auto_switch_php_version() { return 0 } +list_installed_versions() { + phpvm_echo "Installed PHP versions:" + + case "$PKG_MANAGER" in + brew) + if [ -d "$HOMEBREW_PREFIX/Cellar" ]; then + for dir in "$HOMEBREW_PREFIX/Cellar/php"*; do + if [ -d "$dir" ]; then + base_name=$(basename "$dir") + if [ "$base_name" = "php" ]; then + version=$(get_installed_php_version) + echo " $version (latest)" + else + # Extract version from php@X.Y format + version=${base_name#php@} + echo " $version" + fi + fi + done + fi + ;; + apt) + dpkg -l | grep -E '^ii +php[0-9]+\.[0-9]+' | awk '{print " " $2}' | sed 's/^ php//' + ;; + dnf | yum) + $PKG_MANAGER list installed | grep -E 'php[0-9]+\.' | awk '{print " " $1}' | sed 's/^ php//' + ;; + pacman) + pacman -Q | grep '^php' | awk '{print " " $1}' | sed 's/^ php//' + ;; + esac + + echo "" + if [ -f "$PHPVM_ACTIVE_VERSION_FILE" ]; then + active_version=$(cat "$PHPVM_ACTIVE_VERSION_FILE") + phpvm_echo "Active version: $active_version" + else + phpvm_warn "No active PHP version set." + fi +} + +print_help() { + cat < Install specified PHP version + phpvm use Switch to specified PHP version + phpvm auto Auto-switch based on .phpvmrc file + phpvm list List installed PHP versions + phpvm help Show this help message + +Examples: + phpvm install 8.1 Install PHP 8.1 + phpvm use 7.4 Switch to PHP 7.4 + phpvm auto Auto-switch based on current directory +EOF +} + main() { + create_directories + detect_system + if [ "$#" -eq 0 ]; then - phpvm_err "No command provided. Available commands: install , use ." - return 1 + phpvm_err "No command provided." + print_help + exit 1 fi + command="$1" shift + case "$command" in use) if [ "$#" -eq 0 ]; then phpvm_err "Missing PHP version argument for 'use' command." - return 1 + exit 1 fi use_php_version "$@" ;; install) if [ "$#" -eq 0 ]; then phpvm_err "Missing PHP version argument for 'install' command." - return 1 + exit 1 fi install_php "$@" ;; auto) auto_switch_php_version ;; + list) + list_installed_versions + ;; + help) + print_help + ;; *) - phpvm_err "Unknown command: $command. Available commands: install , use ." - return 1 + phpvm_err "Unknown command: $command" + print_help + exit 1 ;; esac } diff --git a/test_phpvm.bats b/test_phpvm.bats index ef3f884..ba889d1 100644 --- a/test_phpvm.bats +++ b/test_phpvm.bats @@ -1,68 +1,209 @@ #!/usr/bin/env bats -# Source the script under test. +# Set up test environment setup() { - ORIGINAL_PATH="$PATH" - MOCK_DIR="$(mktemp -d)" - PATH="$MOCK_DIR:$PATH" + # Create a temporary directory for tests + export TEMP_DIR=$(mktemp -d) + export HOME="$TEMP_DIR" + export PHPVM_DIR="$HOME/.phpvm" + export PHPVM_VERSIONS_DIR="$PHPVM_DIR/versions" + export PHPVM_ACTIVE_VERSION_FILE="$PHPVM_DIR/active_version" + export PHPVM_CURRENT_SYMLINK="$PHPVM_DIR/current" - # Ensure phpvm.sh exists before sourcing - if [[ ! -f "./phpvm.sh" ]]; then - echo "Error: phpvm.sh not found!" - exit 1 - fi + # Mock the brew command + mkdir -p "$TEMP_DIR/bin" + cat >"$TEMP_DIR/bin/brew" <<'EOF' +#!/bin/sh +if [ "$1" = "install" ]; then + if [ "$2" = "php@7.4" ]; then + echo "Installing php@7.4..." + mkdir -p /opt/homebrew/Cellar/php@7.4/bin + return 0 + elif [ "$2" = "php" ]; then + echo "Installing php (latest)..." + mkdir -p /opt/homebrew/Cellar/php/bin + return 0 + else + echo "Error: Formula php@$2 not available" >&2 + return 1 + fi +elif [ "$1" = "unlink" ]; then + return 0 +elif [ "$1" = "link" ]; then + return 0 +fi +EOF + chmod +x "$TEMP_DIR/bin/brew" - chmod +x "./phpvm.sh" - source "./phpvm.sh" + # Mock php and php-config + cat >"$TEMP_DIR/bin/php" <<'EOF' +#!/bin/sh +if [ "$1" = "-v" ]; then + echo "PHP 8.0.0 (cli)" +fi +EOF + chmod +x "$TEMP_DIR/bin/php" + + cat >"$TEMP_DIR/bin/php-config" <<'EOF' +#!/bin/sh +if [ "$1" = "--version" ]; then + echo "8.0.0" +fi +EOF + chmod +x "$TEMP_DIR/bin/php-config" + + # Add mocks to PATH + export PATH="$TEMP_DIR/bin:$PATH" + + # Create required directories + mkdir -p /opt/homebrew/Cellar + mkdir -p /opt/homebrew/bin + + # Source the script under test + source ./phpvm } +# Clean up after tests teardown() { - PATH="$ORIGINAL_PATH" - rm -rf "$MOCK_DIR" - # Ensure .phpvmrc exists before attempting to remove it - if [[ -f "$PWD/.phpvmrc" ]]; then - rm -f "$PWD/.phpvmrc" - fi + rm -rf "$TEMP_DIR" +} + +# Utility function to create mock PHP installations +create_mock_php_installation() { + local version="$1" + mkdir -p "/opt/homebrew/Cellar/php@$version" + mkdir -p "/opt/homebrew/bin" + touch "/opt/homebrew/bin/php" +} + +# Test directory creation +@test "phpvm creates required directories" { + rm -rf "$PHPVM_DIR" + mkdir -p "$PHPVM_DIR" || true + [ -d "$PHPVM_VERSIONS_DIR" ] +} + +# Test install command +@test "install command with valid version" { + run install_php "7.4" + [ "$status" -eq 0 ] + [[ "$output" == *"Installing PHP 7.4"* ]] + [[ "$output" == *"PHP 7.4 installed"* ]] } -@test "install_php returns error if version not provided" { +@test "install command with missing version" { run install_php "" - [ "$status" -ne 0 ] - [[ "$output" == *"No PHP version specified"* ]] + [ "$status" -eq 1 ] + [[ "$output" == *"No PHP version specified for installation"* ]] } -@test "install_php calls brew with version" { - run install_php "8.3" +# Test use command +@test "use command with installed version" { + create_mock_php_installation "7.4" + run use_php_version "7.4" [ "$status" -eq 0 ] - [[ "$output" == *"Installing PHP 8.3..."* ]] - [[ "$output" == *"PHP 8.3 installed."* ]] + [[ "$output" == *"Switching to PHP 7.4"* ]] + [[ "$output" == *"Switched to PHP 7.4"* ]] + [ "$(cat $PHPVM_ACTIVE_VERSION_FILE)" == "7.4" ] } -@test "use_php_version returns error if version not provided" { +@test "use command with missing version" { run use_php_version "" - [ "$status" -ne 0 ] - [[ "$output" == *"No PHP version specified to switch."* ]] + [ "$status" -eq 1 ] + [[ "$output" == *"No PHP version specified to switch"* ]] } -@test "use_php_version returns error if version not installed (brew cellar missing)" { - run use_php_version "7.4" - [ "$status" -ne 0 ] - [[ "$output" == *"PHP version 7.4 is not installed"* ]] +@test "use command with non-installed version" { + run use_php_version "5.6" + [ "$status" -eq 1 ] + [[ "$output" == *"PHP version 5.6 is not installed"* ]] } -@test "auto_switch_php_version warns when .phpvmrc is not found" { +# Test auto-switch functionality +@test "auto-switch with valid .phpvmrc" { + create_mock_php_installation "7.4" + mkdir -p "$HOME/project" + echo "7.4" >"$HOME/project/.phpvmrc" + cd "$HOME/project" run auto_switch_php_version - [ "$status" -ne 0 ] - [[ "$output" == *"No .phpvmrc file found"* ]] + [ "$status" -eq 0 ] + [[ "$output" == *"Auto-switching to PHP 7.4"* ]] + [ "$(cat $PHPVM_ACTIVE_VERSION_FILE)" == "7.4" ] +} + +@test "auto-switch with invalid .phpvmrc" { + mkdir -p "$HOME/project" + echo "" >"$HOME/project/.phpvmrc" + cd "$HOME/project" + run auto_switch_php_version + [ "$status" -eq 1 ] + [[ "$output" == *"No valid PHP version found"* ]] } -@test "auto_switch_php_version switches PHP version from .phpvmrc" { - echo "8.3" >.phpvmrc - export HOMEBREW_PHP_CELLAR="/opt/homebrew/Cellar" - export HOMEBREW_PHP_BIN="/opt/homebrew/bin" # Ensure binary path is available +@test "auto-switch with no .phpvmrc" { + mkdir -p "$HOME/project" + cd "$HOME/project" run auto_switch_php_version - echo "Test output: $output" # Debugging line to inspect output + [ "$status" -eq 1 ] + [[ "$output" == *"No .phpvmrc file found"* ]] +} + +# Test main command dispatcher +@test "main with no arguments" { + run main + [ "$status" -eq 1 ] + [[ "$output" == *"No command provided"* ]] +} + +@test "main with unknown command" { + run main "unknown" + [ "$status" -eq 1 ] + [[ "$output" == *"Unknown command: unknown"* ]] +} + +@test "main with use command but no version" { + run main "use" + [ "$status" -eq 1 ] + [[ "$output" == *"Missing PHP version argument for 'use' command"* ]] +} + +@test "main with install command but no version" { + run main "install" + [ "$status" -eq 1 ] + [[ "$output" == *"Missing PHP version argument for 'install' command"* ]] +} + +@test "main with valid use command" { + create_mock_php_installation "7.4" + run main "use" "7.4" + [ "$status" -eq 0 ] + [[ "$output" == *"Switched to PHP 7.4"* ]] +} + +@test "main with valid install command" { + run main "install" "7.4" + [ "$status" -eq 0 ] + [[ "$output" == *"PHP 7.4 installed"* ]] +} + +@test "main with valid auto command" { + create_mock_php_installation "7.4" + mkdir -p "$HOME/project" + echo "7.4" >"$HOME/project/.phpvmrc" + cd "$HOME/project" + run main "auto" + [ "$status" -eq 0 ] + [[ "$output" == *"Auto-switching to PHP 7.4"* ]] +} + +# Test helper functions +@test "get_installed_php_version returns correct version" { + run get_installed_php_version + [ "$status" -eq 0 ] + [ "$output" = "8.0.0" ] +} + +@test "is_brew_installed returns success" { + run is_brew_installed [ "$status" -eq 0 ] - [[ "$output" == *"Auto-switching to PHP 8.3"* ]] - rm -f .phpvmrc # Cleanup after test }