Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/unit-tests-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: PHPUNIT-IMAGE

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
workflow_dispatch:
inputs:
name:
description: 'Person to greet'
required: true
default: 'Mona the Octocat'
home:
description: 'location'
required: false
default: 'The Octoverse'


env:
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: phpunit


jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
-
name: Checkout repository
uses: actions/checkout@v2

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
-
name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
-
name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
-
name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ./magento-unit-test/
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
17 changes: 17 additions & 0 deletions magento-database-anonimiser/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM php:7.4-cli-alpine
ENV PLATFORM 'magento2'
ENV DATABASE 'magento'
ENV USERNAME 'magento'
ENV PASSWORD 'magento'
ENV DB_HOST 'localost'
ENV PORT '3306'

RUN ash -c 'mkdir -p /anonymize/{database,prepared}'
RUN curl -L https://github.com/elgentos/masquerade/releases/latest/download/masquerade.phar -o /bin/masquerade
RUN chmod +x /bin/masquerade

RUN docker-php-ext-install pdo_mysql

ADD entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
24 changes: 24 additions & 0 deletions magento-database-anonimiser/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.9'
services:
database:
container_name: anon_mysql
image: mariadb:10.2.30
volumes:
- ./db/:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: magento
MYSQL_PASSWORD: magento
MYSQL_DATABASE: magento
anonimise:
container_name: anon_mask
image: eclipse-php:masquerade
build: .
volumes:
- ./db/:/anonymize/database
- ./entrypoint.sh:/entrypoint.sh
environment:
START: 'false'
USERNAME : 'root'
PASSWORD : 'root'
DB_HOST: 'database'
8 changes: 8 additions & 0 deletions magento-database-anonimiser/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh -l

DIR="/anonymize/database"

#if [[ "${START}" == "true" ]]; then
/bin/masquerade run --platform=$PLATFORM --database=$DATABASE --username=$USERNAME --password=$PASSWORD --host=$DB_HOST --port=$PORT
#fi

9 changes: 9 additions & 0 deletions magento-unit-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ghcr.io/eclipse-digital/magento-php-fpm:feature-php7.4-alpine-dev

COPY entrypoint.sh /entrypoint.sh
RUN chmod 755 /entrypoint.sh

COPY docker-files /docker-files

ENTRYPOINT ["ash", "/entrypoint.sh"]

71 changes: 71 additions & 0 deletions magento-unit-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Magento 2 Unit Tests
To use this action, create a YAML file `.github/workflows/example.yml` in your extension folder, based upon the following contents:
```yaml
name: ExtDN Actions
on: [push]
jobs:
unit-tests:
name: Magento 2 Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker://yireo/github-actions-magento-unit-tests:7.3
env:
MAGENTO_VERSION: '2.3.4'
MAGENTO_MARKETPLACE_USERNAME: ${{ secrets.MAGENTO_MARKETPLACE_USERNAME }}
MAGENTO_MARKETPLACE_PASSWORD: ${{ secrets.MAGENTO_MARKETPLACE_PASSWORD }}
MODULE_NAME: Foo_Bar
COMPOSER_NAME: foo/magento2-foobar
```

You can also run multiple combinations and reuse the same variables:

```yaml
name: ExtDN Actions
on: [push]
jobs:
unit-tests:
name: Magento 2 Unit Tests
runs-on: ubuntu-latest
env:
MAGENTO_MARKETPLACE_USERNAME: ${{ secrets.MAGENTO_MARKETPLACE_USERNAME }}
MAGENTO_MARKETPLACE_PASSWORD: ${{ secrets.MAGENTO_MARKETPLACE_PASSWORD }}
MODULE_NAME: Foo_Bar
COMPOSER_NAME: foo/magento2-foobar
steps:
- uses: actions/checkout@v2
- uses: docker://yireo/github-actions-magento-unit-tests:7.3
env:
MAGENTO_VERSION: '2.3.4'
- uses: docker://yireo/github-actions-magento-unit-tests:7.3
env:
MAGENTO_VERSION: '2.3.5-p2'
- uses: docker://yireo/github-actions-magento-unit-tests:7.4
env:
MAGENTO_VERSION: '2.4.0'
```

Make sure to modify the following values:
- `module_name` - for instance, `Foo` if your Magento 2 module is called `Foo_Bar`
- `composer_name` - for instance, `Bar` if your Magento 2 module is called `Foo_Bar`

You could also choose to switch PHP version, by changing the tag of the Docker image:

- uses: docker://yireo/github-actions-magento-unit-tests:7.4

Next, make sure to add the secrets `MAGENTO_MARKETPLACE_USERNAME` and `MAGENTO_MARKETPLACE_PASSWORD` to your GitHub repository under
**Settings > Secrets**. Tip: You could also use the secrets to define the module and composer name: This way your workflow file remains
generic.

### Maintenance of the Docker image
To use the `Dockerfile` of this package, a new image needs to be built and pushed to the Docker Hub:

docker build -t VENDOR/IMAGE .
docker push VENDOR/IMAGE

For instance with the vendor and image-name used in this package:

docker build -t yireo/github-actions-magento-unit-tests .
docker push yireo/github-actions-magento-unit-tests

The script `build-and-push.sh` is used for this purpose.
38 changes: 38 additions & 0 deletions magento-unit-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'Magento 2 unit tests'
author: 'Taurthil'
description: 'runs unit tests for given Magento 2 open source version and commerce'
inputs:
module_name:
description: 'Your Magento module name. Example: Foo_Bar'
required: true
composer_name:
description: 'Your composer name. Example: foo/bar'
required: true
php_version:
description: 'PHP version'
required: true
default: '7.4'
magento_version_type:
description: 'Magento OS || CE'
required: true
default: 'OS'
magento_version:
description: 'Magento 2 version number'
required: true
default: '2.4.2'
module_source:
description: 'Relative path to your module source within your repository. Empty by default.'
phpunit_file:
description: 'Relative path to your own PHPUnit file. Leave empty to use the default.'
magento_pre_install_script:
description: 'Relative path to an optional script before Magento installation is run. Leave empty to use the default.'
additional_repository:
description: 'Additional repository e.g. Satis'
required: true
default: 'false'
runs:
using: 'docker'
image: 'docker://mageviper/magento-unit-tests'
branding:
icon: 'code'
color: 'green'
7 changes: 7 additions & 0 deletions magento-unit-test/build-and-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
tag='7.4'

#for tag in 7.2 7.3 7.4; do
docker build -t mageviper/magento-unit-tests:$tag -f Dockerfile:$tag . --no-cache
# docker push mageviper/magento-unit-tests:$tag
#done
12 changes: 12 additions & 0 deletions magento-unit-test/composer/auth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"http-basic": {
"repo.magento.com": {
"username": "d2e6266bda3f5e3e7cbaf6a364f088cb",
"password": "183eed8a76893dd2c4e7b4cf201d7abc"
},
"composer.magento-dev01.aws.eclipsegroup.co.uk": {
"username": "dev",
"password": "ioKB0O1X8SWXcKr"
}
}
}
12 changes: 12 additions & 0 deletions magento-unit-test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.7'
services:
unit-test:
image: mageviper/magento-unit-tests:7.4
environment:
MARKETPLACE_LOGIN: d2e6266bda3f5e3e7cbaf6a364f088cb
MARKETPLACE_PASSWORD: 183eed8a76893dd2c4e7b4cf201d7abc
VENDOR_NAME: Eclipse
MODULE_NAME: Importer
MAGENTO_VERSION: '2.4.2'
MAGENTO_VERSION_TYPE: CE
SATIS: 'false'
36 changes: 36 additions & 0 deletions magento-unit-test/docker-files/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="./framework/bootstrap.php"
stderr="true"
>
<testsuites>
<testsuite name="UnitTests">
<directory suffix="Test.php">../../../app/code/%COMPOSER_NAME%/Test/Unit</directory>
<directory suffix="Test.php">../../../vendor/%COMPOSER_NAME%/Test/Unit</directory>
<directory suffix="Test.php">../../../vendor/%COMPOSER_NAME%/Test/Unit</directory>
<directory suffix="Test.php">../../../vendor/%COMPOSER_NAME%/tests/Unit</directory>
<directory suffix="Test.php">../../../vendor/%COMPOSER_NAME%/tests/unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhiteList="true">
<directory suffix=".php">../../../app/code/*</directory>
<exclude>
<!-- Exclude files from code coverage -->
<directory>../../../app/code/*/*/Test</directory>
<directory suffix=".phtml">../../../app/code/*</directory>
<directory suffix=".php">../../../app/code/*/*/Setup/*</directory>
<directory suffix="registration.php">../../../app/code/*</directory>
<directory suffix="ConfigProvider.php">../../../app/code/*</directory>
<directory suffix="Enum.php">../../../app/code/*</directory>
</exclude>
</whitelist>
</filter>
<php>
<ini name="date.timezone" value="America/Los_Angeles"/>
<ini name="xdebug.max_nesting_level" value="200"/>
</php>
</phpunit>
60 changes: 60 additions & 0 deletions magento-unit-test/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/ash
#setted values
set -e
test -z "${CE_VERSION}" || MAGENTO_VERSION=$CE_VERSION
test -z "${MODULE_DIR}" && MODULE_DIR=$INPUT_MODULE_DIR
test -z "${SATIS}" && SATIS=$INPUT_SATIS
test -z "${MARKETPLACE_LOGIN}" && (echo "'MARKETPLACE_LOGIN' is not set" && exit 1)
test -z "${MARKETPLACE_PASSWORD}" && (echo "'MARKETPLACE_PASSWORD' is not set" && exit 1)
test -z "${MODULE_NAME}" && (echo "'MODULE_NAME' is not set" && exit 1)
test -z "${VENDOR_NAME}" && (echo "'VENDOR_NAME' is not set" && exit 1)
test -z "${MAGENTO_VERSION}" && (echo "'MAGENTO_VERSION' is not set" && exit 1)
test -z "${MAGENTO_VERSION_TYPE}" && (echo "'MAGENTO_VERSION_TYPE' is not set" && exit 1)

if [[ "${PRIVATE_PACKEGIST}" == "true" ]] ; then
test -z "${PRIVATE_REPO}" && (echo "'PRIVATE_REPO' is not set" && exit 1)
test -z "${PRIVATE_LOGIN}" && (echo "'PRIVATE_LOGIN' is not set" && exit 1)
test -z "${PRIVATE_PASSWORD}" && (echo "'PRIVATE_PASSWORD' is not set" && exit 1)
fi
#Script const
MG_REPOSITORY_URL='https://repo.magento.com/'
PROJECT_PATH=$GITHUB_WORKSPACE

composer global config http-basic.repo.magento.com $MARKETPLACE_LOGIN $MARKETPLACE_PASSWORD

if [[ "${PRIVATE_PACKEGIST}" == "true" ]] ; then
composer global config http-basic.PRIVATE_REPO $PRIVATE_LOGIN $PRIVATE_PASSWORD
fi

#Logic
echo 'Prepare magento composer project'
if [[ "${MAGENTO_VERSION_TYPE}" == "CE" ]] ; then
composer create-project \
--repository=$MG_REPOSITORY_URL \
magento/project-enterprise-edition=${MAGENTO_VERSION} \
$WEB_DIR --no-install --no-interaction --no-progress
else
composer create-project \
--repository=$MG_REPOSITORY_URL \
magento/project-community-edition=${MAGENTO_VERSION} \
$WEB_DIR --no-install --no-interaction --no-progress
fi

echo "Run installation"
cd $WEB_DIR
COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-dist --no-interaction --no-progress --no-suggest

echo 'Prepare module'
mkdir -p $WEB_DIR/app/code/$VENDOR_NAME/$MODULE_NAME
cd $WEB_DIR/app/code/$VENDOR_NAME/
cp -R ${GITHUB_WORKSPACE}/${MODULE_SOURCE}* $MODULE_NAME

echo 'Prepare unit config'
cp /docker-files/phpunit.xml $WEB_DIR/dev/tests/unit/phpunit.xml

echo "Run the unit tests"
php $WEB_DIR/vendor/phpunit/phpunit/phpunit \
-c $WEB_DIR/dev/tests/unit/phpunit.xml \
--colors=always \
$WEB_DIR/app/code/$VENDOR_NAME/$MODULE_NAME/Test/Unit/

2 changes: 1 addition & 1 deletion magento-unit-tests/Dockerfile:7.3
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM php:7.3

COPY --from=composer:1 /usr/bin/composer /usr/local/bin/composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

RUN apt-get update && apt-get -y install \
mariadb-client \
Expand Down
Loading