-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor GitHub Actions workflows for PHPVM: streamline job configura…
…tions, update Node.js actions, and enhance test scripts.
- Loading branch information
1 parent
9b98de5
commit 1c8e267
Showing
4 changed files
with
51 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
#!/usr/bin/env bats | ||
|
||
# Source the script under test. | ||
# Adjust the relative path if necessary. | ||
source "./phpvm.sh" | ||
|
||
setup() { | ||
# Save the original PATH | ||
ORIGINAL_PATH="$PATH" | ||
# Create a temporary directory for our mock commands | ||
MOCK_DIR="$(mktemp -d)" | ||
PATH="$MOCK_DIR:$PATH" | ||
|
||
# Create a dummy 'brew' command | ||
cat <<'EOF' >"$MOCK_DIR/brew" | ||
#!/bin/bash | ||
# Simply print the arguments to verify the call. | ||
echo "brew $*" | ||
exit 0 | ||
EOF | ||
chmod +x "$MOCK_DIR/brew" | ||
# Ensure phpvm.sh exists before sourcing | ||
if [[ ! -f "./phpvm.sh" ]]; then | ||
echo "Error: phpvm.sh not found!" | ||
exit 1 | ||
fi | ||
|
||
chmod +x "./phpvm.sh" | ||
source "./phpvm.sh" | ||
} | ||
|
||
teardown() { | ||
PATH="$ORIGINAL_PATH" | ||
rm -rf "$MOCK_DIR" | ||
# Remove any temporary test directories if created. | ||
[ -n "$TEST_DIR" ] && rm -rf "$TEST_DIR" | ||
# Ensure .phpvmrc exists before attempting to remove it | ||
if [[ -f "$PWD/.phpvmrc" ]]; then | ||
rm -f "$PWD/.phpvmrc" | ||
fi | ||
} | ||
|
||
@test "install_php returns error if version not provided" { | ||
|
@@ -35,11 +32,10 @@ teardown() { | |
} | ||
|
||
@test "install_php calls brew with version" { | ||
run install_php "7.4" | ||
run install_php "8.3" | ||
[ "$status" -eq 0 ] | ||
# Check that the function echoed the installation messages. | ||
[[ "$output" == *"Installing PHP 7.4..."* ]] | ||
[[ "$output" == *"PHP 7.4 installed."* ]] | ||
[[ "$output" == *"Installing PHP 8.3..."* ]] | ||
[[ "$output" == *"PHP 8.3 installed."* ]] | ||
} | ||
|
||
@test "use_php_version returns error if version not provided" { | ||
|
@@ -55,27 +51,18 @@ teardown() { | |
} | ||
|
||
@test "auto_switch_php_version warns when .phpvmrc is not found" { | ||
# Run from a temporary directory that does not contain .phpvmrc. | ||
TEST_DIR="$(mktemp -d)" | ||
pushd "$TEST_DIR" >/dev/null | ||
run auto_switch_php_version | ||
popd >/dev/null | ||
[ "$status" -ne 0 ] | ||
[[ "$output" == *"No .phpvmrc file found"* ]] | ||
} | ||
|
||
@test "auto_switch_php_version switches PHP version from .phpvmrc" { | ||
# Create a temporary directory with a .phpvmrc file | ||
TEST_DIR="$(mktemp -d)" | ||
echo "7.4" >"$TEST_DIR/.phpvmrc" | ||
|
||
# Create a fake Homebrew cellar directory to simulate an installed PHP version. | ||
mkdir -p "/opt/homebrew/Cellar/[email protected]" | ||
|
||
pushd "$TEST_DIR" >/dev/null | ||
echo "8.3" >.phpvmrc | ||
export HOMEBREW_PHP_CELLAR="/opt/homebrew/Cellar" | ||
export HOMEBREW_PHP_BIN="/opt/homebrew/bin" # Ensure binary path is available | ||
run auto_switch_php_version | ||
popd >/dev/null | ||
|
||
echo "Test output: $output" # Debugging line to inspect output | ||
[ "$status" -eq 0 ] | ||
[[ "$output" == *"Auto-switching to PHP 7.4"* ]] | ||
[[ "$output" == *"Auto-switching to PHP 8.3"* ]] | ||
rm -f .phpvmrc # Cleanup after test | ||
} |