Skip to content

Commit

Permalink
feat: add phpunits
Browse files Browse the repository at this point in the history
2 types de tests:
unitaire: tester une classe seule sans dépendance = github workflow phpunit.yml
intégration: tester jeedom en fonctionnement, utilise docker pour démarrer la bdd et le container jeedom = github workflow docker-test.yml
  • Loading branch information
pifou25 committed Dec 8, 2024
1 parent 4bea7ea commit b266c02
Show file tree
Hide file tree
Showing 67 changed files with 2,016 additions and 1,774 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
/vendor
/docs
27 changes: 21 additions & 6 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# build docker image based on debian bullseye and bookworm
# build docker image based on debian bullseye or bookworm
# start both containers and run sick.php
# install composer dev depedencies and run phpunits into running containers
# stop & clean
name: Docker Test Image
name: Integrated PHPUnit

on:
# only trigger CI when pull request on following branches
pull_request:
branches:
- 'alpha'
push:
branches:
- 'feat/run_phpunit'
# this is to manually trigger the worklow
workflow_dispatch:
inputs:
Expand All @@ -30,21 +34,32 @@ jobs:
run: |
docker build -t jeedom:bullseye --build-arg DEBIAN=bullseye --build-arg DATABASE=1 .
- name: run jeedom:bullseye and check
# build current image for bullseye and check it
# run current image for bullseye and check it
run: |
docker run -p 80:80 -d --rm --name jeedom_bullseye jeedom:bullseye
sleep 45
until [ "`docker inspect -f {{.State.Health.Status}} jeedom_bullseye`" == "healthy" ]; do
echo "waiting container to be healthy..."
sleep 5;
done;
docker exec jeedom_bullseye php sick.php
docker exec jeedom_bullseye /bin/bash -c "COMPOSER_NO_DEV=0 && composer install"
docker exec jeedom_bullseye ./vendor/bin/phpunit --testsuite integration
- name: Build jeedom:bookworm
# build current image for bookworm
run: |
docker build -t jeedom:bookworm --build-arg DEBIAN=bookworm --build-arg DATABASE=1 .
- name: run jeedom:bookworm and check
# build current image for bookworm and check it
# run current image for bookworm and check it
run: |
docker run -p 81:80 -d --rm --name jeedom_bookworm jeedom:bookworm
sleep 45
until [ "`docker inspect -f {{.State.Health.Status}} jeedom_bullseye`" == "healthy" ]; do
echo "waiting container to be healthy..."
sleep 5;
done;
docker exec jeedom_bookworm php sick.php
docker exec jeedom_bookworm /bin/bash -c "COMPOSER_NO_DEV=0 && composer install"
docker exec jeedom_bookworm ./vendor/bin/phpunit --testsuite integration
- name: Clean docker image
continue-on-error: true
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# tests unitaires exécutés directement dans le contexte courant
# Aucune bdd, Jeedom non démarré
name: Standalone PHPUnit

on:
push:
# only trigger CI when push on following branches
branches:
- feat/run_phpunit
- alpha
pull_request:
branches:
- alpha

jobs:
build-test:
runs-on: ubuntu-latest

steps:
# checkout repo
# https://github.com/marketplace/actions/checkout
- uses: actions/checkout@v4
# composer installation
# https://github.com/marketplace/actions/composer-php-actions
- name: composer installation
uses: php-actions/composer@v6
# trigger phpunit using custom xml configuration
# https://github.com/marketplace/actions/phpunit-php-actions
- name: run standalone phpunit
uses: php-actions/phpunit@v4
with:
php_version: 7.4
testsuite: unit
php_extensions: xdebug pdo_mysql
coverage_clover: coverage/clover.xml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ tmp/*

!.htaccess
.env
.phpunit.result.cache
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"cacheTest::testSave":4,"cacheTest::testLoad":1,"cacheTest::testRemove":1,"cacheTest::testDefault":1,"cacheTest::testTime":1,"configTest::testSave":4,"configTest::testLoad":1,"configTest::testRemove":1,"configTest::testDefault":1,"cronTest::testCreate":4,"cronTest::testCreateWithOption":4,"logTest::testLoggerHandler with data set #0":4,"logTest::testLoggerHandler with data set #1":4,"logTest::testAddGetRemove with data set #0":4,"logTest::testAddLevels with data set #0":4,"logTest::testAddLevels with data set #1":4,"logTest::testAddLevels with data set #2":4,"logTest::testAddLevels with data set #3":4,"logTest::testAddLevels with data set #4":4,"logTest::testListe with data set #0":4,"Error":4,"pluginTest::testInstall with data set #0":4,"pluginTest::testCreateEqVirtual":1,"pluginTest::testCreateCmdVirtualBinary":1,"pluginTest::testCreateCmdVirtualNumeric":1,"pluginTest::testCmdVirtualNumeric":1,"pluginTest::testCreateCmdVirtualString":1,"pluginTest::testCmdVirtualString":1,"pluginTest::testCreateCmdVirtualActionOther":1,"pluginTest::testCmdVirtualActionOther":1,"pluginTest::testCreateCmdVirtualActionNumeric":1,"pluginTest::testCmdVirtualActionNumeric":1,"pluginTest::testCreateCmdVirtualActionColor":1,"pluginTest::testCmdVirtualActionColor":1,"pluginTest::testRemove":1,"scenarioExpressionTest::testCalculCondition":4,"scenarioExpressionTest::testVariable":4,"scenarioExpressionTest::testStringCondition":1,"scenarioTest::testGetterSetter with data set #2":4,"scenarioTest::testGetterSetter with data set #5":4,"scenarioTest::testGetterSetter with data set #10":4,"scenarioTest::testGetterSetter with data set #24":3,"userTest::testCreate":4,"userTest::testConnect":1,"userTest::testRemove":1},"times":{"ajaxTest::testSuccess with data set #0":0.107,"ajaxTest::testError with data set #0":0,"cacheTest::testSave":0.051,"cacheTest::testLoad":0,"cacheTest::testRemove":0,"cacheTest::testDefault":0,"cacheTest::testTime":0,"configTest::testSave":0.036,"configTest::testLoad":0,"configTest::testRemove":0,"configTest::testDefault":0,"cronTest::testCreate":0.032,"cronTest::testCreateWithOption":0,"logTest::testLoggerHandler with data set #0":0,"logTest::testLoggerHandler with data set #1":0,"logTest::testAddGetRemove with data set #0":0,"logTest::testAddLevels with data set #0":0,"logTest::testAddLevels with data set #1":0,"logTest::testAddLevels with data set #2":0,"logTest::testAddLevels with data set #3":0,"logTest::testAddLevels with data set #4":0,"logTest::testListe with data set #0":0,"Error":0.008,"pluginTest::testInstall with data set #0":0,"pluginTest::testCreateEqVirtual":0,"pluginTest::testCreateCmdVirtualBinary":0,"pluginTest::testCreateCmdVirtualNumeric":0,"pluginTest::testCmdVirtualNumeric":0,"pluginTest::testCreateCmdVirtualString":0,"pluginTest::testCmdVirtualString":0,"pluginTest::testCreateCmdVirtualActionOther":0,"pluginTest::testCmdVirtualActionOther":0,"pluginTest::testCreateCmdVirtualActionNumeric":0,"pluginTest::testCmdVirtualActionNumeric":0,"pluginTest::testCreateCmdVirtualActionColor":0,"pluginTest::testCmdVirtualActionColor":0,"pluginTest::testRemove":0,"scenarioExpressionTest::testCalculCondition":0.099,"scenarioExpressionTest::testVariable":0,"scenarioExpressionTest::testStringCondition":0,"scenarioTest::testGetterSetter with data set #0":0.182,"scenarioTest::testGetterSetter with data set #1":0,"scenarioTest::testGetterSetter with data set #2":0.121,"scenarioTest::testGetterSetter with data set #3":0,"scenarioTest::testGetterSetter with data set #4":0,"scenarioTest::testGetterSetter with data set #5":0,"scenarioTest::testGetterSetter with data set #6":0,"scenarioTest::testGetterSetter with data set #7":0,"scenarioTest::testGetterSetter with data set #8":0,"scenarioTest::testGetterSetter with data set #9":0,"scenarioTest::testGetterSetter with data set #10":0.001,"scenarioTest::testGetterSetter with data set #11":0,"scenarioTest::testGetterSetter with data set #12":0,"scenarioTest::testGetterSetter with data set #13":0,"scenarioTest::testGetterSetter with data set #14":0.034,"scenarioTest::testGetterSetter with data set #15":0,"scenarioTest::testGetterSetter with data set #16":0,"scenarioTest::testGetterSetter with data set #17":0,"scenarioTest::testGetterSetter with data set #18":0,"scenarioTest::testGetterSetter with data set #19":0,"scenarioTest::testGetterSetter with data set #20":0,"scenarioTest::testGetterSetter with data set #21":0,"scenarioTest::testGetterSetter with data set #22":0,"scenarioTest::testGetterSetter with data set #23":0,"scenarioTest::testGetterSetter with data set #24":0,"scenarioTest::testGetterSetter with data set #25":0,"scenarioTest::testGetterSetter with data set #26":0,"scenarioTest::testGetterSetter with data set #27":0,"scenarioTest::testGetterSetter with data set #28":0,"scenarioTest::testGetterSetter with data set #29":0,"scenarioTest::testPersistLog":0.063,"shellTest::testGetCmd":0,"shellTest::testCommandExist":0.018,"shellTest::testBackground with data set #0":0,"shellTest::testBackground with data set #1":0,"shellTest::testExec":0.03,"shellTest::testInstance":0.016,"shellTest::testExecute":0.014,"shellTest::testCache":0.002,"shellTest::testHistory":0.005,"userTest::testCreate":0.013,"userTest::testConnect":0,"userTest::testRemove":0,"utilsTest::testTemplace_replace with data set #0":0,"utilsTest::testTemplace_replace with data set #1":0,"utilsTest::testInit":0,"utilsTest::testConvertDuartion with data set #0":0,"utilsTest::testConvertDuartion with data set #1":0,"utilsTest::testConvertDuartion with data set #2":0,"utilsTest::testConvertDuartion with data set #3":0,"utilsTest::testConvertDuartion with data set #4":0,"utilsTest::testConvertDuartion with data set #5":0,"utilsTest::testConvertDuartion with data set #6":0,"utilsTest::testConvertDuartion with data set #7":0,"utilsTest::testIs_json with data set #0":0,"utilsTest::testIs_json with data set #1":0,"utilsTest::testIs_json with data set #2":0,"utilsTest::testIs_json with data set #3":0,"utilsTest::testCleanPath with data set #0":0}}
43 changes: 30 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,43 @@ RUN apt -o Dpkg::Options::="--force-confdef" -y install software-properties-comm
gettext libcurl3-gnutls chromium librsync-dev ssl-cert iputils-ping \
apache2 apache2-utils libexpat1 ssl-cert \
php libapache2-mod-php php-json php-mysql php-curl php-gd php-imap php-xml php-opcache php-soap php-xmlrpc \
php-common php-dev php-zip php-ssh2 php-mbstring php-ldap php-yaml php-snmp && apt -y remove brltty
php-common php-dev php-zip php-ssh2 php-mbstring php-ldap php-yaml php-snmp && apt -y remove brltty \
> /dev/null

COPY install/install.sh /tmp/
RUN sh /tmp/install.sh -s 1 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 2 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 3 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 4 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 5 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
COPY --chown=root:root --chmod=550 install/install.sh /root/
# install step by step : step_1_upgrade ... useless, using the LATEST debian
RUN sh /root/install.sh -s 1 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_2_mainpackage ... useless, already installed before
# RUN sh /root/install.sh -s 2 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_3_database ... only if $DATABASE
RUN sh /root/install.sh -s 3 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_4_apache
RUN sh /root/install.sh -s 4 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_5_php : install php with extensions
RUN sh /root/install.sh -s 5 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step 6 : copy jeedom source files from local
COPY . ${WEBSERVER_HOME}
RUN sh /tmp/install.sh -s 7 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 8 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 9 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 10 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
RUN sh /tmp/install.sh -s 11 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_7_jeedom_customization_mariadb
RUN sh /root/install.sh -s 7 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_8_jeedom_customization
RUN sh /root/install.sh -s 8 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_9_jeedom_configuration
RUN sh /root/install.sh -s 9 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_10_jeedom_installation
RUN sh /root/install.sh -s 10 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
# step_11_jeedom_post
RUN sh /root/install.sh -s 11 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker

RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN echo >${WEBSERVER_HOME}/initialisation

WORKDIR ${WEBSERVER_HOME}
# check apache is running
HEALTHCHECK --interval=1m --timeout=3s --retries=5 --start-period=10s --start-interval=5s \
CMD curl -f http://localhost/ || exit 1

EXPOSE 80
EXPOSE 443
COPY --chown=root:root --chmod=550 install/OS_specific/Docker/init.sh /root/
COPY --chown=root:root --chmod=550 install/bashrc /root/.bashrc
CMD ["bash", "/root/init.sh"]
CMD ["/root/init.sh"]
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
"psr/log": "^1.1"
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
"allow-plugins": {
"php-http/discovery": true
}
},
"require-dev": {
"phpunit/phpunit": "^9.6"
}
}
}
Loading

0 comments on commit b266c02

Please sign in to comment.