MDL-55776 enrol: Add unit tests for enrolment manager.
[moodle.git] / .travis.yml
blobda666ee78816ea84502b3af29e22d58a49edb45a
1 # PLEASE NOTE: Travis is not currently utilised by the Moodle core integration
2 # process (which uses our internal CI system) this file is here for the benefit
3 # of community developers git clones - see MDL-51458.
5 sudo: false
7 # We currently disable Travis notifications entirely until https://github.com/travis-ci/travis-ci/issues/4976
8 # is fixed.
9 notifications:
10   email: false
12 language: php
14 php:
15     # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
16     - 7.0
17     - 5.6
19 env:
20     # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
21     # start first so that the total run time is not too high.
22     #
23     # We only run MySQL on PHP 7.0, so run that first.
24     # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
25     # Postgres is significantly is pretty reasonable in its run-time.
27     # Run unit tests on MySQL
28     - DB=mysqli   TASK=PHPUNIT
30     # Run CI Tests without running PHPUnit.
31     - DB=none     TASK=CITEST
33     # Run unit tests on Postgres
34     - DB=pgsql    TASK=PHPUNIT
36     # Perform an upgrade test too.
37     - DB=pgsql    TASK=UPGRADE
39 matrix:
40     # Enable fast finish.
41     # This will fail the build if a single job fails (except those in allow_failures).
42     # It will not stop the jobs from running.
43     fast_finish: true
45     include:
46           # Run grunt/npm install on lowest supported npm version
47         - php: 7
48           env: DB=none     TASK=GRUNT   NVM_VERSION='4'
49           # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
50         - php: 7
51           env: DB=none     TASK=GRUNT   NVM_VERSION='node'
53     exclude:
54         # MySQL - it's just too slow.
55         # Exclude it on all versions except for 7.0
57         - env: DB=mysqli   TASK=PHPUNIT
58           php: 5.6
60         # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
61         - env: DB=pgsql    TASK=UPGRADE
62           php: 7.0
64 cache:
65     directories:
66       - $HOME/.composer/cache
67       - $HOME/.npm
69 install:
70     # Disable xdebug. We aren't generating code coverage, and it has a huge impact upon test performance.
71     - rm /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
73     - >
74         if [ "$TASK" = 'PHPUNIT' ];
75         then
76             if [ -n "$GITHUB_APITOKEN" ]; then
77                 composer config github-oauth.github.com $GITHUB_APITOKEN;
78                 echo 'auth.json' >> .git/info/exclude
79             fi
81             # Install composer dependencies.
82             # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
83             # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
84             travis_retry composer install --prefer-dist --no-interaction;
85         fi
87     - >
88         if [ "$TASK" = 'GRUNT' ];
89         then
90             nvm install $NVM_VERSION ;
91             nvm use $NVM_VERSION ;
92         fi
94 before_script:
95     - >
96       if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
97       then
98         # Copy generic configuration in place.
99         cp config-dist.php config.php ;
101         # Create the moodledata directory.
102         mkdir -p "$HOME"/roots/base
104         # The database name and password.
105         sed -i \
106           -e "s%= 'moodle'%= 'travis_ci_test'%" \
107           -e "s%= 'password'%= ''%" \
108           config.php ;
110         # The wwwroot and dataroot.
111         sed -i \
112           -e "s%http://example.com/moodle%http://localhost%" \
113           -e "s%/home/example/moodledata%/home/travis/roots/base%" \
114           config.php ;
116         if [ "$DB" = 'pgsql' ];
117         then
118           # Postgres-specific setup.
119           sed -i \
120             -e "s%= 'username'%= 'postgres'%" \
121             config.php ;
123           psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
124         fi
126         if [ "$DB" = 'mysqli' ];
127         then
128           # MySQL-specific setup.
129           sed -i \
130             -e "s%= 'pgsql'%= 'mysqli'%" \
131             -e "s%= 'username'%= 'travis'%" \
132             config.php;
134           mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
135           mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
136           mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
137         fi
138       fi
140     - >
141       if [ "$TASK" = 'PHPUNIT' ];
142       then
143         # Create a directory for the phpunit dataroot.
144         mkdir -p "$HOME"/roots/phpunit
146         # The phpunit dataroot and prefix..
147         sed -i \
148           -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
149           -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
150           config.php ;
152         # Initialise PHPUnit for Moodle.
153         php admin/tool/phpunit/cli/init.php
154       fi
156     - >
157       if [ "$TASK" = 'GRUNT' ];
158       then
159         npm install --no-spin;
160         npm install --no-spin -g grunt ;
161       fi
163     ########################################################################
164     # CI Tests
165     ########################################################################
166     - >
167       if [ "$TASK" = 'CITEST' ];
168       then
169         # Note - this is deliberately placed in the script section as we
170         # should not add any code until after phpunit has run.
172         # The following repositories are required.
173         # The local_ci repository does the actual checking.
174         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
176         # We need the official upstream for comparison
177         git remote add upstream https://github.com/moodle/moodle.git;
179         git fetch upstream master;
180         export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
181         export GIT_COMMIT="$TRAVIS_COMMIT";
182         export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
184         # Variables required by our linter.
185         export gitcmd=`which git`;
186         export gitdir="$TRAVIS_BUILD_DIR";
187         export phpcmd=`which php`;
188       fi
190     ########################################################################
191     # Upgrade test
192     ########################################################################
193     - >
194       if [ "$TASK" = 'UPGRADE' ];
195       then
196         # We need the official upstream.
197         git remote add upstream https://github.com/moodle/moodle.git;
199         # Checkout 27 STABLE branch.
200         git fetch upstream MOODLE_27_STABLE;
201         git checkout MOODLE_27_STABLE;
203         # Perform the upgrade
204         php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
206         # Return to the previous commit
207         git checkout -;
209         # Perform the upgrade
210         php admin/cli/upgrade.php --non-interactive --allow-unstable ;
212         # The local_ci repository can be used to check upgrade savepoints.
213         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
214       fi
216 script:
217     - >
218       if [ "$TASK" = 'PHPUNIT' ];
219       then
220         vendor/bin/phpunit;
221       fi
223     - >
224       if [ "$TASK" = 'CITEST' ];
225       then
226         bash local/ci/php_lint/php_lint.sh;
227       fi
229     - >
230       if [ "$TASK" = 'GRUNT' ];
231       then
232         grunt ;
233         # Add all files to the git index and then run diff --cached to see all changes.
234         # This ensures that we get the status of all files, including new files.
235         git add . ;
236         git diff --cached --exit-code ;
237       fi
239     ########################################################################
240     # Upgrade test
241     ########################################################################
242     - >
243       if [ "$TASK" = 'UPGRADE' ];
244       then
245         cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
246         result=`php check_upgrade_savepoints.php`;
247         # Check if there are problems
248         count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;
249         if (($count > 0));
250         then
251           echo "$result"
252           exit 1 ;
253         fi
254       fi