Skip to content

Commit

Permalink
Merge pull request #238 from alma/devx/setup_unit_tests
Browse files Browse the repository at this point in the history
[DEX-420] Add support for unit tests, coverage, and CI
  • Loading branch information
remi-zuffinetti authored Nov 28, 2023
2 parents 3de4038 + 229742a commit 90f77fb
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 4 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Continuous Integration

on:
push:
pull_request:
branches:
- main
- develop
workflow_dispatch:

jobs:
tests:

runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Run unit tests
run: make test
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ARG COMPOSER_VERSION=2
ARG PLATFORM_VERSION=8.1.0

FROM composer:${COMPOSER_VERSION} AS composer
FROM prestashop/prestashop:${PLATFORM_VERSION}

ENV PS_ENABLE_SSL=1

# Change root password
RUN echo 'root:alma' | chpasswd

RUN pecl install xdebug-3.1.5 \
&& docker-php-ext-enable xdebug

WORKDIR /var/www/html/modules/alma/

RUN head -n -1 /tmp/docker_run.sh > /tmp/docker_install.sh
COPY ./scripts/entrypoint.sh /entrypoint.sh

# Composer install
COPY --from=composer /usr/bin/composer /usr/bin/composer
COPY alma/composer.json .

RUN composer install

ENTRYPOINT ["bash", "/entrypoint.sh"]
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ crowdin-download:
.PHONY: crowdin-upload
crowdin-upload:
crowdin upload sources

.PHONY: test
test:
docker compose build prestashop
docker compose run --rm prestashop ./vendor/bin/phpunit -c phpunit.ci.xml --coverage-text
9 changes: 9 additions & 0 deletions alma/phpunit.ci.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@
</testsuite>
</testsuites>

<filter>
<whitelist includeUncoveredFilesFromWhitelist="true">
<directory>../alma</directory>
<exclude>
<directory>../alma/vendor</directory>
</exclude>
</whitelist>
</filter>

</phpunit>
25 changes: 23 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'

services:
mysql:
image: mysql:5.5
image: mysql:8.2
environment:
- MYSQL_ROOT_PASSWORD=admin
- MYSQL_DATABASE=prestashop
Expand All @@ -12,9 +12,25 @@ services:
- 3307:3306
volumes:
- "./tmp/db_data:/var/lib/mysql"
healthcheck:
test:
[
"CMD",
"mysqladmin",
"ping",
"-p$$MYSQL_ROOT_PASSWORD"
]
timeout: 10s
retries: 10

prestashop:
image: prestashop/prestashop:1.6.1.23
build:
context: .
args:
# We are not using version 8.x for now, as this will install with PHP 8.x.
# This will then require a PHPUnit version that will be too high, requiring
# updating prestashop/autoindex.
PLATFORM_VERSION: 1.7.8.7
environment:
- DB_SERVER=mysql
- DB_NAME=prestashop
Expand All @@ -32,8 +48,13 @@ services:
- PS_FOLDER_INSTALL=alminstall
- [email protected]
- ADMIN_PASSWD=test2test
depends_on:
mysql:
condition: service_healthy
ports:
- "8080:80"
# platform: linux/x86_64
volumes:
- ./alma:/var/www/html/modules/alma
- /var/www/html/modules/alma/vendor # do not mount vendor inside container
- ./docker/php-customization.ini:/usr/local/etc/php/conf.d/php-customization.ini
4 changes: 2 additions & 2 deletions docker/php-customization.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ max_input_vars=5000

display_errors=1

;[xdebug]
[xdebug]
xdebug.mode=develop,coverage
;; comment out this line to disable xdebug
;zend_extension=xdebug.so
;xdebug.mode=develop
;xdebug.remote_enable=1
;xdebug.remote_autostart=1
;xdebug.log=/var/log/xdebug.log
Expand Down
12 changes: 12 additions & 0 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

########################################
# Exit as soon as any line in the bash script fails.
set -o errexit

# pipefail: the return value of a pipeline is the status of the last command to exit with a non-zero status, or zero if no command exited with a non-zero status
set -o pipefail

bash /tmp/docker_install.sh

exec "$@"

0 comments on commit 90f77fb

Please sign in to comment.