Moodle HQ provides moodle-ci-runner as a way to run the Moodle automated tests, e.g. on a CI server. (If you want to do interactive development, then moodle-docker is more appropriate. These are worth knowing about if you suddenly find yourself needing to test your code in a sepcific environment that is a pain to set up (E.g test with PHP7.4 and Microsoft SQL server.) I don't really undersand how this works. Lets just waive our hands and say 'Docker magic' but I was able to understand enough to get the CodeRunner tests working.
The complication is, of course, that CodeRunner needs Jobe, so we need to add that to the setup. Here is, manually, what you need to do to get this running. (Becuase this is CI, I acutally have a bash script to do this automatically, but I think it is more readable to give the steps manually.
- To use this, you will have moodle-ci-runner checked out, and in there, the key files are in
runner/main/
jobtypes/
behat/
behat.sh
phpunit/
phpunit.sh
modules/
docker-... in various forms, and some other modules. - The first thing to do is to add a new module for docker-jobe. So
mkdir runner/main/modules/docker-jobe
then save the attached file in there (assuming Moodle lets me attach something dangerous like a .sh file). - Then we need to tell the jobs to use that, so edit each of runner/main/jobtypes/behat/behat.sh and runner/main/jobtypes/phpunit/phpunit.sh and in the list of required modules in function ..._modules() { add docker-jobe. (I added it just after docker-php).
- The other thing you will have to use this is to have the Moodle code checked out somewhere (with the coderunner and adaptive_adapted_for_coderunner plugins added.) In there, you need to create the question/type/coderunner/tests/fixtures/test-sandbox-config.php file as usual to run the tests. The contents you need for that file in this setup is
<?php
That is, the 'hostname' of the jobe container of the virtual internal network the docker has set up is 'jobe'.
echo "set_config('jobesandbox_enabled', 1, 'qtype_coderunner');
echo "set_config('jobe_host', 'jobe', 'qtype_coderunner');