1import ../make-test-python.nix ({pkgs, ...}:
2let
3 testdir = pkgs.writeTextDir "www/info.php" "<?php phpinfo();";
4
5in {
6 name = "unit-php-test";
7 meta.maintainers = with pkgs.lib.maintainers; [ izorkin ];
8
9 nodes.machine = { config, lib, pkgs, ... }: {
10 services.unit = {
11 enable = true;
12 config = pkgs.lib.strings.toJSON {
13 listeners."*:9081".application = "php_81";
14 applications.php_81 = {
15 type = "php 8.1";
16 processes = 1;
17 user = "testuser";
18 group = "testgroup";
19 root = "${testdir}/www";
20 index = "info.php";
21 options.file = "${pkgs.unit.usedPhp81}/lib/php.ini";
22 };
23 };
24 };
25 users = {
26 users.testuser = {
27 isSystemUser = true;
28 uid = 1080;
29 group = "testgroup";
30 };
31 groups.testgroup = {
32 gid = 1080;
33 };
34 };
35 };
36 testScript = ''
37 machine.start()
38
39 machine.wait_for_unit("unit.service")
40 machine.wait_for_open_port(9081)
41
42 # Check so we get an evaluated PHP back
43 response = machine.succeed("curl -f -vvv -s http://127.0.0.1:9081/")
44 assert "PHP Version ${pkgs.unit.usedPhp81.version}" in response, "PHP version not detected"
45
46 # Check so we have database and some other extensions loaded
47 for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite"]:
48 assert ext in response, f"Missing {ext} extension"
49
50 machine.shutdown()
51 '';
52})