Skip to content

Commit

Permalink
Fix unit/integration test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
joernott committed Jul 12, 2024
1 parent 056ef81 commit 8684c9c
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 71 deletions.
73 changes: 43 additions & 30 deletions .github/oxid-esales/twig-component.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
# This plan should be used before ~/defaults/component.yml. That template uses
# the variables below to fill all the settings for the installation into
# /var/www directly without installing a shop.
install: &install
method: script
script: 'source/.github/oxid-esales/install.sh'
git:
ref: '{{ .Data.global.git.default_ref }}'
composer:
early: 'skip'
root_url: ''
transform: |
{
"preferred-install": {
"oxid-esales/*": "source",
"oxid-professional-services/*": "source",
"ddoe/*": "source"
},
"require": {
"oxid-esales/twig-component": "dev-{{ .Data.global.git.safe_ref_name }}",
"oxid-esales/twig-admin-theme": "{{ .Data.global.composer.dev_ref }}",
"oxid-esales/apex-theme": "{{ .Data.global.composer.dev_ref }}",
"twig/twig": "v3.8.0"
}
}
output:
files: |
docker-compose.yml
source/composer.json*
source/composer.lock
source/source/config.inc.php
source/vendor/oxid-esales/oxideshop-ce/source/config.inc.php
data/php/logs/error_log.txt
global:
# The organisation part of the composer package name <org>/<name>
org: 'oxid-esales'
# The name part of the composer package, also used in other places
name: 'twig-component'
# The repository organisation/name to check out
repo: 'OXID-eSales/twig-component'
install_shop_with_modules: *install

# These tests are run for all PHP/MySQL combinations specified when calling
# the workflow
runscript:
runscript: &runscript
matrix:
# A string containing a valid json array of scripts to execute
# The scripts follow the pattern "<prefix>:<composer_alias>" for scripts
# defined in composer.json and "<prefix>:~/<shell_script>" for shell
# scripts located in tests/Scripts
# If you want to see the tests output, make sure to generate it in tests/Output
script: '["component:~/unit.sh","component:~/integration.sh"]'
script: |
[
"twig:~/unit.sh",
"twig:~/integration.sh"
]
twig:
path: 'vendor/oxid-esales/twig-component'

sonarcloud:
# Remove the next two lines if you want to feed the results of your tests
# to sonarcloud. You need to make sure that your scripts generate an xml
# coverage file in tests/Reports, e.g. by adding
# --coverage-clover=tests/Reports/coverage_phpunit_integration.xml to them.
matrix:
testplan: 'skip'
# If you want to enable sonarcloud, you need to fill out the
# settings for project_key and project_name. You can get them from
# https://sonarcloud.io/organizations/oxid-esales/projects. The defaults for
# organization and parameters should be OK for most cases, so you don't need
# to overwrite them here.
project_key: '???'
project_name: '???'

finish:
slack_title: 'Twig Component ({{ .Data.github.RefName }}) by {{ .Github.Actor }}'
slack_compact: true
2 changes: 1 addition & 1 deletion .github/workflows/dispatch_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ on:
custom_testplan:
type: string
description: 'Custom testplan'
default: '~/defaults/php8.2_mysql5.7_only.yaml,~/twig-component.yaml,~/defaults/component.yaml'
default: '~/defaults/php8.2_mysql5.7_only.yaml,~/twig-component.yaml'
runs_on:
type: string
description: 'JSON string/array describing the runner'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/scheduled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
if: always()
uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4
with:
testplan: '~/defaults/7.0.x.yaml,~/defaults/scheduled.yaml,~/twig-component.yaml,~/defaults/component.yaml'
testplan: '~/defaults/7.0.x.yaml,~/defaults/scheduled.yaml,~/twig-component.yaml'
runs_on: '"ubuntu-latest"'
defaults: 'v4'
plan_folder: '.github/oxid-esales'
Expand All @@ -32,7 +32,7 @@ jobs:
if: always()
uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4
with:
testplan: '~/defaults/7.1.x.yaml,~/defaults/scheduled.yaml,~/twig-component.yaml,~/defaults/component.yaml'
testplan: '~/defaults/7.1.x.yaml,~/defaults/scheduled.yaml,~/twig-component.yaml'
runs_on: '"ubuntu-latest"'
defaults: 'v4'
plan_folder: '.github/oxid-esales'
Expand All @@ -55,7 +55,7 @@ jobs:
if: always()
uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4
with:
testplan: '~/defaults/7.2.x.yaml,~/defaults/scheduled.yaml,~/twig-component.yaml,~/defaults/component.yaml'
testplan: '~/defaults/7.2.x.yaml,~/defaults/scheduled.yaml,~/twig-component.yaml'
runs_on: '"ubuntu-latest"'
defaults: 'v4'
plan_folder: '.github/oxid-esales'
Expand All @@ -78,7 +78,7 @@ jobs:
if: always()
uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4
with:
testplan: '~/defaults/8.0.x.yaml,~/defaults/scheduled.yaml,~/twig-component.yaml,~/defaults/component.yaml'
testplan: '~/defaults/8.0.x.yaml,~/defaults/scheduled.yaml,~/twig-component.yaml'
runs_on: '"ubuntu-latest"'
defaults: 'v4'
plan_folder: '.github/oxid-esales'
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ jobs:
fi
# shellcheck disable=SC2088
case "${REF_TO_CHECK}" in
refs/heads/b-7.0.x*) TESTPLAN="~/defaults/7.0.x.yaml,${LIMIT70}~/twig-component.yaml,~/defaults/component.yaml" ;;
refs/heads/b-7.1.x*) TESTPLAN="~/defaults/7.1.x.yaml,${LIMIT}~/twig-component.yaml,~/defaults/component.yaml" ;;
refs/heads/b-7.2.x*) TESTPLAN="~/defaults/7.2.x.yaml,${LIMIT}~/twig-component.yaml,~/defaults/component.yaml" ;;
refs/heads/b-8.0.x*) TESTPLAN="~/defaults/8.0.x.yaml,${LIMIT}~/twig-component.yaml,~/defaults/component.yaml" ;;
refs/heads/b-7.0.x*) TESTPLAN="~/defaults/7.0.x.yaml,${LIMIT70}~/twig-component.yaml" ;;
refs/heads/b-7.1.x*) TESTPLAN="~/defaults/7.1.x.yaml,${LIMIT}~/twig-component.yaml" ;;
refs/heads/b-7.2.x*) TESTPLAN="~/defaults/7.2.x.yaml,${LIMIT}~/twig-component.yaml" ;;
refs/heads/b-8.0.x*) TESTPLAN="~/defaults/8.0.x.yaml,${LIMIT}~/twig-component.yaml" ;;
*)
echo "Can't match ${REF_TO_CHECK} to a version, can't determine test plan."
echo "Branch names should start with b-<major>.<minor>.x"
echo "Using the shop changelog to determine the shop version"
git clone --depth 2 "${{ github.repositoryUrl }}" --branch "${{ github.ref_name}}" --single-branch .tmp
if [ -f .tmp/CHANGELOG-3.x.md ]; then
TESTPLAN="~/defaults/8.0.x.yaml,${LIMIT}~/twig-component.yaml,~/defaults/component.yaml"
TESTPLAN="~/defaults/8.0.x.yaml,${LIMIT}~/twig-component.yaml"
elif [ -f .tmp/CHANGELOG-2.x.md ]; then
TESTPLAN="~/defaults/7.2.x.yaml,${LIMIT}~/twig-component.yaml,~/defaults/component.yaml"
TESTPLAN="~/defaults/7.2.x.yaml,${LIMIT}~/twig-component.yaml"
elif [ -f .tmp/CHANGELOG-2.x.md ]; then
TESTPLAN="~/defaults/7.1.x.yaml,${LIMIT}~/twig-component.yaml,~/defaults/component.yaml"
TESTPLAN="~/defaults/7.1.x.yaml,${LIMIT}~/twig-component.yaml"
elif [ -f .tmp/CHANGELOG.md ]; then
TESTPLAN="~/defaults/7.0.x.yaml,${LIMIT}~/twig-component.yaml,~/defaults/component.yaml"
TESTPLAN="~/defaults/7.0.x.yaml,${LIMIT}~/twig-component.yaml"
else
echo "Could not find any of CHANGELOG-8.0, CHANGELOG-7.2, CHANGELOG-71. or CHANGELOG-7.0"
echo "Still can't determine the test plan"
Expand Down
48 changes: 24 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"name": "oxid-esales/twig-component",
"description": "The component supports Twig template engine.",
"license": [
"proprietary"
],
"type": "oxideshop-component",
"keywords": [
"oxid",
"component",
"eShop"
],
"homepage": "https://www.oxid-esales.com",
"require": {
"php": ">=8.1",
"twig/twig": "3.8.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"OxidEsales\\Twig\\": "src",
"OxidEsales\\Twig\\Tests\\": "tests"
"name": "oxid-esales/twig-component",
"description": "The component supports Twig template engine.",
"license": [
"proprietary"
],
"type": "oxideshop-component",
"keywords": [
"oxid",
"component",
"eShop"
],
"homepage": "https://www.oxid-esales.com",
"require": {
"php": ">=8.0",
"twig/twig": "3.8.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"OxidEsales\\Twig\\": "src",
"OxidEsales\\Twig\\Tests\\": "tests"
}
}
}
}
}
64 changes: 62 additions & 2 deletions tests/scripts/integration.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,67 @@
#!/bin/bash
set -e
vendor/bin/phpunit \
-c phpunit.xml \
export XDEBUG_MODE=coverage
PHPUNIT="vendor/bin/phpunit"
if [ ! -f "${PHPUNIT}" ]; then
PHPUNIT="/var/www/${PHPUNIT}"
if [ ! -f "${PHPUNIT}" ]; then
echo -e "\033[0;31mCould not find phpunit in vendor/bin or /var/www/vendor/bin\033[0m"
exit 1
fi
fi
BOOTSTRAP="../../../tests/bootstrap.php"
if [ ! -f "${BOOTSTRAP}" ]; then
BOOTSTRAP="../oxideshop-ce/tests"
if [ ! -f "${BOOTSTRAP}" ]; then
echo -e "\033[0;31mCould not find bootstrap.php in ../../../tests or ../oxideshop-ce/tests\033[0m"
exit 1
fi
fi
"${PHPUNIT}" \
-c tests/phpunit.xml \
--bootstrap "${BOOTSTRAP}" \
--coverage-clover=tests/Reports/coverage_phpunit_integration.xml \
tests/Integration 2>&1 \
| tee tests/Output/integration_tests.txt
RESULT=$?
echo "phpunit exited with error code ${RESULT}"
if [ ! -s "tests/Output/integration_tests.txt" ]; then
echo -e "\033[0;31mLog file is empty! Seems like no tests have been run!\033[0m"
RESULT=1
fi
cat >failure_pattern.tmp <<EOF
fail
\\.\\=\\=
Warning
Notice
Deprecated
Fatal
Error
DID NOT FINISH
Test file ".+" not found
Cannot open file
No tests executed
Could not read
Warnings: [1-9][0-9]*
Errors: [1-9][0-9]*
Failed: [1-9][0-9]*
Deprecations: [1-9][0-9]*
Risky: [1-9][0-9]*
EOF
sed -e 's|(.*)\r|$1|' -i failure_pattern.tmp
while read -r LINE ; do
if [ -n "${LINE}" ]; then
if grep -q -E "${LINE}" "tests/Output/integration_tests.txt"; then
echo -e "\033[0;31m integration test failed matching pattern ${LINE}\033[0m"
grep -E "${LINE}" "tests/Output/integration_tests.txt"
RESULT=1
else
echo -e "\033[0;32m integration test passed matching pattern ${LINE}"
fi
fi
done <failure_pattern.tmp
if [[ ! -s "tests/Reports/coverage_phpunit_integration.xml" ]]; then
echo -e "\033[0;31m coverage report tests/Reports/coverage_phpunit_integration.xml is empty\033[0m"
RESULT=1
fi
exit ${RESULT}
65 changes: 63 additions & 2 deletions tests/scripts/unit.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,68 @@
#!/bin/bash
set -e
vendor/bin/phpunit \
-c phpunit.xml \
export XDEBUG_MODE=coverage
PHPUNIT="vendor/bin/phpunit"
if [ ! -f "${PHPUNIT}" ]; then
PHPUNIT="/var/www/${PHPUNIT}"
if [ ! -f "${PHPUNIT}" ]; then
echo -e "\033[0;31mCould not find phpunit in vendor/bin or /var/www/vendor/bin\033[0m"
exit 1
fi
fi
BOOTSTRAP="../../../tests/bootstrap.php"
if [ ! -f "${BOOTSTRAP}" ]; then
BOOTSTRAP="../oxideshop-ce/tests"
if [ ! -f "${BOOTSTRAP}" ]; then
echo -e "\033[0;31mCould not find bootstrap.php in ../../../tests or ../oxideshop-ce/tests\033[0m"
exit 1
fi
fi
"${PHPUNIT}" \
-c tests/phpunit.xml \
--bootstrap "${BOOTSTRAP}" \
--coverage-clover=tests/Reports/coverage_phpunit_unit.xml \
--log-junit tests/Reports/phpunit-unit.xml \
tests/Unit 2>&1 \
| tee tests/Output/unit_tests.txt
RESULT=$?
echo "phpunit exited with error code ${RESULT}"
if [ ! -s "tests/Output/unit_tests.txt" ]; then
echo -e "\033[0;31mLog file is empty! Seems like no tests have been run!\033[0m"
RESULT=1
fi
cat >failure_pattern.tmp <<EOF
fail
\\.\\=\\=
Warning
Notice
Deprecated
Fatal
Error
DID NOT FINISH
Test file ".+" not found
Cannot open file
No tests executed
Could not read
Warnings: [1-9][0-9]*
Errors: [1-9][0-9]*
Failed: [1-9][0-9]*
Deprecations: [1-9][0-9]*
Risky: [1-9][0-9]*
EOF
sed -e 's|(.*)\r|$1|' -i failure_pattern.tmp
while read -r LINE ; do
if [ -n "${LINE}" ]; then
if grep -q -E "${LINE}" "tests/Output/unit_tests.txt"; then
echo -e "\033[0;31m unit test failed matching pattern ${LINE}\033[0m"
grep -E "${LINE}" "tests/Output/unit_tests.txt"
RESULT=1
else
echo -e "\033[0;32m unit test passed matching pattern ${LINE}"
fi
fi
done <failure_pattern.tmp
if [[ ! -s "tests/Reports/coverage_phpunit_unit.xml" ]]; then
echo -e "\033[0;31m coverage report tests/Reports/coverage_phpunit_unit.xml is empty\033[0m"
RESULT=1
fi
exit ${RESULT}

0 comments on commit 8684c9c

Please sign in to comment.