xref: /unit/test/unit/applications/lang/php.py (revision 2000:c42fcbf93789)
1import os
2import shutil
3
4from unit.applications.proto import TestApplicationProto
5from unit.option import option
6
7
8class TestApplicationPHP(TestApplicationProto):
9    application_type = "php"
10
11    def load(self, script, index='index.php', **kwargs):
12        script_path = option.test_dir + '/php/' + script
13
14        if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'):
15            rootfs = kwargs['isolation']['rootfs']
16
17            if not os.path.exists(rootfs + '/app/php/'):
18                os.makedirs(rootfs + '/app/php/')
19
20            if not os.path.exists(rootfs + '/app/php/' + script):
21                shutil.copytree(script_path, rootfs + '/app/php/' + script)
22
23            script_path = '/app/php/' + script
24
25        app = {
26            "type": self.get_application_type(),
27            "processes": kwargs.pop('processes', {"spare": 0}),
28            "root": script_path,
29            "working_directory": script_path,
30            "index": index,
31        }
32
33        for attr in (
34            'environment',
35            'limits',
36            'options',
37            'targets',
38        ):
39            if attr in kwargs:
40                app[attr] = kwargs.pop(attr)
41
42        self._load_conf(
43            {
44                "listeners": {"*:7080": {"pass": "applications/" + script}},
45                "applications": {script: app},
46            },
47            **kwargs
48        )
49