Skip to content

Commit cbcf7d3

Browse files
committed
feat: add phpunits
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
1 parent 4bea7ea commit cbcf7d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2013
-1774
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.git
2+
/vendor
3+
/docs

.github/workflows/docker-test.yml

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
# build docker image based on debian bullseye and bookworm
1+
# build docker image based on debian bullseye or bookworm
22
# start both containers and run sick.php
3+
# install composer dev depedencies and run phpunits into running containers
34
# stop & clean
4-
name: Docker Test Image
5+
name: Integrated PHPUnit
56

67
on:
78
# only trigger CI when pull request on following branches
89
pull_request:
910
branches:
1011
- 'alpha'
12+
push:
13+
branches:
14+
- 'feat/run_phpunit'
1115
# this is to manually trigger the worklow
1216
workflow_dispatch:
1317
inputs:
@@ -30,21 +34,32 @@ jobs:
3034
run: |
3135
docker build -t jeedom:bullseye --build-arg DEBIAN=bullseye --build-arg DATABASE=1 .
3236
- name: run jeedom:bullseye and check
33-
# build current image for bullseye and check it
37+
# run current image for bullseye and check it
3438
run: |
3539
docker run -p 80:80 -d --rm --name jeedom_bullseye jeedom:bullseye
36-
sleep 45
40+
until [ "`docker inspect -f {{.State.Health.Status}} jeedom_bullseye`" == "healthy" ]; do
41+
echo "waiting container to be healthy..."
42+
sleep 5;
43+
done;
3744
docker exec jeedom_bullseye php sick.php
45+
docker exec jeedom_bullseye /bin/bash -c "COMPOSER_NO_DEV=0 && composer install"
46+
docker exec jeedom_bullseye ./vendor/bin/phpunit --testsuite integration
47+
3848
- name: Build jeedom:bookworm
3949
# build current image for bookworm
4050
run: |
4151
docker build -t jeedom:bookworm --build-arg DEBIAN=bookworm --build-arg DATABASE=1 .
4252
- name: run jeedom:bookworm and check
43-
# build current image for bookworm and check it
53+
# run current image for bookworm and check it
4454
run: |
4555
docker run -p 81:80 -d --rm --name jeedom_bookworm jeedom:bookworm
46-
sleep 45
56+
until [ "`docker inspect -f {{.State.Health.Status}} jeedom_bullseye`" == "healthy" ]; do
57+
echo "waiting container to be healthy..."
58+
sleep 5;
59+
done;
4760
docker exec jeedom_bookworm php sick.php
61+
docker exec jeedom_bookworm /bin/bash -c "COMPOSER_NO_DEV=0 && composer install"
62+
docker exec jeedom_bookworm ./vendor/bin/phpunit --testsuite integration
4863
4964
- name: Clean docker image
5065
continue-on-error: true

.github/workflows/phpunit.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# tests unitaires exécutés directement dans le contexte courant
2+
# Aucune bdd, Jeedom non démarré
3+
name: Standalone PHPUnit
4+
5+
on:
6+
push:
7+
# only trigger CI when push on following branches
8+
branches:
9+
- feat/run_phpunit
10+
- alpha
11+
pull_request:
12+
branches:
13+
- alpha
14+
15+
jobs:
16+
build-test:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
# checkout repo
21+
# https://github.com/marketplace/actions/checkout
22+
- uses: actions/checkout@v4
23+
# composer installation
24+
# https://github.com/marketplace/actions/composer-php-actions
25+
- name: composer installation
26+
uses: php-actions/composer@v6
27+
# trigger phpunit using custom xml configuration
28+
# https://github.com/marketplace/actions/phpunit-php-actions
29+
- name: run standalone phpunit
30+
uses: php-actions/phpunit@v4
31+
with:
32+
php_version: 7.4
33+
testsuite: unit
34+
php_extensions: xdebug pdo_mysql
35+
coverage_clover: coverage/clover.xml

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ tmp/*
4646

4747
!.htaccess
4848
.env
49+
.phpunit.result.cache

Dockerfile

+30-13
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,43 @@ RUN apt -o Dpkg::Options::="--force-confdef" -y install software-properties-comm
4242
gettext libcurl3-gnutls chromium librsync-dev ssl-cert iputils-ping \
4343
apache2 apache2-utils libexpat1 ssl-cert \
4444
php libapache2-mod-php php-json php-mysql php-curl php-gd php-imap php-xml php-opcache php-soap php-xmlrpc \
45-
php-common php-dev php-zip php-ssh2 php-mbstring php-ldap php-yaml php-snmp && apt -y remove brltty
45+
php-common php-dev php-zip php-ssh2 php-mbstring php-ldap php-yaml php-snmp && apt -y remove brltty \
46+
> /dev/null
4647

47-
COPY install/install.sh /tmp/
48-
RUN sh /tmp/install.sh -s 1 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
49-
RUN sh /tmp/install.sh -s 2 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
50-
RUN sh /tmp/install.sh -s 3 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
51-
RUN sh /tmp/install.sh -s 4 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
52-
RUN sh /tmp/install.sh -s 5 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
48+
COPY --chown=root:root --chmod=550 install/install.sh /root/
49+
# install step by step : step_1_upgrade ... useless, using the LATEST debian
50+
RUN sh /root/install.sh -s 1 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
51+
# step_2_mainpackage ... useless, already installed before
52+
# RUN sh /root/install.sh -s 2 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
53+
# step_3_database ... only if $DATABASE
54+
RUN sh /root/install.sh -s 3 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
55+
# step_4_apache
56+
RUN sh /root/install.sh -s 4 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
57+
# step_5_php : install php with extensions
58+
RUN sh /root/install.sh -s 5 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
59+
# step 6 : copy jeedom source files from local
5360
COPY . ${WEBSERVER_HOME}
54-
RUN sh /tmp/install.sh -s 7 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
55-
RUN sh /tmp/install.sh -s 8 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
56-
RUN sh /tmp/install.sh -s 9 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
57-
RUN sh /tmp/install.sh -s 10 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
58-
RUN sh /tmp/install.sh -s 11 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
61+
# step_7_jeedom_customization_mariadb
62+
RUN sh /root/install.sh -s 7 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
63+
# step_8_jeedom_customization
64+
RUN sh /root/install.sh -s 8 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
65+
# step_9_jeedom_configuration
66+
RUN sh /root/install.sh -s 9 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
67+
# step_10_jeedom_installation
68+
RUN sh /root/install.sh -s 10 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
69+
# step_11_jeedom_post
70+
RUN sh /root/install.sh -s 11 -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE} -i docker
71+
5972
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
6073
RUN echo >${WEBSERVER_HOME}/initialisation
6174

6275
WORKDIR ${WEBSERVER_HOME}
76+
# check apache is running
77+
HEALTHCHECK --interval=1m --timeout=3s --retries=5 --start-period=10s --start-interval=5s \
78+
CMD curl -f http://localhost/ || exit 1
79+
6380
EXPOSE 80
6481
EXPOSE 443
6582
COPY --chown=root:root --chmod=550 install/OS_specific/Docker/init.sh /root/
6683
COPY --chown=root:root --chmod=550 install/bashrc /root/.bashrc
67-
CMD ["bash", "/root/init.sh"]
84+
CMD ["/root/init.sh"]

composer.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
"psr/log": "^1.1"
88
},
99
"config": {
10-
"allow-plugins": {
11-
"php-http/discovery": true
12-
}
10+
"allow-plugins": {
11+
"php-http/discovery": true
12+
}
13+
},
14+
"require-dev": {
15+
"phpunit/phpunit": "^9.6"
1316
}
14-
}
17+
}

0 commit comments

Comments
 (0)