language: php

matrix:
  include:
    - php: 7.2
      env: SNIFF=1
    # - php: 7.2
    #   env: WP_VERSION=latest
    - php: 7.1
      env: WP_VERSION=latest
    - php: 7.0
      env: WP_VERSION=latest
    - php: 5.6
      env: WP_VERSION=latest

notifications:
  email: false

cache:
  directories:
    - /tmp/phpcs
    - /tmp/sniffs

before_script:
  - if [[ ! -z "$WP_VERSION" ]]; then bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION; fi

install:
  - if [[ "$SNIFF" == "1" ]]; then export PHPCS_DIR=/tmp/phpcs; fi
  - if [[ "$SNIFF" == "1" ]]; then export SNIFFS_DIR=/tmp/sniffs; fi
  # Install PHP_CodeSniffer.
  - if [[ "$SNIFF" == "1" && ! $(ls -A $PHPCS_DIR) ]]; then git clone -b master --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git $PHPCS_DIR; fi
  # Install WordPress Coding Standards.
  - if [[ "$SNIFF" == "1" && ! $(ls -A $SNIFFS_DIR) ]]; then git clone -b master --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $SNIFFS_DIR; fi
  # Set install path for WordPress Coding Standards.
  - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs --config-set installed_paths $SNIFFS_DIR; fi
  # After CodeSniffer install you should refresh your path.
  - if [[ "$SNIFF" == "1" ]]; then phpenv rehash; fi

script:
  # Run against WordPress Coding Standards.
  # If you use a custom ruleset, change `--standard=WordPress` to point to your ruleset file,
  # for example: `--standard=wpcs.xml`.
  # You can use any of the normal PHPCS command line arguments in the command:
  # https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage
  - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs -p . --standard=phpcs.xml; fi
  # Run PHPUnit
  - if [[ ! -z "$WP_VERSION" ]]; then phpunit; fi
