1import ../make-test-python.nix ({pkgs, ...}:
2 let
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 machine = { config, lib, pkgs, ... }: {
10 services.unit = {
11 enable = true;
12 config = ''
13 {
14 "listeners": {
15 "*:9074": {
16 "application": "php_74"
17 }
18 },
19 "applications": {
20 "php_74": {
21 "type": "php 7.4",
22 "processes": 1,
23 "user": "testuser",
24 "group": "testgroup",
25 "root": "${testdir}/www",
26 "index": "info.php",
27 "options": {
28 "file": "${pkgs.unit.usedPhp74}/lib/php.ini"
29 }
30 }
31 }
32 }
33 '';
34 };
35 users = {
36 users.testuser = {
37 isSystemUser = true;
38 uid = 1074;
39 group = "testgroup";
40 };
41 groups.testgroup = {
42 gid= 1074;
43 };
44 };
45 };
46 testScript = ''
47 machine.wait_for_unit("unit.service")
48
49 # Check so we get an evaluated PHP back
50 response = machine.succeed("curl -f -vvv -s http://127.0.0.1:9074/")
51 assert "PHP Version ${pkgs.unit.usedPhp74.version}" in response, "PHP version not detected"
52
53 # Check so we have database and some other extensions loaded
54 for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite"]:
55 assert ext in response, f"Missing {ext} extension"
56 '';
57})