diff --git a/README.md b/README.md index aa538d2..715a83b 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Additionally, you can use the following options when starting an instance: #### Run tests in a new instance ```bash -haze test [database] [php-version] [path] +haze test [database] [php-version] [phpunit version] [path] ``` Where `path` is a file or folder to run PHPUnit in, relative to the sources diff --git a/nix/image/haze.nix b/nix/image/haze.nix index ca3f77a..82924ff 100644 --- a/nix/image/haze.nix +++ b/nix/image/haze.nix @@ -85,28 +85,28 @@ name = "phpunit"; runtimeInputs = [jq]; text = '' - MAJOR=$(jq -r 'first(.require."phpunit/phpunit" | scan("[[:digit:]]+"))' vendor-bin/phpunit/composer.json) + MAJOR=$(jq -r 'first(.require."phpunit/phpunit" | scan("[[:digit:]]+"))' vendor-bin/phpunit/composer.json || echo "") case "$MAJOR" in 9) - PKG=${phpunitUnwrapped "9"} + BIN="${getExe (phpunitUnwrapped "9")}" ;; 10) - PKG=${phpunitUnwrapped "10"} + BIN="${getExe (phpunitUnwrapped "10")}" ;; 11) - PKG=${phpunitUnwrapped "11"} + BIN="${getExe (phpunitUnwrapped "11")}" ;; 12) - PKG=${phpunitUnwrapped "12"} + BIN="${getExe (phpunitUnwrapped "12")}" ;; 13) - PKG=${phpunitUnwrapped "13"} + BIN="${getExe (phpunitUnwrapped "13")}" ;; *) - PKG=${phpunitUnwrapped "10"} + BIN="${getExe (phpunitUnwrapped "10")}" ;; esac - "$PKG"/bin/phpunit "$@" + "$BIN" "$@" ''; }; @@ -160,6 +160,7 @@ phpEnv.packages.composer phpunit ] + ++ (map phpunitUnwrapped ["9" "10" "11" "12" "13"]) ++ optionals ((compareVersions phpVersion "8.2") == 1) [ (frankenphp.override { php = php.withExtensions ( diff --git a/nix/image/phpunit.nix b/nix/image/phpunit.nix index 279e771..5af3582 100644 --- a/nix/image/phpunit.nix +++ b/nix/image/phpunit.nix @@ -45,12 +45,16 @@ in doInstallCheck = false; + postInstall = '' + mv $out/bin/phpunit $out/bin/phpunit${majorVersion} + ''; + meta = { changelog = "https://github.com/sebastianbergmann/phpunit/blob/${finalAttrs.version}/ChangeLog-${lib.versions.majorMinor finalAttrs.version}.md"; description = "PHP Unit Testing framework"; homepage = "https://phpunit.de"; license = lib.licenses.bsd3; - mainProgram = "phpunit"; + mainProgram = "phpunit${majorVersion}"; maintainers = with lib.maintainers; [onny]; teams = [lib.teams.php]; }; diff --git a/nix/image/scripts/tests b/nix/image/scripts/tests index 868f225..2bb7d59 100755 --- a/nix/image/scripts/tests +++ b/nix/image/scripts/tests @@ -3,5 +3,15 @@ def --wrapped main [...rest] { cd $env.WEBROOT - XDEBUG_SESSION=haze phpunit --configuration $"($env.WEBROOT)/tests/phpunit-autotest.xml" ...$rest + mut args = $rest; + mut command = "phpunit"; + if (($args | first | detect type | describe) == "int") { + let phpunit_version = $rest | first + $command = $"phpunit($phpunit_version)" + $args = $args | skip 1 + } + + let command = $command + let args = $args + XDEBUG_SESSION=haze exec $command --configuration $"($env.WEBROOT)/tests/phpunit-autotest.xml" ...$args } diff --git a/src/args.rs b/src/args.rs index 59bca87..777c6b2 100644 --- a/src/args.rs +++ b/src/args.rs @@ -426,7 +426,7 @@ pub enum HazeCommand { /// Run tests in a new instance #[strum(props( InstanceArgs = true, - Args = "[phpunit arguments] arguments to pass to phpunit" + Args = "[phpunit version] use a specific phpunit version instead of the automatically detected one [phpunit arguments] arguments to pass to phpunit" ))] Test, /// Run a command in an instance