How to run mission-portal phpunit and phpunit-selenium tests via docker.

The latest docker hub image is referenced in docker.sh.

If changes are made to setup.sh for packages and such you should rebuild the docker image and push up a different version.

./build.sh
docker tag cfengine-selenium-tests cfengine/cfengine-selenium-tests:php82-ubuntu22
# password for "cfengine" user at mystiko/developers/CFEngine/hub.docker.com/cfengine@hub.docker.com
docker push cfengine-selenium-tests:php82-ubuntu22

- change directory to NTECH_ROOT
  e.g. the directory in which mission-portal, nova, core, etc are checked out

# without cleaning local built bits before using them in a container you can get errors like
# gcc: error: /data/core/libpromises/.libs/libpromises.dylib: No such file or directory
rm -rf cfengine-nova-hub # previous packages built and such
# if core, etc are not autotools configured these clean targets will fail, so maybe skip these steps
#make -C core clean
#make -C enterprise clean
# todo maybe do git clean -xfd, but that's dangerous in a developer place :(
make -C mission-portal clean
export GITLAB_BUILD_REPOSITORY_TOKEN=$(pass mystiko/developers/CFEngine/GITLAB_BUILD_REPOSITORY_TOKEN)
if [ ! -f artifacts/*.deb ]; then
  ./buildscripts/ci/clean.sh
  ./buildscripts/ci/docker.sh 2>&1 | tee log
fi
./mission-portal/ci/clean.sh
./mission-portal/ci/docker.sh 2>&1 | tee -a log

artifacts saved are like this:

Craigs-MBP:Downloads craig$ unzip -t artifacts\ \(2\).zip 
Archive:  artifacts (2).zip
    testing: artifacts/               OK
    testing: artifacts/cfengine_support_case_NA-0ac90ddd5a06-2023-07-13-1437.tar.gz   OK
    testing: artifacts/dump_cfdb_1689259048.sql   OK
    testing: artifacts/dump_cfmp_1689259048.sql   OK
    testing: artifacts/dump_cfsettings_1689259048.sql   OK
    testing: artifacts/failure1689259048.png   OK
    testing: artifacts/phpunit-selenium-report.xml   OK
    testing: artifacts/phpunit-report.xml   OK
    testing: artifacts/cfengine-nova-hub_3.23.0a.9ee4a60da~.ubuntu20_amd64.deb   OK


# run a single test (docker container)

use mission-portal/ci/shell.sh to enter the shell of the docker container after running ci/docker.sh once to build the container and setup the various needed components (selenium, geckodriver, cfengine hub install)

prepare the environment possibly

sudo mkdir -p /artifacts
sudo chown cfapache /artifacts

run the following command, changing the value for the filter argument as needed:

sudo --preserve-env=GITLAB_BUILD_REPOSITORY_TOKEN -u cfapache  ./vendor/phpunit/phpunit/phpunit --coverage-clover="${NTECH_ROOT}/artifacts/coverage.xml" --log-junit "${NTECH_ROOT}/artifacts/phpunit-report.xml" --debug --verbose --stop-on-defect --filter CfDirectoryHelperTest

Note that you may need to provide the GITLAB_BUILD_REPOSITORY_TOKEN with an export command if you are working on a build project related test.
