tag for next version; try to fix generation of code coverage
[plcapi.git] / tests / ci / setup / setup_code_coverage.sh
1 #!/bin/sh
2
3 # @todo add 'query' action
4 # @todo avoid reloading php-fpm if config did not change
5
6 # Note: we have php set up either via Ubuntu packages (PHP_VERSION=default) or Sury packages.
7 #       xdebug comes either at version 2 or 3
8
9 set -e
10
11 PHPCONFDIR_CLI=$(php -i | grep 'Scan this dir for additional .ini files' | sed 's|Scan this dir for additional .ini files => ||')
12 PHPCONFDIR_FPM=$(echo "$PHPCONFDIR_CLI" | sed 's|/cli/|/fpm/|')
13
14 enable_cc() {
15     if [ -L "${PHPCONFDIR_CLI}/99-codecoverage_xdebug.ini" ]; then sudo rm "${PHPCONFDIR_CLI}/99-codecoverage_xdebug.ini"; fi
16     sudo ln -s $(realpath tests/ci/config/codecoverage_xdebug.ini) "${PHPCONFDIR_CLI}/99-codecoverage_xdebug.ini"
17     if [ -L "${PHPCONFDIR_FPM}/99-codecoverage_xdebug.ini" ]; then sudo rm "${PHPCONFDIR_FPM}/99-codecoverage_xdebug.ini"; fi
18     sudo ln -s $(realpath tests/ci/config/codecoverage_xdebug.ini) "${PHPCONFDIR_FPM}/99-codecoverage_xdebug.ini"
19
20     sudo service php-fpm restart
21 }
22
23 disable_cc() {
24     if [ -L "${PHPCONFDIR_CLI}/99-codecoverage_xdebug.ini" ]; then sudo rm "${PHPCONFDIR_CLI}/99-codecoverage_xdebug.ini"; fi
25     if [ -L "${PHPCONFDIR_FPM}/99-codecoverage_xdebug.ini" ]; then sudo rm "${PHPCONFDIR_FPM}/99-codecoverage_xdebug.ini"; fi
26
27     sudo service php-fpm restart
28 }
29
30 case "$1" in
31    enable | on)
32        enable_cc
33        ;;
34    disable | off)
35        disable_cc
36        ;;
37    *)
38        echo "ERROR: unknown action '${1}', please use 'enable' or 'disable'" >&2
39        exit 1
40        ;;
41 esac