nixpkgs/nixos/tests/php/httpd.nix
Martin Weinelt a9202f95da
nixos/test/php: migrate to nspawn, modernize
They boot up quicker now, which is why the curl needs a retry mechanism.

Also uses proper unittest asserts, which provide good feedback on error.
2026-06-22 23:05:13 +02:00

47 lines
1.1 KiB
Nix

{
lib,
php,
...
}:
{
name = "php-${php.version}-httpd-test";
meta.maintainers = lib.teams.php.members;
containers.machine =
{
config,
pkgs,
...
}:
{
services.httpd = {
enable = true;
adminAddr = "admin@phpfpm";
virtualHosts."phpfpm" =
let
testdir = pkgs.writeTextDir "web/index.php" "<?php phpinfo();";
in
{
documentRoot = "${testdir}/web";
locations."/" = {
index = "index.php index.html";
};
};
phpPackage = php;
enablePHP = true;
};
};
testScript =
# python
''
machine.wait_for_unit("httpd.service")
# Check so we get an evaluated PHP back
response = machine.wait_until_succeeds("curl -fvvv -s http://127.0.0.1:80/")
t.assertIn("PHP Version ${php.version}", response, "PHP version not detected")
# Check so we have database and some other extensions loaded
for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite"]:
assert ext in response, f"Missing {ext} extension"
'';
}