145de3d4ec56d0434cd7dbe580b0aab631703ef6
[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 phpenv (TRAVIS=true), Ubuntu packages (PHP_VERSION=default) or Sury packages.
7 #       xdebug comes either at version 2 or 3
8
9 set -e
10
11 if [ "$TRAVIS" != true ]; then
12     PHPCONFDIR_CLI=$(php -i | grep 'Scan this dir for additional .ini files' | sed 's|Scan this dir for additional .ini files => ||')
13     PHPCONFDIR_FPM=$(echo "$PHPCONFDIR_CLI" | sed 's|/cli/|/fpm/|')
14 fi
15
16 enable_cc() {
17     if [ "$TRAVIS" = true ]; then
18         phpenv config-add tests/ci/config/codecoverage_xdebug.ini
19
20         pkill php-fpm
21         ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm
22     else
23         if [ -L "${PHPCONFDIR_CLI}/99-codecoverage_xdebug.ini" ]; then sudo rm "${PHPCONFDIR_CLI}/99-codecoverage_xdebug.ini"; fi
24         sudo ln -s $(realpath tests/ci/config/codecoverage_xdebug.ini) "${PHPCONFDIR_CLI}/99-codecoverage_xdebug.ini"
25         if [ -L "${PHPCONFDIR_FPM}/99-codecoverage_xdebug.ini" ]; then sudo rm "${PHPCONFDIR_FPM}/99-codecoverage_xdebug.ini"; fi
26         sudo ln -s $(realpath tests/ci/config/codecoverage_xdebug.ini) "${PHPCONFDIR_FPM}/99-codecoverage_xdebug.ini"
27
28         sudo service php-fpm restart
29     fi
30 }
31
32 disable_cc() {
33     if [ "$TRAVIS" = true ]; then
34         phpenv config-rm tests/ci/config/codecoverage_xdebug.ini
35
36         pkill php-fpm
37         ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm
38     else
39         if [ -L "${PHPCONFDIR_CLI}/99-codecoverage_xdebug.ini" ]; then sudo rm "${PHPCONFDIR_CLI}/99-codecoverage_xdebug.ini"; fi
40         if [ -L "${PHPCONFDIR_FPM}/99-codecoverage_xdebug.ini" ]; then sudo rm "${PHPCONFDIR_FPM}/99-codecoverage_xdebug.ini"; fi
41
42         sudo service php-fpm restart
43     fi
44 }
45
46 case "$1" in
47    enable | on)
48        enable_cc
49        ;;
50    disable | off)
51        disable_cc
52        ;;
53    *)
54        echo "ERROR: unknown action '${1}', please use 'enable' or 'disable'" >&2
55        exit 1
56        ;;
57 esac