phpunit app

This commit is contained in:
Robin Appelman 2025-10-25 23:37:06 +02:00
commit d143b04ec3
4 changed files with 84 additions and 2 deletions

12
apps/phpunit.nix Normal file
View file

@ -0,0 +1,12 @@
{
phpunit,
testDependencies,
writeShellApplication,
}:
writeShellApplication {
name = "phpunit";
runtimeInputs = [phpunit] ++ testDependencies;
text = ''
phpunit "$@"
'';
}

View file

@ -2,7 +2,7 @@
lib,
allVersions,
}: let
inherit (lib) splitString split trim map substring stringToCharacters foldr elemAt filter isString;
inherit (lib) splitString split trim map substring stringToCharacters foldr elemAt filter isString splitVersion head;
inherit (lib.lists) findFirstIndex;
inherit (lib.strings) charToInt compareVersions;
in
@ -49,4 +49,5 @@ in
then composerJson.version
else "0.0.0";
phpVersions = filter matches allVersions;
phpUnitVersion = head (splitVersion composerJson.require-dev."phpunit/phpunit");
}

View file

@ -111,6 +111,11 @@ in
vendorHash = mkOption {
type = with types; str;
};
testDependencies = mkOption {
type = function;
default = pkgs: [];
description = "extra dependencies needed during testing";
};
};
config = mkMerge [
@ -123,6 +128,14 @@ in
inherit (config) composerJson composerLock vendorHash;
};
phpunit = final.callPackage ./apps/phpunit.nix {
phpunit = final.callPackage ./pkgs/phpunit.nix {
php = final.minPhp;
majorVersion = composerMeta.phpUnitVersion;
};
testDependencies = config.testDependencies final;
};
inherit composerMeta filteredSrc;
inherit (final.minPhp.packages) php-cs-fixer composer psalm phpstan;
})
@ -156,12 +169,16 @@ in
in
(optionalAttrs hasPsalm (forPhpVersions "psalm" ./checks/psalm.nix))
// (optionalAttrs hasPhpStan (forPhpVersions "phpstan" ./checks/phpstan.nix));
apps = {pkgs, ...}: {
phpunit = ''${getExe pkgs.phpunit} "$@"'';
};
})
{
devShells = {
default = {
packages = pkgs: (config.tools pkgs) ++ (with pkgs; [minPhp php-cs-fixer composer psalm phpstan]);
packages = pkgs: (config.tools pkgs) ++ (with pkgs; [minPhp php-cs-fixer composer psalm phpstan phpunit]);
};
};

52
pkgs/phpunit.nix Normal file
View file

@ -0,0 +1,52 @@
{
lib,
fetchFromGitHub,
php,
majorVersion,
}: let
versions = {
"9" = {
version = "9.6.25";
hash = "sha256-DKbInG8zsIa2DFNY5eqW8CKWUhGM0yc3/wppUiizYbg=";
vendorHash = "sha256-pvP2ULwnDbPb9bIaNKkQ7cvyMpgZiFfoJfUFRGzojBQ=";
};
"10" = {
version = "10.5.46";
hash = "sha256-DtQ6CR4RAGKpZcJA9WZ5ud5ztIBTr8MeVTIhFwbGHYc=";
vendorHash = "sha256-fNv9pWFwYTyw3KEGtmbKNzXFsiDE6oZjRCWhypa/k0A=";
};
"11" = {
version = "11.5.22";
hash = "sha256-oXoh/2G0bqPPyvVoQUUdUz8XGyNtRJE3taUFGu2UIsc=";
vendorHash = "sha256-9gLTJe2ft90qGr/d8/Zc/ua7EWyNZ16wPEZRe9sKZf0=";
};
"12" = {
version = "12.2.1";
hash = "sha256-D5WI1kv05L8X3Gfw/MCxGdIcqWyWJg68GL9I24z/zIY=";
vendorHash = "sha256-H+XMRMvbUz/WCUdPRmL8nSCqa5YE3Qb1+goEQjjDK70=";
};
};
in
php.buildComposerProject2 (finalAttrs: {
pname = "phpunit";
inherit (versions.${majorVersion}) version vendorHash;
src = fetchFromGitHub {
owner = "sebastianbergmann";
repo = "phpunit";
tag = finalAttrs.version;
inherit (versions.${majorVersion}) hash;
};
doInstallCheck = false;
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";
maintainers = with lib.maintainers; [onny];
teams = [lib.teams.php];
};
})