Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k3lm committed Feb 6, 2024
1 parent 0bbfff8 commit 1c26ce1
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 69 deletions.
139 changes: 70 additions & 69 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,33 @@ jobs:
### Download our code in custom dir###
- uses: actions/checkout@v3
with:
path: magento/app/code/Sequra/Core
path: magento/vendor/sequra/magento2-core

- uses: "shivammathur/setup-php@v2"
with:
php-version: "8.2"

- name: 'Unit test'
working-directory: magento/app/code/Sequra/Core
env:
COMPOSER_AUTH: ${{ steps.composer_auth.outputs.auth }}
run: |
../../../../vendor/bin/composer install
PAT="s/\/REAL-PATH-TO-MAGENTO-ROOT/..\/..\/..\/../g"
sed -e $PAT Test/autoload_sample.php > Test/autoload.php
../../../../vendor/bin/phpunit -c Test/phpunit.xml Test/Unit
# - name: 'launch magento2 unit test'
# if: always()
# uses: MAD-I-T/magento-actions@v3.25
# - name: 'Unit test'
# working-directory: magento/app/code/Sequra/Core
# env:
# COMPOSER_AUTH: ${{ steps.composer_auth.outputs.auth }}
# with:
# process: 'unit-test'
# unit_test_subset_path: 'vendor/sequra/magento2-core/Test/Unit'
# override_settings: 1
# magento_version: ${{ matrix.magento_version }}
# run: |
# ../../../../vendor/bin/composer install
# PAT="s/\/REAL-PATH-TO-MAGENTO-ROOT/..\/..\/..\/../g"
# sed -e $PAT Test/autoload_sample.php > Test/autoload.php
# ../../../../vendor/bin/phpunit -c Test/phpunit.xml Test/Unit

- name: 'launch magento2 unit test'
if: always()
uses: MAD-I-T/magento-actions@v3.25
env:
COMPOSER_AUTH: ${{ steps.composer_auth.outputs.auth }}
with:
process: 'unit-test'
unit_test_subset_path: 'vendor/sequra/magento2-core/Test/Unit'
unit_test_config: 'vendor/sequra/magento2-core/Test/Unit/phpunit.xml.dist'
override_settings: 1
magento_version: ${{ matrix.magento_version }}

# Integrations tests
- name: "Run Integration tests"
Expand All @@ -96,60 +97,60 @@ jobs:
process: 'integration-test'
unit_test_subset_path: "Sequra_Core Integration Tests"

magento2-checks:
runs-on: ubuntu-latest
container: ubuntu
name: 'm2 Standards, MD and PHPStan'
strategy:
matrix:
magento_version: [2.4.6]
steps:
### Download our code in custom dir###
- uses: actions/checkout@v3
with:
path: Sequra_Core
# magento2-checks:
# runs-on: ubuntu-latest
# container: ubuntu
# name: 'm2 Standards, MD and PHPStan'
# strategy:
# matrix:
# magento_version: [2.4.6]
# steps:
# ### Download our code in custom dir###
# - uses: actions/checkout@v3
# with:
# path: Sequra_Core

- name: 'install fresh magento repo'
uses: MAD-I-T/magento-actions@v3.25
env:
COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
with:
process: 'install-magento'
magento_version: ${{ matrix.magento_version }}
no_push: 1 ## add this arg to not push to the repo ideal for quick test on specific version
# - name: 'install fresh magento repo'
# uses: MAD-I-T/magento-actions@v3.25
# env:
# COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
# with:
# process: 'install-magento'
# magento_version: ${{ matrix.magento_version }}
# no_push: 1 ## add this arg to not push to the repo ideal for quick test on specific version

- uses: "shivammathur/setup-php@v2"
with:
php-version: "8.2"
- name: 'unit test'
run: |
cd Sequra_Core
../magento/vendor/bin/composer install
PAT="s/\/REAL-PATH-TO-MAGENTO-ROOT/..\/magento/g"
sed -e $PAT Test/autoload_sample.php > Test/autoload.php
../magento/vendor/bin/phpunit -c Test/phpunit.xml Test/Unit
# - uses: "shivammathur/setup-php@v2"
# with:
# php-version: "8.2"
# - name: 'unit test'
# run: |
# cd Sequra_Core
# ../magento/vendor/bin/composer install
# PAT="s/\/REAL-PATH-TO-MAGENTO-ROOT/..\/magento/g"
# sed -e $PAT Test/autoload_sample.php > Test/autoload.php
# ../magento/vendor/bin/phpunit -c Test/phpunit.xml Test/Unit

- name: 'phpstan'
if: always()
uses: MAD-I-T/magento-actions@v3.25
with:
process: 'phpstan'
exec_path: '../Sequra_Core'
# - name: 'phpstan'
# if: always()
# uses: MAD-I-T/magento-actions@v3.25
# with:
# process: 'phpstan'
# exec_path: '../Sequra_Core'

- name: 'mess detector'
if: always()
uses: MAD-I-T/magento-actions@v3.25
with:
process: 'mess-detector'
md_src_path: '../Sequra_Core'
# - name: 'mess detector'
# if: always()
# uses: MAD-I-T/magento-actions@v3.25
# with:
# process: 'mess-detector'
# md_src_path: '../Sequra_Core'

- name: 'Magento coding standard checking'
if: always()
uses: MAD-I-T/magento-actions@v3.25
with:
process: 'phpcs-test'
extension: 'Sequra_Core'
severity: 10
standard: 'Magento2'
# - name: 'Magento coding standard checking'
# if: always()
# uses: MAD-I-T/magento-actions@v3.25
# with:
# process: 'phpcs-test'
# extension: 'Sequra_Core'
# severity: 10
# standard: 'Magento2'


20 changes: 20 additions & 0 deletions Test/Unit/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
use Magento\Framework\App\Bootstrap;
use Magento\Framework\App\Cron;
// Load Composer's autoloader
require_once __DIR__ . '/../../../../autoload.php';

// Register namespaces for autoloading
$loader = new \Composer\Autoload\ClassLoader();

// Add namespaces from your module's composer.json file
$loader->addPsr4('SeQura\\Core\\Tests\\Infrastructure\\', __DIR__ . '/../../vendor/sequra/integration-core/tests/Infrastructure');
$loader->addPsr4('SeQura\\Core\\Tests\\BusinessLogic\\', __DIR__ . '/../../vendor/sequra/integration-core/tests/BusinessLogic');

// Register the loader
$loader->register();

require __DIR__ . '/../../../../../app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);
$bootstrap->createApplication(Cron::class);
8 changes: 8 additions & 0 deletions Test/Unit/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./bootstrap.php" colors="true">
<testsuites>
<testsuite name="Sequra Magento 2 Core Test Suite">
<directory>./</directory>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit 1c26ce1

Please sign in to comment.