Skip to content

Install and Testing Environment

Kasper Dugaw edited this page Nov 17, 2020 · 2 revisions

Installing Moodle

The following documentation was followed during the install process: https://docs.moodle.org/39/en/Step-by-step_Installation_Guide_for_Ubuntu#Step_2:_Install_Apache.2FMySQL.2FPHP

Initializing the Moodle Testing Environment

This text describes the steps we took to configure the Moodle testing environment. The official documentation can be found at the link below.

Official Moodle Documentation: https://docs.moodle.org/dev/PHPUnit

Install PHPUnit via Composer

Download Composer

https://getcomposer.org/download/

Composer was installed using the followng commands in the moodle directory:

Note: must be root

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '795f976fe0ebd8b75f26a6dd68f78fd3453ce79f32ecb33e7fd087d39bfeb978342fb73ac986cd4f54edd0dc902601dc') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Execute Composer

php composer.phar install

Initializing the Test Environment

Create dedicated dataroot

mkdir ../phpu_moodledata
chown www-data phpu_moodledata
chmod 755 phpu_moodledata

Add dedicated dataroot in config.php

In section 9 edit the following lines:

$CFG->phpunit_prefix = 'phpu_';
$CFG->phpunit_dataroot = '/home/example/phpu_moodledata';

Initialize

php admin/tool/phpunit/cli/init.php

Running Tests

All Tests (10-20 mins)

From moodle dir run: vendor/bin/phpunit

Keys for all tests output:
. - Printed when the test succeeds.
F - Printed when an assertion fails while running the test method.
E - Printed when an error occurs while running the test method.
R - Printed when the test has been marked as risky.
S - Printed when the test has been skipped.
I - Printed when the test is marked as being incomplete or not yet implemented.
see more on test outputs

Some Tests

  • One Test vendor/bin/phpunit my/test/filename.php
  • Single Method vendor/bin/phpunit --filter test_function_name path/to/file.php
  • Grouped Tests vendor/bin/phpunit --filter test_flag_user

Note: Tests are flagged with the following file annotation

/**
 * Unit tests for {@link stack_cas_keyval}.
 * @group qtype_stack
 */
class qtype_stack_cas_keyval_exception_testcase extends basic_testcase {

Tests of this group would be run with: phpunit --group qtype_stack


All caught up? Check out our next project task!