From 67cc9453a58235a0fd722eda946b086849d214e3 Mon Sep 17 00:00:00 2001 From: Septian Dwic Date: Thu, 15 Nov 2018 21:00:55 +0700 Subject: [PATCH] Fix rbenv -> phpenv test --- test/--version.bats | 28 +++---- test/commands.bats | 12 +-- test/completions.bats | 18 ++--- test/exec.bats | 84 +++++++-------------- test/global.bats | 26 +++---- test/help.bats | 80 ++++++++++---------- test/hooks.bats | 38 +++++----- test/init.bats | 68 ++++++++--------- test/libexec/phpenv-echo | 2 +- test/local.bats | 106 +++++++++++++------------- test/phpenv.bats | 56 +++++++------- test/prefix.bats | 30 ++++---- test/rehash.bats | 118 ++++++++++++++--------------- test/run | 2 +- test/shell.bats | 42 +++++------ test/shims.bats | 26 +++---- test/test_helper.bash | 36 ++++----- test/version-file-read.bats | 54 ++++++------- test/version-file-write.bats | 24 +++--- test/version-file.bats | 104 ++++++++++++------------- test/version-name.bats | 72 +++++++++--------- test/version-origin.bats | 50 ++++++------ test/version.bats | 36 ++++----- test/versions.bats | 142 +++++++++++++++++------------------ test/whence.bats | 24 +++--- test/which.bats | 110 +++++++++++++-------------- 26 files changed, 678 insertions(+), 710 deletions(-) diff --git a/test/--version.bats b/test/--version.bats index 556c7d6..2f07559 100644 --- a/test/--version.bats +++ b/test/--version.bats @@ -2,13 +2,13 @@ load test_helper -export GIT_DIR="${RBENV_TEST_DIR}/.git" +export GIT_DIR="${PHPENV_TEST_DIR}/.git" setup() { mkdir -p "$HOME" git config --global user.name "Tester" git config --global user.email "tester@test.local" - cd "$RBENV_TEST_DIR" + cd "$PHPENV_TEST_DIR" } git_commit() { @@ -16,40 +16,40 @@ git_commit() { } @test "default version" { - assert [ ! -e "$RBENV_ROOT" ] - run rbenv---version + assert [ ! -e "$PHPENV_ROOT" ] + run phpenv---version assert_success - [[ $output == "rbenv "?.?.? ]] + [[ $output == "phpenv "?.?.? ]] } -@test "doesn't read version from non-rbenv repo" { +@test "doesn't read version from non-phpenv repo" { git init git remote add origin https://github.com/homebrew/homebrew.git git_commit git tag v1.0 - run rbenv---version + run phpenv---version assert_success - [[ $output == "rbenv "?.?.? ]] + [[ $output == "phpenv "?.?.? ]] } @test "reads version from git repo" { git init - git remote add origin https://github.com/rbenv/rbenv.git + git remote add origin https://github.com/sptndc/phpenv.git git_commit git tag v0.4.1 git_commit git_commit - run rbenv---version - assert_success "rbenv 0.4.1-2-g$(git rev-parse --short HEAD)" + run phpenv---version + assert_success "phpenv 0.4.1-2-g$(git rev-parse --short HEAD)" } @test "prints default version if no tags in git repo" { git init - git remote add origin https://github.com/rbenv/rbenv.git + git remote add origin https://github.com/sptndc/phpenv.git git_commit - run rbenv---version - [[ $output == "rbenv "?.?.? ]] + run phpenv---version + [[ $output == "phpenv "?.?.? ]] } diff --git a/test/commands.bats b/test/commands.bats index 81d3860..5f09b3d 100644 --- a/test/commands.bats +++ b/test/commands.bats @@ -3,7 +3,7 @@ load test_helper @test "commands" { - run rbenv-commands + run phpenv-commands assert_success assert_line "init" assert_line "rehash" @@ -13,26 +13,26 @@ load test_helper } @test "commands --sh" { - run rbenv-commands --sh + run phpenv-commands --sh assert_success refute_line "init" assert_line "shell" } @test "commands in path with spaces" { - path="${RBENV_TEST_DIR}/my commands" - cmd="${path}/rbenv-sh-hello" + path="${PHPENV_TEST_DIR}/my commands" + cmd="${path}/phpenv-sh-hello" mkdir -p "$path" touch "$cmd" chmod +x "$cmd" - PATH="${path}:$PATH" run rbenv-commands --sh + PATH="${path}:$PATH" run phpenv-commands --sh assert_success assert_line "hello" } @test "commands --no-sh" { - run rbenv-commands --no-sh + run phpenv-commands --no-sh assert_success assert_line "init" refute_line "shell" diff --git a/test/completions.bats b/test/completions.bats index 6871cf5..7ce5b69 100644 --- a/test/completions.bats +++ b/test/completions.bats @@ -3,28 +3,28 @@ load test_helper create_command() { - bin="${RBENV_TEST_DIR}/bin" + bin="${PHPENV_TEST_DIR}/bin" mkdir -p "$bin" echo "$2" > "${bin}/$1" chmod +x "${bin}/$1" } @test "command with no completion support" { - create_command "rbenv-hello" "#!$BASH + create_command "phpenv-hello" "#!$BASH echo hello" - run rbenv-completions hello + run phpenv-completions hello assert_success "--help" } @test "command with completion support" { - create_command "rbenv-hello" "#!$BASH -# Provide rbenv completions + create_command "phpenv-hello" "#!$BASH +# Provide phpenv completions if [[ \$1 = --complete ]]; then echo hello else exit 1 fi" - run rbenv-completions hello + run phpenv-completions hello assert_success assert_output < .ruby-version - run rbenv-exec rspec - assert_failure "rbenv: version \`1.9' is not installed (set by $PWD/.ruby-version)" + mkdir -p "$PHPENV_TEST_DIR" + cd "$PHPENV_TEST_DIR" + echo 7.1 > .php-version + run phpenv-exec phpize + assert_failure "phpenv: version \`7.1' is not installed (set by $PWD/.php-version)" } @test "completes with names of executables" { - export RBENV_VERSION="2.0" - create_executable "ruby" "#!/bin/sh" - create_executable "rake" "#!/bin/sh" + export PHPENV_VERSION="7.2" + create_executable "php" "#!/bin/sh" + create_executable "php-cgi" "#!/bin/sh" - rbenv-rehash - run rbenv-completions exec + phpenv-rehash + run phpenv-completions exec assert_success assert_output < "${hook_path}/exec/hello.bash" - export RBENV_VERSION=system - RBENV_HOOK_PATH="$hook_path" run rbenv-exec env + export PHPENV_VERSION=system + PHPENV_HOOK_PATH="$hook_path" run phpenv-exec env assert_success assert_line "HELLO=from hook" } @test "carries original IFS within hooks" { - hook_path="${RBENV_TEST_DIR}/rbenv.d" + hook_path="${PHPENV_TEST_DIR}/phpenv.d" mkdir -p "${hook_path}/exec" cat > "${hook_path}/exec/hello.bash" <" { - export RBENV_VERSION="2.0" - - # emulate `ruby -S' behavior - create_executable "ruby" </dev/null; then - \$BASH "\$found" - else - echo "ruby: no Ruby script found in input (LoadError)" >&2 - exit 1 - fi -else - echo 'ruby 2.0 (rbenv test)' -fi -SH - - create_executable "rake" < "$RBENV_ROOT/version" - run rbenv-global +@test "read PHPENV_ROOT/version" { + mkdir -p "$PHPENV_ROOT" + echo "1.2.3" > "$PHPENV_ROOT/version" + run phpenv-global assert_success assert_output "1.2.3" } -@test "set RBENV_ROOT/version" { - mkdir -p "$RBENV_ROOT/versions/1.2.3" - run rbenv-global "1.2.3" +@test "set PHPENV_ROOT/version" { + mkdir -p "$PHPENV_ROOT/versions/1.2.3" + run phpenv-global "1.2.3" assert_success - run rbenv global + run phpenv global assert_success "1.2.3" } -@test "fail setting invalid RBENV_ROOT/version" { - mkdir -p "$RBENV_ROOT" - run rbenv-global "1.2.3" - assert_failure "rbenv: version \`1.2.3' not installed" +@test "fail setting invalid PHPENV_ROOT/version" { + mkdir -p "$PHPENV_ROOT" + run phpenv-global "1.2.3" + assert_failure "phpenv: version \`1.2.3' not installed" } diff --git a/test/help.bats b/test/help.bats index 9862d63..0ec7b30 100644 --- a/test/help.bats +++ b/test/help.bats @@ -3,97 +3,97 @@ load test_helper @test "without args shows summary of common commands" { - run rbenv-help + run phpenv-help assert_success - assert_line "Usage: rbenv []" - assert_line "Some useful rbenv commands are:" + assert_line "Usage: phpenv []" + assert_line "Some useful phpenv commands are:" } @test "invalid command" { - run rbenv-help hello - assert_failure "rbenv: no such command \`hello'" + run phpenv-help hello + assert_failure "phpenv: no such command \`hello'" } @test "shows help for a specific command" { - mkdir -p "${RBENV_TEST_DIR}/bin" - cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < "${PHPENV_TEST_DIR}/bin/phpenv-hello" < -# Summary: Says "hello" to you, from rbenv +# Usage: phpenv hello +# Summary: Says "hello" to you, from phpenv # This command is useful for saying hello. echo hello SH - run rbenv-help hello + run phpenv-help hello assert_success assert_output < +Usage: phpenv hello This command is useful for saying hello. SH } @test "replaces missing extended help with summary text" { - mkdir -p "${RBENV_TEST_DIR}/bin" - cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < "${PHPENV_TEST_DIR}/bin/phpenv-hello" < -# Summary: Says "hello" to you, from rbenv +# Usage: phpenv hello +# Summary: Says "hello" to you, from phpenv echo hello SH - run rbenv-help hello + run phpenv-help hello assert_success assert_output < +Usage: phpenv hello -Says "hello" to you, from rbenv +Says "hello" to you, from phpenv SH } @test "extracts only usage" { - mkdir -p "${RBENV_TEST_DIR}/bin" - cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < "${PHPENV_TEST_DIR}/bin/phpenv-hello" < -# Summary: Says "hello" to you, from rbenv +# Usage: phpenv hello +# Summary: Says "hello" to you, from phpenv # This extended help won't be shown. echo hello SH - run rbenv-help --usage hello - assert_success "Usage: rbenv hello " + run phpenv-help --usage hello + assert_success "Usage: phpenv hello " } @test "multiline usage section" { - mkdir -p "${RBENV_TEST_DIR}/bin" - cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < "${PHPENV_TEST_DIR}/bin/phpenv-hello" < -# rbenv hi [everybody] -# rbenv hola --translate -# Summary: Says "hello" to you, from rbenv +# Usage: phpenv hello +# phpenv hi [everybody] +# phpenv hola --translate +# Summary: Says "hello" to you, from phpenv # Help text. echo hello SH - run rbenv-help hello + run phpenv-help hello assert_success assert_output < - rbenv hi [everybody] - rbenv hola --translate +Usage: phpenv hello + phpenv hi [everybody] + phpenv hola --translate Help text. SH } @test "multiline extended help section" { - mkdir -p "${RBENV_TEST_DIR}/bin" - cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < "${PHPENV_TEST_DIR}/bin/phpenv-hello" < -# Summary: Says "hello" to you, from rbenv +# Usage: phpenv hello +# Summary: Says "hello" to you, from phpenv # This is extended help text. # It can contain multiple lines. # @@ -102,10 +102,10 @@ SH echo hello SH - run rbenv-help hello + run phpenv-help hello assert_success assert_output < +Usage: phpenv hello This is extended help text. It can contain multiple lines. diff --git a/test/hooks.bats b/test/hooks.bats index 99dc4bf..8a62519 100644 --- a/test/hooks.bats +++ b/test/hooks.bats @@ -8,53 +8,53 @@ create_hook() { } @test "prints usage help given no argument" { - run rbenv-hooks - assert_failure "Usage: rbenv hooks " + run phpenv-hooks + assert_failure "Usage: phpenv hooks " } @test "prints list of hooks" { - path1="${RBENV_TEST_DIR}/rbenv.d" - path2="${RBENV_TEST_DIR}/etc/rbenv_hooks" + path1="${PHPENV_TEST_DIR}/phpenv.d" + path2="${PHPENV_TEST_DIR}/etc/phpenv_hooks" create_hook "$path1" exec "hello.bash" create_hook "$path1" exec "ahoy.bash" create_hook "$path1" exec "invalid.sh" create_hook "$path1" which "boom.bash" create_hook "$path2" exec "bueno.bash" - RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec + PHPENV_HOOK_PATH="$path1:$path2" run phpenv-hooks exec assert_success assert_output </dev/null" + assert_line "command phpenv rehash 2>/dev/null" } @test "setup shell completions" { root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" - run rbenv-init - bash + run phpenv-init - bash assert_success - assert_line "source '${root}/test/../libexec/../completions/rbenv.bash'" + assert_line "source '${root}/test/../libexec/../completions/phpenv.bash'" } @test "detect parent shell" { - SHELL=/bin/false run rbenv-init - + SHELL=/bin/false run phpenv-init - assert_success - assert_line "export RBENV_SHELL=bash" + assert_line "export PHPENV_SHELL=bash" } @test "detect parent shell from script" { - mkdir -p "$RBENV_TEST_DIR" - cd "$RBENV_TEST_DIR" + mkdir -p "$PHPENV_TEST_DIR" + cd "$PHPENV_TEST_DIR" cat > myscript.sh </dev/null" + refute_line "phpenv rehash 2>/dev/null" } @test "adds shims to PATH" { export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin" - run rbenv-init - bash + run phpenv-init - bash assert_success - assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' + assert_line 0 'export PATH="'${PHPENV_ROOT}'/shims:${PATH}"' } @test "adds shims to PATH (fish)" { export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin" - run rbenv-init - fish + run phpenv-init - fish assert_success - assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH" + assert_line 0 "setenv PATH '${PHPENV_ROOT}/shims' \$PATH" } @test "can add shims to PATH more than once" { - export PATH="${RBENV_ROOT}/shims:$PATH" - run rbenv-init - bash + export PATH="${PHPENV_ROOT}/shims:$PATH" + run phpenv-init - bash assert_success - assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' + assert_line 0 'export PATH="'${PHPENV_ROOT}'/shims:${PATH}"' } @test "can add shims to PATH more than once (fish)" { - export PATH="${RBENV_ROOT}/shims:$PATH" - run rbenv-init - fish + export PATH="${PHPENV_ROOT}/shims:$PATH" + run phpenv-init - fish assert_success - assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH" + assert_line 0 "setenv PATH '${PHPENV_ROOT}/shims' \$PATH" } @test "outputs sh-compatible syntax" { - run rbenv-init - bash + run phpenv-init - bash assert_success assert_line ' case "$command" in' - run rbenv-init - zsh + run phpenv-init - zsh assert_success assert_line ' case "$command" in' } @test "outputs fish-specific syntax (fish)" { - run rbenv-init - fish + run phpenv-init - fish assert_success assert_line ' switch "$command"' refute_line ' case "$command" in' diff --git a/test/libexec/phpenv-echo b/test/libexec/phpenv-echo index a94af7b..75fa8bc 100755 --- a/test/libexec/phpenv-echo +++ b/test/libexec/phpenv-echo @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Usage: rbenv echo [-F] VAR +# Usage: phpenv echo [-F] VAR if [[ $1 == -F* ]]; then sep="${1:2}" diff --git a/test/local.bats b/test/local.bats index a84833e..22dc789 100644 --- a/test/local.bats +++ b/test/local.bats @@ -3,101 +3,101 @@ load test_helper setup() { - mkdir -p "${RBENV_TEST_DIR}/myproject" - cd "${RBENV_TEST_DIR}/myproject" + mkdir -p "${PHPENV_TEST_DIR}/myproject" + cd "${PHPENV_TEST_DIR}/myproject" } @test "no version" { - assert [ ! -e "${PWD}/.ruby-version" ] - run rbenv-local - assert_failure "rbenv: no local version configured for this directory" + assert [ ! -e "${PWD}/.php-version" ] + run phpenv-local + assert_failure "phpenv: no local version configured for this directory" } @test "local version" { - echo "1.2.3" > .ruby-version - run rbenv-local + echo "1.2.3" > .php-version + run phpenv-local assert_success "1.2.3" } -@test "supports legacy .rbenv-version file" { - echo "1.2.3" > .rbenv-version - run rbenv-local +@test "supports legacy .phpenv-version file" { + echo "1.2.3" > .phpenv-version + run phpenv-local assert_success "1.2.3" } -@test "local .ruby-version has precedence over .rbenv-version" { - echo "1.8" > .rbenv-version - echo "2.0" > .ruby-version - run rbenv-local - assert_success "2.0" +@test "local .php-version has precedence over .phpenv-version" { + echo "7.0" > .phpenv-version + echo "7.2" > .php-version + run phpenv-local + assert_success "7.2" } @test "discovers version file in parent directory" { - echo "1.2.3" > .ruby-version + echo "1.2.3" > .php-version mkdir -p "subdir" && cd "subdir" - run rbenv-local + run phpenv-local assert_success "1.2.3" } -@test "ignores RBENV_DIR" { - echo "1.2.3" > .ruby-version +@test "ignores PHPENV_DIR" { + echo "1.2.3" > .php-version mkdir -p "$HOME" - echo "2.0-home" > "${HOME}/.ruby-version" - RBENV_DIR="$HOME" run rbenv-local + echo "7.2-home" > "${HOME}/.php-version" + PHPENV_DIR="$HOME" run phpenv-local assert_success "1.2.3" } @test "sets local version" { - mkdir -p "${RBENV_ROOT}/versions/1.2.3" - run rbenv-local 1.2.3 + mkdir -p "${PHPENV_ROOT}/versions/1.2.3" + run phpenv-local 1.2.3 assert_success "" - assert [ "$(cat .ruby-version)" = "1.2.3" ] + assert [ "$(cat .php-version)" = "1.2.3" ] } @test "changes local version" { - echo "1.0-pre" > .ruby-version - mkdir -p "${RBENV_ROOT}/versions/1.2.3" - run rbenv-local - assert_success "1.0-pre" - run rbenv-local 1.2.3 + echo "5.6-pre" > .php-version + mkdir -p "${PHPENV_ROOT}/versions/1.2.3" + run phpenv-local + assert_success "5.6-pre" + run phpenv-local 1.2.3 assert_success "" - assert [ "$(cat .ruby-version)" = "1.2.3" ] + assert [ "$(cat .php-version)" = "1.2.3" ] } -@test "renames .rbenv-version to .ruby-version" { - echo "1.8.7" > .rbenv-version - mkdir -p "${RBENV_ROOT}/versions/1.9.3" - run rbenv-local - assert_success "1.8.7" - run rbenv-local "1.9.3" +@test "renames .phpenv-version to .php-version" { + echo "7.0.32" > .phpenv-version + mkdir -p "${PHPENV_ROOT}/versions/7.1.23" + run phpenv-local + assert_success "7.0.32" + run phpenv-local "7.1.23" assert_success assert_output < .rbenv-version - assert [ ! -e "${RBENV_ROOT}/versions/1.9.3" ] - run rbenv-local "1.9.3" - assert_failure "rbenv: version \`1.9.3' not installed" - assert [ ! -e .ruby-version ] - assert [ "$(cat .rbenv-version)" = "1.8.7" ] +@test "doesn't rename .phpenv-version if changing the version failed" { + echo "7.0.32" > .phpenv-version + assert [ ! -e "${PHPENV_ROOT}/versions/7.1.23" ] + run phpenv-local "7.1.23" + assert_failure "phpenv: version \`7.1.23' not installed" + assert [ ! -e .php-version ] + assert [ "$(cat .phpenv-version)" = "7.0.32" ] } @test "unsets local version" { - touch .ruby-version - run rbenv-local --unset + touch .php-version + run phpenv-local --unset assert_success "" - assert [ ! -e .rbenv-version ] + assert [ ! -e .phpenv-version ] } @test "unsets alternate version file" { - touch .rbenv-version - run rbenv-local --unset + touch .phpenv-version + run phpenv-local --unset assert_success "" - assert [ ! -e .rbenv-version ] + assert [ ! -e .phpenv-version ] } diff --git a/test/phpenv.bats b/test/phpenv.bats index 6ded889..03f2af6 100644 --- a/test/phpenv.bats +++ b/test/phpenv.bats @@ -3,73 +3,71 @@ load test_helper @test "blank invocation" { - run rbenv + run phpenv assert_failure - assert_line 0 "$(rbenv---version)" + assert_line 0 "$(phpenv---version)" } @test "invalid command" { - run rbenv does-not-exist + run phpenv does-not-exist assert_failure - assert_output "rbenv: no such command \`does-not-exist'" + assert_output "phpenv: no such command \`does-not-exist'" } -@test "default RBENV_ROOT" { - RBENV_ROOT="" HOME=/home/mislav run rbenv root +@test "default PHPENV_ROOT" { + PHPENV_ROOT="" HOME=/home/sptndc run phpenv root assert_success - assert_output "/home/mislav/.rbenv" + assert_output "/home/sptndc/.phpenv" } -@test "inherited RBENV_ROOT" { - RBENV_ROOT=/opt/rbenv run rbenv root +@test "inherited PHPENV_ROOT" { + PHPENV_ROOT=/opt/phpenv run phpenv root assert_success - assert_output "/opt/rbenv" + assert_output "/opt/phpenv" } -@test "default RBENV_DIR" { - run rbenv echo RBENV_DIR +@test "default PHPENV_DIR" { + run phpenv echo PHPENV_DIR assert_output "$(pwd)" } -@test "inherited RBENV_DIR" { +@test "inherited PHPENV_DIR" { dir="${BATS_TMPDIR}/myproject" mkdir -p "$dir" - RBENV_DIR="$dir" run rbenv echo RBENV_DIR + PHPENV_DIR="$dir" run phpenv echo PHPENV_DIR assert_output "$dir" } -@test "invalid RBENV_DIR" { +@test "invalid PHPENV_DIR" { dir="${BATS_TMPDIR}/does-not-exist" assert [ ! -d "$dir" ] - RBENV_DIR="$dir" run rbenv echo RBENV_DIR + PHPENV_DIR="$dir" run phpenv echo PHPENV_DIR assert_failure - assert_output "rbenv: cannot change working directory to \`$dir'" + assert_output "phpenv: cannot change working directory to \`$dir'" } @test "adds its own libexec to PATH" { - run rbenv echo "PATH" + run phpenv echo "PATH" assert_success "${BATS_TEST_DIRNAME%/*}/libexec:$PATH" } @test "adds plugin bin dirs to PATH" { - mkdir -p "$RBENV_ROOT"/plugins/ruby-build/bin - mkdir -p "$RBENV_ROOT"/plugins/rbenv-each/bin - run rbenv echo -F: "PATH" + mkdir -p "$PHPENV_ROOT"/plugins/php-build/bin + run phpenv echo -F: "PATH" assert_success assert_line 0 "${BATS_TEST_DIRNAME%/*}/libexec" - assert_line 1 "${RBENV_ROOT}/plugins/ruby-build/bin" - assert_line 2 "${RBENV_ROOT}/plugins/rbenv-each/bin" + assert_line 1 "${PHPENV_ROOT}/plugins/php-build/bin" } -@test "RBENV_HOOK_PATH preserves value from environment" { - RBENV_HOOK_PATH=/my/hook/path:/other/hooks run rbenv echo -F: "RBENV_HOOK_PATH" +@test "PHPENV_HOOK_PATH preserves value from environment" { + PHPENV_HOOK_PATH=/my/hook/path:/other/hooks run phpenv echo -F: "PHPENV_HOOK_PATH" assert_success assert_line 0 "/my/hook/path" assert_line 1 "/other/hooks" - assert_line 2 "${RBENV_ROOT}/rbenv.d" + assert_line 2 "${PHPENV_ROOT}/phpenv.d" } -@test "RBENV_HOOK_PATH includes rbenv built-in plugins" { - run rbenv echo "RBENV_HOOK_PATH" - assert_success "${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" +@test "PHPENV_HOOK_PATH includes phpenv built-in plugins" { + run phpenv echo "PHPENV_HOOK_PATH" + assert_success "${PHPENV_ROOT}/phpenv.d:${BATS_TEST_DIRNAME%/*}/phpenv.d:/usr/local/etc/phpenv.d:/etc/phpenv.d:/usr/lib/phpenv/hooks" } diff --git a/test/prefix.bats b/test/prefix.bats index 3fb9408..37c9039 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -3,28 +3,28 @@ load test_helper @test "prefix" { - mkdir -p "${RBENV_TEST_DIR}/myproject" - cd "${RBENV_TEST_DIR}/myproject" - echo "1.2.3" > .ruby-version - mkdir -p "${RBENV_ROOT}/versions/1.2.3" - run rbenv-prefix - assert_success "${RBENV_ROOT}/versions/1.2.3" + mkdir -p "${PHPENV_TEST_DIR}/myproject" + cd "${PHPENV_TEST_DIR}/myproject" + echo "1.2.3" > .php-version + mkdir -p "${PHPENV_ROOT}/versions/1.2.3" + run phpenv-prefix + assert_success "${PHPENV_ROOT}/versions/1.2.3" } @test "prefix for invalid version" { - RBENV_VERSION="1.2.3" run rbenv-prefix - assert_failure "rbenv: version \`1.2.3' not installed" + PHPENV_VERSION="1.2.3" run phpenv-prefix + assert_failure "phpenv: version \`1.2.3' not installed" } @test "prefix for system" { - mkdir -p "${RBENV_TEST_DIR}/bin" - touch "${RBENV_TEST_DIR}/bin/ruby" - chmod +x "${RBENV_TEST_DIR}/bin/ruby" - RBENV_VERSION="system" run rbenv-prefix - assert_success "$RBENV_TEST_DIR" + mkdir -p "${PHPENV_TEST_DIR}/bin" + touch "${PHPENV_TEST_DIR}/bin/php" + chmod +x "${PHPENV_TEST_DIR}/bin/php" + PHPENV_VERSION="system" run phpenv-prefix + assert_success "$PHPENV_TEST_DIR" } @test "prefix for invalid system" { - PATH="$(path_without ruby)" run rbenv-prefix system - assert_failure "rbenv: system version not found in PATH" + PATH="$(path_without php)" run phpenv-prefix system + assert_failure "phpenv: system version not found in PATH" } diff --git a/test/rehash.bats b/test/rehash.bats index 74f55a9..695d14b 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -3,109 +3,109 @@ load test_helper create_executable() { - local bin="${RBENV_ROOT}/versions/${1}/bin" + local bin="${PHPENV_ROOT}/versions/${1}/bin" mkdir -p "$bin" touch "${bin}/$2" chmod +x "${bin}/$2" } @test "empty rehash" { - assert [ ! -d "${RBENV_ROOT}/shims" ] - run rbenv-rehash + assert [ ! -d "${PHPENV_ROOT}/shims" ] + run phpenv-rehash assert_success "" - assert [ -d "${RBENV_ROOT}/shims" ] - rmdir "${RBENV_ROOT}/shims" + assert [ -d "${PHPENV_ROOT}/shims" ] + rmdir "${PHPENV_ROOT}/shims" } @test "non-writable shims directory" { - mkdir -p "${RBENV_ROOT}/shims" - chmod -w "${RBENV_ROOT}/shims" - run rbenv-rehash - assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable" + mkdir -p "${PHPENV_ROOT}/shims" + chmod -w "${PHPENV_ROOT}/shims" + run phpenv-rehash + assert_failure "phpenv: cannot rehash: ${PHPENV_ROOT}/shims isn't writable" } @test "rehash in progress" { - mkdir -p "${RBENV_ROOT}/shims" - touch "${RBENV_ROOT}/shims/.rbenv-shim" - run rbenv-rehash - assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims/.rbenv-shim exists" + mkdir -p "${PHPENV_ROOT}/shims" + touch "${PHPENV_ROOT}/shims/.phpenv-shim" + run phpenv-rehash + assert_failure "phpenv: cannot rehash: ${PHPENV_ROOT}/shims/.phpenv-shim exists" } @test "creates shims" { - create_executable "1.8" "ruby" - create_executable "1.8" "rake" - create_executable "2.0" "ruby" - create_executable "2.0" "rspec" + create_executable "7.0" "php" + create_executable "7.0" "php-cgi" + create_executable "7.2" "php" + create_executable "7.2" "phpdbg" - assert [ ! -e "${RBENV_ROOT}/shims/ruby" ] - assert [ ! -e "${RBENV_ROOT}/shims/rake" ] - assert [ ! -e "${RBENV_ROOT}/shims/rspec" ] + assert [ ! -e "${PHPENV_ROOT}/shims/php" ] + assert [ ! -e "${PHPENV_ROOT}/shims/php-cgi" ] + assert [ ! -e "${PHPENV_ROOT}/shims/phpdbg" ] - run rbenv-rehash + run phpenv-rehash assert_success "" - run ls "${RBENV_ROOT}/shims" + run ls "${PHPENV_ROOT}/shims" assert_success assert_output < "${hook_path}/rehash/hello.bash" </dev/null || true" - assert [ -x "${RBENV_ROOT}/shims/ruby" ] + assert [ -x "${PHPENV_ROOT}/shims/php" ] } @test "sh-rehash in fish" { - create_executable "2.0" "ruby" - RBENV_SHELL=fish run rbenv-sh-rehash + create_executable "7.2" "php" + PHPENV_SHELL=fish run phpenv-sh-rehash assert_success "" - assert [ -x "${RBENV_ROOT}/shims/ruby" ] + assert [ -x "${PHPENV_ROOT}/shims/php" ] } diff --git a/test/run b/test/run index 9d3b9e5..b4f3b33 100755 --- a/test/run +++ b/test/run @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -if [ -n "$RBENV_NATIVE_EXT" ]; then +if [ -n "$PHPENV_NATIVE_EXT" ]; then src/configure make -C src fi diff --git a/test/shell.bats b/test/shell.bats index 0f77674..18a4aff 100644 --- a/test/shell.bats +++ b/test/shell.bats @@ -3,50 +3,50 @@ load test_helper @test "no shell version" { - mkdir -p "${RBENV_TEST_DIR}/myproject" - cd "${RBENV_TEST_DIR}/myproject" - echo "1.2.3" > .ruby-version - RBENV_VERSION="" run rbenv-sh-shell - assert_failure "rbenv: no shell-specific version configured" + mkdir -p "${PHPENV_TEST_DIR}/myproject" + cd "${PHPENV_TEST_DIR}/myproject" + echo "1.2.3" > .php-version + PHPENV_VERSION="" run phpenv-sh-shell + assert_failure "phpenv: no shell-specific version configured" } @test "shell version" { - RBENV_SHELL=bash RBENV_VERSION="1.2.3" run rbenv-sh-shell - assert_success 'echo "$RBENV_VERSION"' + PHPENV_SHELL=bash PHPENV_VERSION="1.2.3" run phpenv-sh-shell + assert_success 'echo "$PHPENV_VERSION"' } @test "shell version (fish)" { - RBENV_SHELL=fish RBENV_VERSION="1.2.3" run rbenv-sh-shell - assert_success 'echo "$RBENV_VERSION"' + PHPENV_SHELL=fish PHPENV_VERSION="1.2.3" run phpenv-sh-shell + assert_success 'echo "$PHPENV_VERSION"' } @test "shell unset" { - RBENV_SHELL=bash run rbenv-sh-shell --unset - assert_success "unset RBENV_VERSION" + PHPENV_SHELL=bash run phpenv-sh-shell --unset + assert_success "unset PHPENV_VERSION" } @test "shell unset (fish)" { - RBENV_SHELL=fish run rbenv-sh-shell --unset - assert_success "set -e RBENV_VERSION" + PHPENV_SHELL=fish run phpenv-sh-shell --unset + assert_success "set -e PHPENV_VERSION" } @test "shell change invalid version" { - run rbenv-sh-shell 1.2.3 + run phpenv-sh-shell 1.2.3 assert_failure assert_output </dev/null || echo "$RBENV_TEST_DIR")" +if [ -z "$PHPENV_TEST_DIR" ]; then + PHPENV_TEST_DIR="${BATS_TMPDIR}/phpenv" + export PHPENV_TEST_DIR="$(mktemp -d "${PHPENV_TEST_DIR}.XXX" 2>/dev/null || echo "$PHPENV_TEST_DIR")" - if enable -f "${BATS_TEST_DIRNAME}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then - export RBENV_TEST_DIR="$(realpath "$RBENV_TEST_DIR")" + if enable -f "${BATS_TEST_DIRNAME}"/../libexec/phpenv-realpath.dylib realpath 2>/dev/null; then + export PHPENV_TEST_DIR="$(realpath "$PHPENV_TEST_DIR")" else - if [ -n "$RBENV_NATIVE_EXT" ]; then - echo "rbenv: failed to load \`realpath' builtin" >&2 + if [ -n "$PHPENV_NATIVE_EXT" ]; then + echo "phpenv: failed to load \`realpath' builtin" >&2 exit 1 fi fi - export RBENV_ROOT="${RBENV_TEST_DIR}/root" - export HOME="${RBENV_TEST_DIR}/home" + export PHPENV_ROOT="${PHPENV_TEST_DIR}/root" + export HOME="${PHPENV_TEST_DIR}/home" PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin - PATH="${RBENV_TEST_DIR}/bin:$PATH" + PATH="${PHPENV_TEST_DIR}/bin:$PATH" PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" - PATH="${RBENV_ROOT}/shims:$PATH" + PATH="${PHPENV_ROOT}/shims:$PATH" export PATH for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done @@ -30,14 +30,14 @@ if [ -z "$RBENV_TEST_DIR" ]; then fi teardown() { - rm -rf "$RBENV_TEST_DIR" + rm -rf "$PHPENV_TEST_DIR" } flunk() { { if [ "$#" -eq 0 ]; then cat - else echo "$@" fi - } | sed "s:${RBENV_TEST_DIR}:TEST_DIR:g" >&2 + } | sed "s:${PHPENV_TEST_DIR}:TEST_DIR:g" >&2 return 1 } @@ -108,15 +108,15 @@ assert() { } # Output a modified PATH that ensures that the given executable is not present, -# but in which system utils necessary for rbenv operation are still available. +# but in which system utils necessary for phpenv operation are still available. path_without() { local exe="$1" local path=":${PATH}:" local found alt util for found in $(which -a "$exe"); do found="${found%/*}" - if [ "$found" != "${RBENV_ROOT}/shims" ]; then - alt="${RBENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')" + if [ "$found" != "${PHPENV_ROOT}/shims" ]; then + alt="${PHPENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')" mkdir -p "$alt" for util in bash head cut readlink greadlink; do if [ -x "${found}/$util" ]; then diff --git a/test/version-file-read.bats b/test/version-file-read.bats index bf7bf91..04ba753 100644 --- a/test/version-file-read.bats +++ b/test/version-file-read.bats @@ -3,70 +3,70 @@ load test_helper setup() { - mkdir -p "${RBENV_TEST_DIR}/myproject" - cd "${RBENV_TEST_DIR}/myproject" + mkdir -p "${PHPENV_TEST_DIR}/myproject" + cd "${PHPENV_TEST_DIR}/myproject" } @test "fails without arguments" { - run rbenv-version-file-read + run phpenv-version-file-read assert_failure "" } @test "fails for invalid file" { - run rbenv-version-file-read "non-existent" + run phpenv-version-file-read "non-existent" assert_failure "" } @test "fails for blank file" { echo > my-version - run rbenv-version-file-read my-version + run phpenv-version-file-read my-version assert_failure "" } @test "reads simple version file" { - cat > my-version <<<"1.9.3" - run rbenv-version-file-read my-version - assert_success "1.9.3" + cat > my-version <<<"7.1.23" + run phpenv-version-file-read my-version + assert_success "7.1.23" } @test "ignores leading spaces" { - cat > my-version <<<" 1.9.3" - run rbenv-version-file-read my-version - assert_success "1.9.3" + cat > my-version <<<" 7.1.23" + run phpenv-version-file-read my-version + assert_success "7.1.23" } @test "reads only the first word from file" { - cat > my-version <<<"1.9.3-p194@tag 1.8.7 hi" - run rbenv-version-file-read my-version - assert_success "1.9.3-p194@tag" + cat > my-version <<<"7.1.23@tag 7.0.32 hi" + run phpenv-version-file-read my-version + assert_success "7.1.23@tag" } @test "loads only the first line in file" { cat > my-version < my-version < my-version - run rbenv-version-file-read my-version - assert_success "1.8.7" + echo -n "7.0.32" > my-version + run phpenv-version-file-read my-version + assert_success "7.0.32" } @test "ignores carriage returns" { - cat > my-version <<< $'1.9.3\r' - run rbenv-version-file-read my-version - assert_success "1.9.3" + cat > my-version <<< $'7.1.23\r' + run phpenv-version-file-read my-version + assert_success "7.1.23" } diff --git a/test/version-file-write.bats b/test/version-file-write.bats index 0393a97..ee1bdd8 100644 --- a/test/version-file-write.bats +++ b/test/version-file-write.bats @@ -3,28 +3,28 @@ load test_helper setup() { - mkdir -p "$RBENV_TEST_DIR" - cd "$RBENV_TEST_DIR" + mkdir -p "$PHPENV_TEST_DIR" + cd "$PHPENV_TEST_DIR" } @test "invocation without 2 arguments prints usage" { - run rbenv-version-file-write - assert_failure "Usage: rbenv version-file-write " - run rbenv-version-file-write "one" "" + run phpenv-version-file-write + assert_failure "Usage: phpenv version-file-write " + run phpenv-version-file-write "one" "" assert_failure } @test "setting nonexistent version fails" { - assert [ ! -e ".ruby-version" ] - run rbenv-version-file-write ".ruby-version" "1.8.7" - assert_failure "rbenv: version \`1.8.7' not installed" - assert [ ! -e ".ruby-version" ] + assert [ ! -e ".php-version" ] + run phpenv-version-file-write ".php-version" "7.0.32" + assert_failure "phpenv: version \`7.0.32' not installed" + assert [ ! -e ".php-version" ] } @test "writes value to arbitrary file" { - mkdir -p "${RBENV_ROOT}/versions/1.8.7" + mkdir -p "${PHPENV_ROOT}/versions/7.0.32" assert [ ! -e "my-version" ] - run rbenv-version-file-write "${PWD}/my-version" "1.8.7" + run phpenv-version-file-write "${PWD}/my-version" "7.0.32" assert_success "" - assert [ "$(cat my-version)" = "1.8.7" ] + assert [ "$(cat my-version)" = "7.0.32" ] } diff --git a/test/version-file.bats b/test/version-file.bats index ef7901f..290fb4a 100644 --- a/test/version-file.bats +++ b/test/version-file.bats @@ -3,8 +3,8 @@ load test_helper setup() { - mkdir -p "$RBENV_TEST_DIR" - cd "$RBENV_TEST_DIR" + mkdir -p "$PHPENV_TEST_DIR" + cd "$PHPENV_TEST_DIR" } create_file() { @@ -13,98 +13,98 @@ create_file() { } @test "prints global file if no version files exist" { - assert [ ! -e "${RBENV_ROOT}/version" ] - assert [ ! -e ".ruby-version" ] - run rbenv-version-file - assert_success "${RBENV_ROOT}/version" + assert [ ! -e "${PHPENV_ROOT}/version" ] + assert [ ! -e ".php-version" ] + run phpenv-version-file + assert_success "${PHPENV_ROOT}/version" } @test "detects 'global' file" { - create_file "${RBENV_ROOT}/global" - run rbenv-version-file - assert_success "${RBENV_ROOT}/global" + create_file "${PHPENV_ROOT}/global" + run phpenv-version-file + assert_success "${PHPENV_ROOT}/global" } @test "detects 'default' file" { - create_file "${RBENV_ROOT}/default" - run rbenv-version-file - assert_success "${RBENV_ROOT}/default" + create_file "${PHPENV_ROOT}/default" + run phpenv-version-file + assert_success "${PHPENV_ROOT}/default" } @test "'version' has precedence over 'global' and 'default'" { - create_file "${RBENV_ROOT}/version" - create_file "${RBENV_ROOT}/global" - create_file "${RBENV_ROOT}/default" - run rbenv-version-file - assert_success "${RBENV_ROOT}/version" + create_file "${PHPENV_ROOT}/version" + create_file "${PHPENV_ROOT}/global" + create_file "${PHPENV_ROOT}/default" + run phpenv-version-file + assert_success "${PHPENV_ROOT}/version" } @test "in current directory" { - create_file ".ruby-version" - run rbenv-version-file - assert_success "${RBENV_TEST_DIR}/.ruby-version" + create_file ".php-version" + run phpenv-version-file + assert_success "${PHPENV_TEST_DIR}/.php-version" } @test "legacy file in current directory" { - create_file ".rbenv-version" - run rbenv-version-file - assert_success "${RBENV_TEST_DIR}/.rbenv-version" + create_file ".phpenv-version" + run phpenv-version-file + assert_success "${PHPENV_TEST_DIR}/.phpenv-version" } -@test ".ruby-version has precedence over legacy file" { - create_file ".ruby-version" - create_file ".rbenv-version" - run rbenv-version-file - assert_success "${RBENV_TEST_DIR}/.ruby-version" +@test ".php-version has precedence over legacy file" { + create_file ".php-version" + create_file ".phpenv-version" + run phpenv-version-file + assert_success "${PHPENV_TEST_DIR}/.php-version" } @test "in parent directory" { - create_file ".ruby-version" + create_file ".php-version" mkdir -p project cd project - run rbenv-version-file - assert_success "${RBENV_TEST_DIR}/.ruby-version" + run phpenv-version-file + assert_success "${PHPENV_TEST_DIR}/.php-version" } @test "topmost file has precedence" { - create_file ".ruby-version" - create_file "project/.ruby-version" + create_file ".php-version" + create_file "project/.php-version" cd project - run rbenv-version-file - assert_success "${RBENV_TEST_DIR}/project/.ruby-version" + run phpenv-version-file + assert_success "${PHPENV_TEST_DIR}/project/.php-version" } @test "legacy file has precedence if higher" { - create_file ".ruby-version" - create_file "project/.rbenv-version" + create_file ".php-version" + create_file "project/.phpenv-version" cd project - run rbenv-version-file - assert_success "${RBENV_TEST_DIR}/project/.rbenv-version" + run phpenv-version-file + assert_success "${PHPENV_TEST_DIR}/project/.phpenv-version" } -@test "RBENV_DIR has precedence over PWD" { - create_file "widget/.ruby-version" - create_file "project/.ruby-version" +@test "PHPENV_DIR has precedence over PWD" { + create_file "widget/.php-version" + create_file "project/.php-version" cd project - RBENV_DIR="${RBENV_TEST_DIR}/widget" run rbenv-version-file - assert_success "${RBENV_TEST_DIR}/widget/.ruby-version" + PHPENV_DIR="${PHPENV_TEST_DIR}/widget" run phpenv-version-file + assert_success "${PHPENV_TEST_DIR}/widget/.php-version" } -@test "PWD is searched if RBENV_DIR yields no results" { +@test "PWD is searched if PHPENV_DIR yields no results" { mkdir -p "widget/blank" - create_file "project/.ruby-version" + create_file "project/.php-version" cd project - RBENV_DIR="${RBENV_TEST_DIR}/widget/blank" run rbenv-version-file - assert_success "${RBENV_TEST_DIR}/project/.ruby-version" + PHPENV_DIR="${PHPENV_TEST_DIR}/widget/blank" run phpenv-version-file + assert_success "${PHPENV_TEST_DIR}/project/.php-version" } @test "finds version file in target directory" { - create_file "project/.ruby-version" - run rbenv-version-file "${PWD}/project" - assert_success "${RBENV_TEST_DIR}/project/.ruby-version" + create_file "project/.php-version" + run phpenv-version-file "${PWD}/project" + assert_success "${PHPENV_TEST_DIR}/project/.php-version" } @test "fails when no version file in target directory" { - run rbenv-version-file "$PWD" + run phpenv-version-file "$PWD" assert_failure "" } diff --git a/test/version-name.bats b/test/version-name.bats index 82e1b2d..35d24e0 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -3,72 +3,72 @@ load test_helper create_version() { - mkdir -p "${RBENV_ROOT}/versions/$1" + mkdir -p "${PHPENV_ROOT}/versions/$1" } setup() { - mkdir -p "$RBENV_TEST_DIR" - cd "$RBENV_TEST_DIR" + mkdir -p "$PHPENV_TEST_DIR" + cd "$PHPENV_TEST_DIR" } @test "no version selected" { - assert [ ! -d "${RBENV_ROOT}/versions" ] - run rbenv-version-name + assert [ ! -d "${PHPENV_ROOT}/versions" ] + run phpenv-version-name assert_success "system" } @test "system version is not checked for existance" { - RBENV_VERSION=system run rbenv-version-name + PHPENV_VERSION=system run phpenv-version-name assert_success "system" } -@test "RBENV_VERSION can be overridden by hook" { - create_version "1.8.7" - create_version "1.9.3" +@test "PHPENV_VERSION can be overridden by hook" { + create_version "7.0.32" + create_version "7.1.23" - mkdir -p "${RBENV_ROOT}/rbenv.d/version-name" - cat > "${RBENV_ROOT}/rbenv.d/version-name/test.bash" < "${PHPENV_ROOT}/phpenv.d/version-name/test.bash" < ".ruby-version" <<<"1.8.7" - run rbenv-version-name - assert_success "1.8.7" + cat > ".php-version" <<<"7.0.32" + run phpenv-version-name + assert_success "7.0.32" - RBENV_VERSION=1.9.3 run rbenv-version-name - assert_success "1.9.3" + PHPENV_VERSION=7.1.23 run phpenv-version-name + assert_success "7.1.23" } @test "local file has precedence over global" { - create_version "1.8.7" - create_version "1.9.3" + create_version "7.0.32" + create_version "7.1.23" - cat > "${RBENV_ROOT}/version" <<<"1.8.7" - run rbenv-version-name - assert_success "1.8.7" + cat > "${PHPENV_ROOT}/version" <<<"7.0.32" + run phpenv-version-name + assert_success "7.0.32" - cat > ".ruby-version" <<<"1.9.3" - run rbenv-version-name - assert_success "1.9.3" + cat > ".php-version" <<<"7.1.23" + run phpenv-version-name + assert_success "7.1.23" } @test "missing version" { - RBENV_VERSION=1.2 run rbenv-version-name - assert_failure "rbenv: version \`1.2' is not installed (set by RBENV_VERSION environment variable)" + PHPENV_VERSION=1.2 run phpenv-version-name + assert_failure "phpenv: version \`1.2' is not installed (set by PHPENV_VERSION environment variable)" } @test "version with prefix in name" { - create_version "1.8.7" - cat > ".ruby-version" <<<"ruby-1.8.7" - run rbenv-version-name + create_version "7.0.32" + cat > ".php-version" <<<"php-7.0.32" + run phpenv-version-name assert_success - assert_output "1.8.7" + assert_output "7.0.32" } diff --git a/test/version-origin.bats b/test/version-origin.bats index 61e1dfe..62ad0fd 100644 --- a/test/version-origin.bats +++ b/test/version-origin.bats @@ -3,51 +3,51 @@ load test_helper setup() { - mkdir -p "$RBENV_TEST_DIR" - cd "$RBENV_TEST_DIR" + mkdir -p "$PHPENV_TEST_DIR" + cd "$PHPENV_TEST_DIR" } @test "reports global file even if it doesn't exist" { - assert [ ! -e "${RBENV_ROOT}/version" ] - run rbenv-version-origin - assert_success "${RBENV_ROOT}/version" + assert [ ! -e "${PHPENV_ROOT}/version" ] + run phpenv-version-origin + assert_success "${PHPENV_ROOT}/version" } @test "detects global file" { - mkdir -p "$RBENV_ROOT" - touch "${RBENV_ROOT}/version" - run rbenv-version-origin - assert_success "${RBENV_ROOT}/version" + mkdir -p "$PHPENV_ROOT" + touch "${PHPENV_ROOT}/version" + run phpenv-version-origin + assert_success "${PHPENV_ROOT}/version" } -@test "detects RBENV_VERSION" { - RBENV_VERSION=1 run rbenv-version-origin - assert_success "RBENV_VERSION environment variable" +@test "detects PHPENV_VERSION" { + PHPENV_VERSION=1 run phpenv-version-origin + assert_success "PHPENV_VERSION environment variable" } @test "detects local file" { - touch .ruby-version - run rbenv-version-origin - assert_success "${PWD}/.ruby-version" + touch .php-version + run phpenv-version-origin + assert_success "${PWD}/.php-version" } @test "detects alternate version file" { - touch .rbenv-version - run rbenv-version-origin - assert_success "${PWD}/.rbenv-version" + touch .phpenv-version + run phpenv-version-origin + assert_success "${PWD}/.phpenv-version" } @test "reports from hook" { - mkdir -p "${RBENV_ROOT}/rbenv.d/version-origin" - cat > "${RBENV_ROOT}/rbenv.d/version-origin/test.bash" < "${PHPENV_ROOT}/phpenv.d/version-origin/test.bash" < ".ruby-version" <<<"1.9.3" - run rbenv-version - assert_success "1.9.3 (set by ${PWD}/.ruby-version)" + create_version "7.1.23" + cat > ".php-version" <<<"7.1.23" + run phpenv-version + assert_success "7.1.23 (set by ${PWD}/.php-version)" } @test "set by global file" { - create_version "1.9.3" - cat > "${RBENV_ROOT}/version" <<<"1.9.3" - run rbenv-version - assert_success "1.9.3 (set by ${RBENV_ROOT}/version)" + create_version "7.1.23" + cat > "${PHPENV_ROOT}/version" <<<"7.1.23" + run phpenv-version + assert_success "7.1.23 (set by ${PHPENV_ROOT}/version)" } diff --git a/test/versions.bats b/test/versions.bats index 3273b37..0bada65 100644 --- a/test/versions.bats +++ b/test/versions.bats @@ -3,154 +3,154 @@ load test_helper create_version() { - mkdir -p "${RBENV_ROOT}/versions/$1" + mkdir -p "${PHPENV_ROOT}/versions/$1" } setup() { - mkdir -p "$RBENV_TEST_DIR" - cd "$RBENV_TEST_DIR" + mkdir -p "$PHPENV_TEST_DIR" + cd "$PHPENV_TEST_DIR" } -stub_system_ruby() { - local stub="${RBENV_TEST_DIR}/bin/ruby" +stub_system_php() { + local stub="${PHPENV_TEST_DIR}/bin/php" mkdir -p "$(dirname "$stub")" touch "$stub" && chmod +x "$stub" } @test "no versions installed" { - stub_system_ruby - assert [ ! -d "${RBENV_ROOT}/versions" ] - run rbenv-versions - assert_success "* system (set by ${RBENV_ROOT}/version)" + stub_system_php + assert [ ! -d "${PHPENV_ROOT}/versions" ] + run phpenv-versions + assert_success "* system (set by ${PHPENV_ROOT}/version)" } -@test "not even system ruby available" { - PATH="$(path_without ruby)" run rbenv-versions +@test "not even system php available" { + PATH="$(path_without php)" run phpenv-versions assert_failure - assert_output "Warning: no Ruby detected on the system" + assert_output "Warning: no PHP detected on the system" } @test "bare output no versions installed" { - assert [ ! -d "${RBENV_ROOT}/versions" ] - run rbenv-versions --bare + assert [ ! -d "${PHPENV_ROOT}/versions" ] + run phpenv-versions --bare assert_success "" } @test "single version installed" { - stub_system_ruby - create_version "1.9" - run rbenv-versions + stub_system_php + create_version "7.1" + run phpenv-versions assert_success assert_output < "${RBENV_ROOT}/version" <<<"1.9.3" - run rbenv-versions + stub_system_php + create_version "7.1.23" + create_version "7.2.0" + cat > "${PHPENV_ROOT}/version" <<<"7.1.23" + run phpenv-versions assert_success assert_output < ".ruby-version" <<<"1.9.3" - run rbenv-versions + stub_system_php + create_version "7.1.23" + create_version "7.2.0" + cat > ".php-version" <<<"7.1.23" + run phpenv-versions assert_success assert_output < "${hook_path}/which/hello.bash" < "${RBENV_ROOT}/version" <<<"1.8" - create_executable "1.8" "ruby" +@test "discovers version from phpenv-version-name" { + mkdir -p "$PHPENV_ROOT" + cat > "${PHPENV_ROOT}/version" <<<"7.0" + create_executable "7.0" "php" - mkdir -p "$RBENV_TEST_DIR" - cd "$RBENV_TEST_DIR" + mkdir -p "$PHPENV_TEST_DIR" + cd "$PHPENV_TEST_DIR" - RBENV_VERSION= run rbenv-which ruby - assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby" + PHPENV_VERSION= run phpenv-which php + assert_success "${PHPENV_ROOT}/versions/7.0/bin/php" }