# Travis CI build configuration for MediaWiki
# <https://travis-ci.org/wikimedia/mediawiki-core>
#
# The Wikimedia Foundation uses a self-hosted Jenkins instance to run unit
# tests, but it tests code against the version of PHP that is deployed on
# Wikimedia's production cluster. This Travis CI configuration is designed to
# complement that setup by testing MediaWiki on travis
#
language: php
# Use the slower sudo-enabled VMs instead of fast containers:
# - Package 'djvulibre-bin' is not yet whitelisted for trusty containers.
#   https://github.com/travis-ci/apt-package-whitelist/issues/4036
sudo: required
# Use Trusty instead of Travis default (precise)
# - Required in order to use HHVM 3.6 or higher.
# - Required for non-buggy xml library for XmlTypeCheck/UploadBaseTest (T75176).
dist: trusty

matrix:
  fast_finish: true
  include:
    # On Trusty, mysql user 'travis' doesn't have create database rights
    # Postgres has no user called 'root'.
    - env: dbtype=mysql dbuser=root
      php: 5.5
    - env: dbtype=postgres dbuser=travis
      php: 5.5
    - env: dbtype=mysql dbuser=root
      # https://docs.travis-ci.com/user/languages/php#HHVM-versions
      # https://github.com/travis-ci/travis-ci/issues/7368
      php: hhvm-3.12
    - env: dbtype=mysql dbuser=root
      php: 7
  allow_failures:
    # Postgres support for unit tests is still buggy
    # https://phabricator.wikimedia.org/T75174
    - env: dbtype=postgres dbuser=travis
      php: 5.5

services:
  - mysql

branches:
  # Test changes in master and arbitrary Travis CI branches only.
  # The latter allows developers to enable Travis CI in their GitHub fork of
  # wikimedia/mediawiki and then push changes for testing to branches like
  # "travis-ci/test-this-awesome-change".
  only:
    - master
    - /^travis-ci\/.*$/

addons:
  apt:
    packages:
    - djvulibre-bin
    - tidy

before_script:
  - composer install --prefer-source --quiet --no-interaction
  - if [ "$dbtype" = postgres ]; then psql -c "CREATE DATABASE traviswiki WITH OWNER travis;" -U postgres; fi
  - >
      php maintenance/install.php traviswiki admin
      --pass travis
      --dbtype "$dbtype"
      --dbname traviswiki
      --dbuser "$dbuser"
      --dbpass ""
      --scriptpath "/w"

script:
  - php tests/phpunit/phpunit.php

notifications:
  email: false
  irc:
    channels:
      - "chat.freenode.net#mediawiki-feed"
    on_success: change
    on_failure: change
    skip_join: true
