Skip to content

Commit

Permalink
Add support for unit tests, coverage, and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-zuffinetti committed Nov 2, 2023
1 parent f5d6d0e commit 2897437
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 4 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
name: E2E Test
on:
pull_request:
branches: ["main", "develop"]
types: ["opened", "synchronize", "reopened", "ready_for_review"]
workflow_dispatch:

jobs:
launch:
strategy:
matrix:
version:
- 1.7.8.7
#- 1.7.7.5
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Get only last part of branch name in $SLUG_VERSION env var
run: |
VERSION=${{ matrix.version }}
echo "SLUG_VERSION=${VERSION//./-}" >> $GITHUB_ENV
- name: Generate token
id: generate_token
uses: tibdex/[email protected]
continue-on-error: true
with:
app_id: ${{ secrets.ALMA_UPDATE_CHECKS_APP_ID }}
private_key: ${{ secrets.ALMA_UPDATE_CHECKS_APP_PEM }}

- uses: LouisBrunner/[email protected]
id: e2e_status
with:
token: ${{ steps.generate_token.outputs.token }}
name: E2E Test / result (${{ matrix.version }})
status: "in_progress"

- name: Generate Github token for integration-infrastructure repo
id: generate_github_token_integration_infrastructure
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.ALMA_WF_TRIGGER_APP_ID }}
private_key: ${{ secrets.ALMA_WF_TRIGGER_APP_PEM }}
installation_id: ${{ secrets.ALMA_WF_TRIGGER_INSTALLATION_ID }}
repository: alma/integration-infrastructure

- name: Invoke e2e workflow with inputs
uses: benc-uk/[email protected]
with:
workflow: Deploy CMS
token: ${{ steps.generate_github_token_integration_infrastructure.outputs.token }}
repo: alma/integration-infrastructure
ref: main
inputs: >
{
"name": "e2e-${{ github.run_id }}",
"alma_plugin_branch": "${{ github.head_ref || github.ref_name }}",
"alma_plugin_test_branch" : "main",
"cms": "prestashop-${{ matrix.version }}",
"e2e": "true",
"e2e_check_id": "${{ steps.e2e_status.outputs.check_id }}",
"e2e_check_origin" : "${{ github.repository }}"
}
- uses: LouisBrunner/[email protected]
if: failure()
with:
token: ${{ steps.generate_token.outputs.token }}
check_id: ${{ steps.e2e_status.outputs.check_id }}
conclusion: failure
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
2 changes: 1 addition & 1 deletion alma/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Payment method module to integrate Alma in PrestaShop",
"type": "library",
"require-dev": {
"phpunit/phpunit": "^5",
"phpunit/phpunit": "^7",
"mockery/mockery": "^1.3",
"phpcompatibility/php-compatibility": "10.x-dev",
"prestashop/php-dev-tools": "^3.16"
Expand Down
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>
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ services:
- "./tmp/db_data:/var/lib/mysql"

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 +38,11 @@ services:
- PS_FOLDER_INSTALL=alminstall
- [email protected]
- ADMIN_PASSWD=test2test
depends_on:
- mysql
ports:
- "8080:80"
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
5 changes: 5 additions & 0 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

bash /tmp/docker_install.sh

exec "$@"

0 comments on commit 2897437

Please sign in to comment.