Skip to content

Commit

Permalink
feat: Add testing environment
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoya-de committed Apr 27, 2022
1 parent 78a4fce commit 133bb9f
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 91 deletions.
95 changes: 48 additions & 47 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,36 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: curl, json, :opcache, xdebug, mbstring, xdebug
coverage: xdebug
ini-values: memory_limit=-1,error_reporting=-1,log_errors_max_len=0,zend.assertions=1,assert.exception=1,xdebug.show_exception_trace=0,suhosin.executor.include.whitelist=phar,xdebug.mode="develop,coverage"

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-dev-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-dev-composer-
- name: Install dependencies
uses: php-actions/composer@v6
with:
command: install
dev: yes
php_version: 8.0
php_version: 7.4
version: 2
args: --ignore-platform-reqs --prefer-dist -no --no-progress
args: --ignore-platform-reqs --prefer-dist -no --no-progress --no-plugins

- name: Create .env for docker
run: |
rm -f tests/utils/.env
echo "USER_ID=$(id -u)" >> tests/utils/.env
echo "GROUP_ID=$(id -g)" >> tests/utils/.env
- name: Build test container
run: docker-compose build tests

- name: Run tests
run: composer test
run: |
docker-compose run --rm tests --all
docker-compose down
- name: Compress HTML code coverage
run: |
cd build/
tar -czf /tmp/code-coverage-html.tar.gz code-coverage-html/
tar -czf /tmp/code-coverage-html.tar.gz html/
- name: Upload HTML code coverage report
uses: actions/upload-artifact@v2
Expand All @@ -67,36 +58,58 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: code-coverage-clover
path: build/code-coverage-clover.xml
path: build/clover.xml
retention-days: 1

- name: Upload PHPUnit junit report
- name: Upload PHP-formatted code coverage report
uses: actions/upload-artifact@v2
with:
name: phpunit-junit
path: build/junit.xml
name: code-coverage-php
path: build/coverage.cov
retention-days: 1

- name: Fix code coverage paths
# Currently unavailable
# - name: Upload PHPUnit junit report
# uses: actions/upload-artifact@v2
# with:
# name: phpunit-junit
# path: build/junit.xml
# retention-days: 1

- name: Upload OXID metrics report
uses: actions/upload-artifact@v2
with:
name: metrics
path: build/metrics.txt
retention-days: 1

- name: Upload OXID pdepend report
uses: actions/upload-artifact@v2
with:
name: pdepend
path: build/pdepend.xml
retention-days: 1

- name: Fix code coverage paths
# Currently unavailable: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' build/junit.xml
run: |
sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' build/code-coverage-clover.xml
sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' build/junit.xml
sed -i 's@/app/@/github/workspace/@g' build/clover.xml
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
# Currently unavailable: -Dsonar.php.tests.reportPath=build/junit.xml
args: >
-Dsonar.projectKey=MakairaIO_oxid-connect-essential
-Dsonar.organization=makairaio
-Dsonar.language=php
-Dsonar.sources=src/
-Dsonar.tests=tests/
-Dsonar.sourceEncoding=UTF-8
-Dsonar.php.tests.reportPath=build/junit.xml
-Dsonar.php.coverage.reportPaths=build/code-coverage-clover.xml
-Dsonar.php.coverage.reportPaths=build/clover.xml
release:
name: Create a new release
Expand All @@ -110,24 +123,12 @@ jobs:
fetch-depth: 0
persist-credentials: false

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-nodev-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-nodev-composer-
- name: Install dependencies
uses: php-actions/composer@v6
with:
command: install
dev: no
php_version: 8.0
dev: yes
php_version: 7.4
version: 2
args: --ignore-platform-reqs --prefer-dist -no --no-progress

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
!/build/.gitkeep
/.idea
/composer.lock
/tests/reports/
tests/utils/.env
14 changes: 0 additions & 14 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,4 @@
<directory>tests/</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/code-coverage-clover.xml" />
<html outputDirectory="build/code-coverage-html/" lowUpperBound="35" highLowerBound="70" />
</report>
</coverage>

<logging>
<junit outputFile="build/junit.xml" />
</logging>
</phpunit>
23 changes: 14 additions & 9 deletions tests/utils/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@ FROM marmaladegmbh/php:7.4

COPY tests/utils/composer.test.json /app/composer.json
COPY tests/utils/config.test.php /app/
COPY tests/utils/php.test.ini /usr/local/etc/php/conf.d/zz-custom.ini
COPY . /app/modules/oxid-connect-essential/
COPY tests/utils/install-mysql-client /usr/bin/
COPY tests/utils/default-command.sh /
COPY tests/utils/run-tests /usr/local/bin/run-tests
COPY tests/utils/generated-services-updater /app/bin/

WORKDIR /app

ENV PARTIAL_MODULE_PATHS=makaira/oxid-connect-essential

RUN install-mysql-client dev && \
apt install -y libmagickwand-6.q16-6 && \
apt-get install -y libmagickwand-6.q16-6 && \
ln -snf /bin/composer2 /bin/composer && \
/bin/composer install -nq && \
/bin/composer install --no-progress -nq && \
echo "include __DIR__ . '/../config.test.php';" >> source/config.inc.php && \
rm -rf app/modules/ && \
apt autoremove -yqq --purge && \
apt clean && \
rm -rf /var/lib/apt/lists/*
apt-get autoremove -yqq --purge && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
. /app/modules/oxid-connect-essential/tests/utils/.env && \
chown -R $USER_ID:$GROUP_ID . && \
rm -f vendor/makaira/oxid-connect-essential && \
rm -rf source/modules/makaira/oxid-connect-essential && \
bin/generated-services-updater


CMD /default-command.sh
ENTRYPOINT ["run-tests"]
CMD ["--unit"]
16 changes: 7 additions & 9 deletions tests/utils/composer.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,23 @@
"oe:ide-helper:generate": [
"if [ -f ./vendor/bin/oe-eshop-ide_helper ]; then oe-eshop-ide_helper; fi"
],
"test": [
"@dev:update",
"run-tests": [
"runtests"
],
"run-tests-coverage": [
"runtests-coverage"
],
"run-metrics": [
"runmetrics"
],
"dev:update": [
"@dev:remove-mod",
"@dev:update-mod",
"@dev:activate-mod",
"@dev:clear-tmp"
],
"dev:clear-tmp": [
"find source/tmp/ -type f -delete"
],
"dev:remove-mod": [
"oe-console oe:module:deactivate makaira_oxid-connect-essential",
"rm -f vendor/makaira/oxid-connect-essential",
"rm -rf source/modules/makaira/oxid-connect-essential",
"@php bin/generated-services-updater"
],
"dev:activate-mod": [
"oe-console oe:module:activate makaira_oxid-connect-essential"
],
Expand Down
9 changes: 0 additions & 9 deletions tests/utils/default-command.sh

This file was deleted.

11 changes: 8 additions & 3 deletions tests/utils/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
services:
shop:
tests:
build:
context: ../../
dockerfile: ./tests/utils/Dockerfile
volumes:
- "../../:/app/modules/oxid-connect-essential"
- "./config.test.php:/app/config.test.php:ro"
- "/etc/passwd:/etc/passwd:ro"
- "/etc/group:/etc/group:ro"
depends_on:
- db
user: ${USER_ID:?You must set the user ID in the .env file}:${GROUP_ID:?You must set the group ID in the .env file}
environment:
COMPOSE_PROJECT_NAME: ${COMPOSE_PROJECT_NAME:-Foo}
APP_DATA: "/app_data"
PHPINI_MEMORY_LIMIT: 1G
PHPINI_SESSION__GC_MAXLIFETIME: "3600"
Expand All @@ -24,6 +25,9 @@ services:
PHPINI_XDEBUG__VAR_DISPLAY_MAX_DATA: 1024
PHPINI_XDEBUG__VAR_DISPLAY_MAX_DEPTH: 10
PHP_IDE_CONFIG: serverName=oxid64-tests.${DOMAIN:-makaira.vm}
extra_hosts:
- "host.docker.internal:host-gateway"
restart: "no"

db:
image: mysql:5.7
Expand All @@ -45,3 +49,4 @@ services:
MYSQL_DATABASE: oxid
MYSQL_USER: oxid
MYSQL_PASSWORD: oxid
restart: "no"
6 changes: 6 additions & 0 deletions tests/utils/lint-php-files
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

files=$(find ./src/ -iname '*.php')
for f in $files; do
php -l $f
done
18 changes: 18 additions & 0 deletions tests/utils/php.test.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
zend_extension=xdebug.so
memory_limit=-1
max_execution_time=0

[session]
session.gc_maxliftime=3600

[xdebug]
xdebug.start_with_request=trigger
xdebug.output_dir=/app_data
xdebug.client_host=host.docker.internal
xdebug.client_port=9000
xdebug.cli_color=1
xdebug.max_nesting_level=512
xdebug.var_display_max_children=256
xdebug.var_display_max_data=1024
xdebug.var_display_max_depth=10
xdebug.mode=debug,coverage
Loading

0 comments on commit 133bb9f

Please # to comment.