language:
    - php
    - node_js

php:
    - 5.3
    - 5.4

node_js:
    - 0.10

env:
    - WP_VERSION=latest WP_MULTISITE=0
    - WP_VERSION=latest WP_MULTISITE=1
    - WP_VERSION=4.0 WP_MULTISITE=0
    - WP_VERSION=4.0 WP_MULTISITE=1

before_script:
    - export WP_TESTS_DIR=/tmp/wordpress-tests/
    - export PLUGIN_DIR=$(pwd)
    - export PLUGIN_SLUG=$(basename $(pwd) | sed 's/^wp-//')
    - export PHPCS_DIR=/tmp/phpcs
    - export PHPCS_GITHUB_SRC=squizlabs/PHP_CodeSniffer
    - export PHPCS_GIT_TREE=master
    - export PHPCS_IGNORE='tests/*,vendor/*'
    - export WPCS_DIR=/tmp/wpcs
    - export WPCS_GITHUB_SRC=WordPress-Coding-Standards/WordPress-Coding-Standards
    - export WPCS_GIT_TREE=master
    - export WPCS_STANDARD=$(if [ -e phpcs.ruleset.xml ]; then echo phpcs.ruleset.xml; else echo WordPress-Core; fi)
    - if [ -e .ci-env.sh ]; then source .ci-env.sh; fi
    - if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then wget -O /tmp/install-wp-tests.sh https://raw.githubusercontent.com/wp-cli/wp-cli/master/templates/install-wp-tests.sh; bash /tmp/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION; cd /tmp/wordpress/wp-content/plugins; ln -s $PLUGIN_DIR $PLUGIN_SLUG; cd $PLUGIN_DIR; fi
    - mkdir -p $PHPCS_DIR && curl -L https://github.com/$PHPCS_GITHUB_SRC/archive/$PHPCS_GIT_TREE.tar.gz | tar xvz --strip-components=1 -C $PHPCS_DIR
    - mkdir -p $WPCS_DIR && curl -L https://github.com/$WPCS_GITHUB_SRC/archive/$WPCS_GIT_TREE.tar.gz | tar xvz --strip-components=1 -C $WPCS_DIR
    - $PHPCS_DIR/scripts/phpcs --config-set installed_paths $WPCS_DIR
    - npm install -g jshint
    - if [ -e composer.json ]; then wget http://getcomposer.org/composer.phar && php composer.phar install --dev; fi

script:
    - find . -path ./bin -prune -o \( -name '*.php' -o -name '*.inc' \) -exec php -lf {} \;
    - if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then phpunit $( if [ -e .coveralls.yml ]; then echo --coverage-clover build/logs/clover.xml; fi ); fi
    - $PHPCS_DIR/scripts/phpcs --standard=$WPCS_STANDARD $(if [ -n "$PHPCS_IGNORE" ]; then echo --ignore=$PHPCS_IGNORE; fi) $(find . -name '*.php')
    - jshint .

after_script:
    - if [ -e .coveralls.yml ]; then php vendor/bin/coveralls; fi
