Skip to content

Commit dbea04c

Browse files
committed
fix: update environment variable names for debug logging consistency
1 parent ebeb045 commit dbea04c

5 files changed

Lines changed: 140 additions & 35 deletions

File tree

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ Conventions: tag = `X.Y.Z` (no `v` prefix), title = `vX.Y.Z` (with `v` prefix).
4343

4444
- `PHPVM_DIR` — Installation directory (default: `~/.phpvm`)
4545
- `PHPVM_TEST_MODE` — Enable test/mock mode
46-
- `DEBUG` — Enable debug logging
46+
- `PHPVM_DEBUG` — Enable debug logging
4747
- `PHPVM_AUTO_USE` — Enable automatic `.phpvmrc` detection
4848
- `PHPVM_PHPVMRC_MAX_DEPTH` — Max parent directory traversal for `.phpvmrc` (default: 25)

CLAUDE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The tool detects and works with multiple package managers:
7070
- ShellCheck static analysis for code quality
7171

7272
### Debugging
73-
- Enable debug mode: `DEBUG=true phpvm <command>`
73+
- Enable debug mode: `PHPVM_DEBUG=true phpvm <command>`
7474
- Debug logs provide detailed execution tracing
7575
- Test mode can be enabled with `PHPVM_TEST_MODE=true`
7676

@@ -100,11 +100,11 @@ bats tests/
100100
bats tests/01_core.bats
101101

102102
# Enable debug mode for troubleshooting
103-
DEBUG=true bats tests/
103+
PHPVM_DEBUG=true bats tests/
104104

105105
# Test specific functionality manually with test mode
106-
PHPVM_TEST_MODE=true DEBUG=true ./phpvm.sh install 8.1
107-
PHPVM_TEST_MODE=true DEBUG=true ./phpvm.sh use 8.1
106+
PHPVM_TEST_MODE=true PHPVM_DEBUG=true ./phpvm.sh install 8.1
107+
PHPVM_TEST_MODE=true PHPVM_DEBUG=true ./phpvm.sh use 8.1
108108

109109
# Check shell syntax
110110
bash -n phpvm.sh
@@ -177,7 +177,7 @@ phpvm/
177177
## Environment Variables
178178

179179
- `PHPVM_DIR` - Installation directory (default: `~/.phpvm`)
180-
- `DEBUG` - Enable debug logging (set to `true`)
180+
- `PHPVM_DEBUG` - Enable debug logging (set to `true`)
181181
- `PHPVM_TEST_MODE` - Enable test mode (set to `true`)
182182
- `PHPVM_SOURCED` - Control execution vs sourcing behavior
183183
- `PHPVM_AUTO_USE` - Enable automatic `.phpvmrc` detection (default: `true`)

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,24 @@ If the installation was successful, it should output the path to `phpvm`.
9595

9696
### Available Commands
9797

98-
| Command | Description |
99-
| --------------------------- | ------------------------------------------ |
100-
| `phpvm install [version]` | Install a PHP version (reads `.phpvmrc` if no version given) |
98+
| Command | Description |
99+
| --------------------------- | ------------------------------------------------------------------------- |
100+
| `phpvm install [version]` | Install a PHP version (reads `.phpvmrc` if no version given) |
101101
| `phpvm use [version]` | Switch PHP version (reads `.phpvmrc` → default alias if no version given) |
102-
| `phpvm uninstall <version>` | Remove a specific PHP version |
103-
| `phpvm current` | Display the currently active PHP version |
104-
| `phpvm which [version]` | Show the path to PHP binary for a version |
105-
| `phpvm deactivate` | Temporarily disable phpvm and restore PATH |
106-
| `phpvm system` | Switch to system/Homebrew default PHP |
107-
| `phpvm auto` | Auto-switch based on `.phpvmrc` file |
108-
| `phpvm list` or `phpvm ls` | List all installed PHP versions |
109-
| `phpvm alias [name] [ver]` | Create, update, or list version aliases |
110-
| `phpvm unalias <name>` | Remove version alias |
111-
| `phpvm cache dir` | Show phpvm cache directory |
112-
| `phpvm info` | Show system information for debugging |
113-
| `phpvm version` | Show version information |
114-
| `phpvm --version` / `-v` | Show version information (aliases) |
115-
| `phpvm help` | Show help message |
102+
| `phpvm uninstall <version>` | Remove a specific PHP version |
103+
| `phpvm current` | Display the currently active PHP version |
104+
| `phpvm which [version]` | Show the path to PHP binary for a version |
105+
| `phpvm deactivate` | Temporarily disable phpvm and restore PATH |
106+
| `phpvm system` | Switch to system/Homebrew default PHP |
107+
| `phpvm auto` | Auto-switch based on `.phpvmrc` file |
108+
| `phpvm list` or `phpvm ls` | List all installed PHP versions |
109+
| `phpvm alias [name] [ver]` | Create, update, or list version aliases |
110+
| `phpvm unalias <name>` | Remove version alias |
111+
| `phpvm cache dir` | Show phpvm cache directory |
112+
| `phpvm info` | Show system information for debugging |
113+
| `phpvm version` | Show version information |
114+
| `phpvm --version` / `-v` | Show version information (aliases) |
115+
| `phpvm help` | Show help message |
116116

117117
### Installing PHP Versions
118118

@@ -341,7 +341,7 @@ fi
341341
| `PHPVM_DIR` | `~/.phpvm` | Installation directory |
342342
| `PHPVM_AUTO_USE` | `true` | Enable automatic `.phpvmrc` detection when sourced |
343343
| `PHPVM_PHPVMRC_MAX_DEPTH` | `25` | Max parent directories to traverse when searching for `.phpvmrc` |
344-
| `DEBUG` | `false` | Enable debug logging with timestamps |
344+
| `PHPVM_DEBUG` | `false` | Enable debug logging with timestamps |
345345
| `NO_COLOR` | _(unset)_ | Disable color output ([no-color.org](https://no-color.org/)) |
346346
| `PHPVM_LOG_TIMESTAMPS` | `false` | Always show timestamps in log output |
347347

@@ -518,15 +518,15 @@ bats tests/01_core.bats
518518
./phpvm.sh info
519519

520520
# Test with debug output
521-
DEBUG=true ./phpvm.sh version
521+
PHPVM_DEBUG=true ./phpvm.sh version
522522
```
523523

524524
### Debugging
525525

526-
To enable debug output, set the `DEBUG` environment variable to `true`:
526+
To enable debug output, set the `PHPVM_DEBUG` environment variable to `true`:
527527

528528
```sh
529-
DEBUG=true phpvm install 8.1
529+
PHPVM_DEBUG=true phpvm install 8.1
530530
```
531531

532532
## Maintainers

install.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,20 @@
103103
PROFILE="$(phpvm_detect_profile)"
104104

105105
if [ -n "$PROFILE" ]; then
106-
phpvm_echo "Adding phpvm to $PROFILE"
107-
108-
# Check shell type and use appropriate syntax
109-
if echo "$PROFILE" | grep -q "zsh"; then
110-
# For zsh - use proper if statement to prevent shell crash
111-
printf "\nexport PHPVM_DIR=\"%s\"\nexport PATH=\"\$PHPVM_DIR/bin:\$PATH\"\nif [[ -s \"\$PHPVM_DIR/phpvm.sh\" ]]; then\n source \"\$PHPVM_DIR/phpvm.sh\"\nfi\n" "$(phpvm_install_dir)" >> "$PROFILE"
106+
# Check if phpvm is already configured in the profile
107+
if grep -qF 'PHPVM_DIR' "$PROFILE" 2>/dev/null; then
108+
phpvm_echo "phpvm already configured in $PROFILE (skipping)"
112109
else
113-
# For bash and others - use POSIX compatible syntax
114-
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"
110+
phpvm_echo "Adding phpvm to $PROFILE"
111+
112+
# Check shell type and use appropriate syntax
113+
if echo "$PROFILE" | grep -q "zsh"; then
114+
# For zsh - use proper if statement to prevent shell crash
115+
printf "\nexport PHPVM_DIR=\"%s\"\nexport PATH=\"\$PHPVM_DIR/bin:\$PATH\"\nif [[ -s \"\$PHPVM_DIR/phpvm.sh\" ]]; then\n source \"\$PHPVM_DIR/phpvm.sh\"\nfi\n" "$(phpvm_install_dir)" >> "$PROFILE"
116+
else
117+
# For bash and others - use POSIX compatible syntax
118+
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"
119+
fi
115120
fi
116121
else
117122
phpvm_warn "Could not detect profile file. Please manually add the following to your shell profile:"

tests/04_lifecycle.bats

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env bats
2+
# BATS test suite for phpvm - Full lifecycle tests (install → use → current → which → uninstall)
3+
4+
bats_require_minimum_version 1.5.0
5+
6+
load test_helper
7+
8+
@test "lifecycle: install creates mock PHP directory" {
9+
run install_php "8.2"
10+
[ "$status" -eq 0 ]
11+
[[ "$output" =~ "Installing PHP 8.2" ]]
12+
[[ "$output" =~ "PHP 8.2 installed" ]]
13+
14+
# Verify mock directory was created
15+
[ -d "$(phpvm_test_php_cellar_dir "8.2")" ]
16+
[ -x "$(phpvm_test_php_path "8.2")" ]
17+
}
18+
19+
@test "lifecycle: use switches to installed version" {
20+
install_php "8.2"
21+
run use_php_version "8.2"
22+
[ "$status" -eq 0 ]
23+
[[ "$output" =~ "Switched to PHP 8.2" ]]
24+
25+
# Active version file should be updated
26+
[ -f "$PHPVM_ACTIVE_VERSION_FILE" ]
27+
[ "$(cat "$PHPVM_ACTIVE_VERSION_FILE")" = "8.2" ]
28+
}
29+
30+
@test "lifecycle: current shows active version after use" {
31+
install_php "8.2"
32+
use_php_version "8.2"
33+
run phpvm_current
34+
[ "$status" -eq 0 ]
35+
[ "$output" = "8.2" ]
36+
}
37+
38+
@test "lifecycle: which returns binary path for installed version" {
39+
install_php "8.2"
40+
use_php_version "8.2"
41+
run phpvm_which "8.2"
42+
[ "$status" -eq 0 ]
43+
[[ "$output" =~ "php@8.2" ]]
44+
[[ "$output" =~ "/bin/php" ]]
45+
}
46+
47+
@test "lifecycle: use system sets active version to system" {
48+
install_php "8.2"
49+
use_php_version "8.2"
50+
run use_php_version "system"
51+
[ "$status" -eq 0 ]
52+
[[ "$output" =~ "Switched to system PHP" ]]
53+
54+
[ "$(cat "$PHPVM_ACTIVE_VERSION_FILE")" = "system" ]
55+
}
56+
57+
@test "lifecycle: uninstall removes mock PHP directory" {
58+
install_php "8.1"
59+
run uninstall_php "8.1"
60+
[ "$status" -eq 0 ]
61+
[[ "$output" =~ "PHP 8.1 uninstalled" ]]
62+
63+
# Mock directory should be removed
64+
[ ! -d "$(phpvm_test_php_cellar_dir "8.1")" ]
65+
}
66+
67+
@test "lifecycle: use fails for uninstalled version" {
68+
run use_php_version "7.4"
69+
[ "$status" -eq 4 ]
70+
[[ "$output" =~ "not installed" ]]
71+
}
72+
73+
@test "lifecycle: install then use then install another then switch" {
74+
install_php "8.1"
75+
use_php_version "8.1"
76+
[ "$(cat "$PHPVM_ACTIVE_VERSION_FILE")" = "8.1" ]
77+
78+
install_php "8.2"
79+
use_php_version "8.2"
80+
[ "$(cat "$PHPVM_ACTIVE_VERSION_FILE")" = "8.2" ]
81+
82+
run phpvm_current
83+
[ "$output" = "8.2" ]
84+
}
85+
86+
@test "lifecycle: install with X.Y.Z normalizes to X.Y" {
87+
run install_php "8.2.15"
88+
[ "$status" -eq 0 ]
89+
[[ "$output" =~ "Installing PHP 8.2" ]]
90+
[ -d "$(phpvm_test_php_cellar_dir "8.2")" ]
91+
}
92+
93+
@test "lifecycle: list shows installed versions" {
94+
install_php "8.1"
95+
install_php "8.2"
96+
run list_installed_versions
97+
[ "$status" -eq 0 ]
98+
[[ "$output" =~ "8.1" ]]
99+
[[ "$output" =~ "8.2" ]]
100+
}

0 commit comments

Comments
 (0)