---
services: docker

env:
  # Test package install on all supported OSes.
  - distro: centos7
    playbook: test.yml
    php_version: 7.0
  - distro: fedora24
    playbook: test.yml
    php_version: 5.6
  - distro: debian8
    playbook: test.yml
    php_version: 7.0
  - distro: ubuntu1604
    playbook: test.yml
    php_version: 7.0
  - distro: ubuntu1404
    playbook: test.yml
    php_version: 7.0

  # Only test source install on latest supported OSes.
  - distro: centos7
    playbook: test-source.yml
    php_version: 7.1.9
  - distro: ubuntu1604
    playbook: test-source.yml
    php_version: 7.1.9

script:
  # Configure test script so we can run extra tests after playbook is run.
  - export container_id=$(date +%s)
  - export cleanup=false

  # Download test shim.
  - wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
  - chmod +x ${PWD}/tests/test.sh

  # Run tests.
  - ${PWD}/tests/test.sh

  # Ensure PHP is installed and at the right version.
  - 'docker exec --tty ${container_id} env TERM=xterm which php'
  - 'docker exec --tty ${container_id} env TERM=xterm test -x /usr/bin/php'

  - 'docker exec --tty ${container_id} env TERM=xterm php --version'
  - 'docker exec --tty ${container_id} env TERM=xterm /usr/bin/php --version | grep -qF "PHP ${php_version}"'

  # Ensure PHP configurations have taken effect.
  - docker exec --tty ${container_id} env TERM=xterm php -i | grep 'memory_limit.*192'

  # Check the status of PHP-FPM.
  - |
    if [ "${playbook}" == "test.yml" ]; then
      case "${distro}" in
        "centos7"|"fedora24")
          docker exec --tty ${container_id} env TERM=xterm systemctl --no-pager status php-fpm status
          docker exec --tty ${container_id} env TERM=xterm systemctl --no-pager status php-fpm status | grep -qF "fpm.service; enabled"
          ;;
        "debian8"|"ubuntu1604")
          docker exec --tty ${container_id} env TERM=xterm systemctl --no-pager status php${php_version}-fpm status
          docker exec --tty ${container_id} env TERM=xterm systemctl --no-pager status php${php_version}-fpm status | grep -qF "fpm.service; enabled"
          ;;
      esac
    fi

notifications:
  webhooks: https://galaxy.ansible.com/api/v1/notifications/
