Skip to content

Commit

Permalink
Merge pull request #1 from nopenopenope/adapt-structure-and-logics
Browse files Browse the repository at this point in the history
Adapt logic to support PHP8, run on docker, added tests and code style.
  • Loading branch information
bytes-commerce committed Aug 3, 2023
2 parents 292ddd4 + 027401f commit c4a4a5d
Show file tree
Hide file tree
Showing 96 changed files with 3,190 additions and 757 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/.github
/docs
/docker
/docker/data
/docker-compose.yml
!/docker/php/etc
!/docker/php/etc/*
/magento
/test_dir
2 changes: 2 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MAGENTO_PUBLIC_KEY=xxx
MAGENTO_SECRET_KEY=xxx
162 changes: 124 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,54 @@ on:
push:
branches:
- "master"
- "2.x"
- "3.x"

jobs:
behat:
name: "Acceptance Tests"

runs-on: "ubuntu-latest"
strategy:
matrix:
php-version:
- "8.1"
- "8.2"

env:
M2_INSTANCE_ROOT_DIR: ${{ github.workspace }}/magento

services:
mysql:
image: mariadb:10.4
image: mariadb:10.6
env:
MYSQL_USER: magento
MYSQL_PASSWORD: magento
MYSQL_DATABASE: magentodb
MYSQL_DATABASE: magento
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --tmpfs /tmp:rw --tmpfs /var/lib/mysql:rw --health-cmd="mysqladmin ping"

elasticsearch:
image: elasticsearch:7.12.1
env:
ES_JAVA_OPTS: -Xms512m -Xmx512m
discovery.type: single-node
opensearch:
image: opensearchproject/opensearch:2.7.0
ports:
- 9200:9200
env:
discovery.type: single-node
cluster.name: opensearch-cluster
node.name: opensearch-node
bootstrap.memory_lock: true
OPENSEARCH_JAVA_OPTS: -Xms512m -Xmx512m
DISABLE_INSTALL_DEMO_CONFIG: true
plugins.security.disabled: true
plugins.security.ssl.http.enabled: false
options: --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
with:
path: 'behat-magento2-extension'

steps:
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: none
php-version: 7.4
php-version: "${{ matrix.php-version }}"
extensions: bcmath, ctype, curl, dom, gd, hash, iconv, intl, mbstring, openssl, pdo_mysql, simplexml, soap, xsl, zip, sockets
ini-values: memory_limit=-1
tools: composer:v2, cs2pr
Expand All @@ -63,40 +68,121 @@ jobs:
path: |
~/.composer/cache
magento
key: "magento-2.4.2-with-php-7.4"
key: "magento-2.4.6-with-php-${{ matrix.php-version }}"

- name: "Create Magento 2.4.2 project with testing dependencies"
- name: "Create Magento 2.4.6 project"
run: |
composer create-project --repository=https://repo.magento.com/ magento/project-community-edition=2.4.2 magento
cd magento
composer require tkotosz/test-area-magento2
composer require --dev behat/behat friends-of-behat/mink-extension behat/mink-goutte-driver
cd -
composer create-project --no-progress --no-install --repository=https://repo.magento.com/ magento/project-community-edition=2.4.6 magento
if: hashFiles('magento/composer.json') == ''

- name: "Add testing dependencies"
run: |
composer config --no-plugins allow-plugins.magento/* true
composer config --no-plugins allow-plugins.php-http/discovery true
composer config --no-plugins allow-plugins.laminas/laminas-dependency-plugin true
composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer require --no-progress behat/behat tkotosz/test-area-magento2
composer install --no-progress
working-directory: 'magento'

- name: "Checkout"
uses: "actions/checkout@v2"
with:
path: 'magento/vendor/seec/behat-magento2-extension'

- name: "Install Magento"
run: |
rm -f app/etc/env.php
mkdir -p pub/static pub/media
bin/magento setup:install --admin-email "kotosy.magento@gmail.com" --admin-firstname "admin" --admin-lastname "admin" --admin-password "admin123" --admin-user "admin" --backend-frontname admin --base-url "http://magento.test" --db-host 127.0.0.1 --db-name magentodb --db-user magento --db-password magento --session-save files --use-rewrites 1 --use-secure 0 --search-engine=elasticsearch7 --elasticsearch-host=127.0.0.1 --elasticsearch-port=9200 -vvv
bin/magento setup:upgrade
composer require --dev behat/behat tkotosz/test-area-magento2
bin/magento setup:install \
--admin-email="magento@magento.com" \
--admin-firstname="admin" \
--admin-lastname="admin" \
--admin-password="admin123!#" \
--admin-user="admin" \
--backend-frontname="admin" \
--base-url="http://magento.test" \
--cleanup-database \
--db-host="127.0.0.1" \
--db-name="magento" \
--db-password="magento" \
--db-user="magento" \
--opensearch-host="127.0.0.1" \
--opensearch-port=9200 \
--search-engine="opensearch" \
--session-save="files" \
--skip-db-validation \
--timezone="Europe/Amsterdam" \
--use-rewrites=1 \
--use-secure-admin=0 \
--use-secure=0
bin/magento --quiet deploy:mode:set developer
bin/magento --quiet setup:upgrade
working-directory: 'magento'

- name: "Install Behat Magento 2 Extension in the Magento 2 Test Environment"
- name: "Install BehatMagento2 Extension"
run: |
composer config repositories.behat-m2-extension path ../behat-magento2-extension
composer require --dev bex/behat-magento2-extension:@dev
composer config minimum-stability dev
composer config repositories.behat-m2-extension path vendor/seec/behat-magento2-extension
composer require seec/behat-magento2-extension:@dev
working-directory: 'magento'

- name: "Install Behat Magento 2 Extension's testing dependencies"
run: |
composer install
working-directory: 'behat-magento2-extension'
- name: "Install BehatMagento2 Extension dependencies"
run: "composer install --no-interaction --no-progress --no-suggest"
working-directory: 'magento/vendor/seec/behat-magento2-extension'

- name: "Run phpstan for src/ and feature/"
run: "vendor/bin/phpstan analyse --error-format=checkstyle src/ features/ --level=8 | cs2pr"
working-directory: 'magento/vendor/seec/behat-magento2-extension'

- name: "Run phpstan for tests/"
run: "vendor/bin/phpstan analyse --error-format=checkstyle tests/ --level=6 | cs2pr"
working-directory: 'magento/vendor/seec/behat-magento2-extension'

- name: "Run Behat tests"
run: "vendor/bin/behat --stop-on-failure --config behat.yml.dist --tags=@virtual"
working-directory: 'magento/vendor/seec/behat-magento2-extension'

code-style:
name: "CodeStyle + UnitTests"
runs-on: "ubuntu-latest"
strategy:
matrix:
php-version:
- "8.1"
- "8.2"

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

- name: "Setup Composer Auth"
run: "echo $COMPOSER_AUTH_JSON > ~/.composer/auth.json"
env:
COMPOSER_AUTH_JSON: ${{ secrets.COMPOSER_AUTH_JSON }}

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: none
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
tools: composer:v2, cs2pr

- name: "Cache dependencies"
uses: "actions/cache@v2"
with:
path: |
~/.composer/cache
vendor
key: "php-${{ matrix.php-version }}"

- name: "Install dependencies"
run: "composer install --no-interaction --no-progress --no-suggest"

- name: "Run tests without compiled DI"
run: "bin/behat -swithout_compiled_di"
working-directory: 'behat-magento2-extension'
- name: "EasyCodingStandards for Src, Features and Tests"
run: "vendor/bin/ecs check src/ features/ tests/ --no-interaction --no-progress-bar"

- name: "Run tests with compiled DI"
run: "bin/behat -swith_compiled_di"
working-directory: 'behat-magento2-extension'
- name: "Run unit tests"
run: "vendor/bin/phpunit tests/"
18 changes: 9 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Composer packages directory
/vendor

# Composer executable files directory
/bin

# Installed Composer packages versions
/composer.lock

# documentation local build directory
docs/_build
/docs/_build
/.env
/behat.yml
/php_error.log
/.phpunit.result.cache
/.idea
/magento
/test_dir
/docker/data
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2019 Tibor Kotosz
Copyright (c) 2023 Maximilian Graf Schimmelmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
57 changes: 51 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,64 @@
BehatMagento2Extension
Behat Magento2 Extension
======================

[![License](https://poser.pugx.org/bex/behat-magento2-extension/license)](https://packagist.org/packages/bex/behat-magento2-extension)
[![Latest Stable Version](https://poser.pugx.org/bex/behat-magento2-extension/version)](https://packagist.org/packages/bex/behat-magento2-extension)
![Build Status](https://github.com/tkotosz/BehatMagento2Extension/actions/workflows/ci.yml/badge.svg)
[![License](https://poser.pugx.org/nopenopenope/behat-magento2-extension/license)](https://packagist.org/packages/nopenopenope/behat-magento2-extension)
[![Latest Stable Version](https://poser.pugx.org/nopenopenope/behat-magento2-extension/version)](https://packagist.org/packages/nopenopenope/behat-magento2-extension)
![Build Status](https://github.com/nopenopenope/BehatMagento2Extension/actions/workflows/ci.yml/badge.svg)

The `BehatMagento2Extension` provides a custom service container for Behat which allows to inject Magento services into Behat Contexts and Behat helper services.
This is a fork of the [BehatMagentoExtension](https://github.com/tkotosz/BehatMagento2Extension), which is
compatible with PHP8.1 and greater. This should ensure successful end-to-end testing of Magento 2 projects.

The `BehatMagento2Extension` provides a custom service container for Behat which allows to inject Magento services into
Behat Contexts and Behat helper services.

Installation
------------

The recommended installation method is through [Composer](https://getcomposer.org):

```bash
composer require --dev bex/behat-magento2-extension
composer require seec/behat-magento2-extension
```

Usage
-----

In order to bootstrap Magento2 into your Behat suite, some modifications to the used behat.yml are required.

**Note**: If you use the Hooks provided by this package, your Magento Database will be purged and refilled with your
fixtures after each individual test.
This adds extra time to the execution but leaves your database also with DUMMY data. Do *not* use the hooks if you want
to keep your database intact. Do *not* use it on a production server if you don't know what you are doing.


Testing
-------

If you want to contribute to this module, make sure to run tests locally before committing. Docker Compose Containers
are set-up to run all tests for all PHP versions automatically, so testing is very easy.

```bash
$ cp .env.dist .env // make sure to add your keys to the .env file otherwise testing will not work!
$ docker compose build
$ docker compose up -d
$ docker compose exec php sh
$ install-magento
$ install-extension
$ cd /var/www/html/vendor/seec/behat-magento2-extension
$ php vendor/bin/behat
```

Code Quality
------------

We aim for a unified code style; thus we enforce ECS and PHPStan onto our code. Make sure to run the following commands
before committing:

```bash
$ php vendor/bin/ecs check src/ tests/ features/ --fix
$ php vendor/bin/phpstan analyse src/ --level=8
$ php vendor/bin/phpstan analyse features/ --level=8
$ php vendor/bin/phpstan analyse tests/ --level=5
```

Documentation
Expand Down
9 changes: 0 additions & 9 deletions behat.yml

This file was deleted.

10 changes: 8 additions & 2 deletions behat.yml.dist
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
default:
extensions:
Bex\Behat\Magento2Extension: ~
formatters:
progress: true

suites:
default:
contexts:
- SEEC\Behat\Magento2Extension\Features\Bootstrap\Context\TestRunnerContext
- SEEC\BehatTestRunner\Context\TestRunnerContext
Loading

0 comments on commit c4a4a5d

Please sign in to comment.