Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhpUnit: use database for tests, added tests #4138

Merged
merged 95 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
3d7eaf6
Rector: CQ - UnusedForeachValueToArrayKeysRector (#1)
sreichel Jul 22, 2024
53ee2f8
Merge branch 'OpenMage:main' into main
sreichel Jul 24, 2024
89cc37c
Merge branch 'OpenMage:main' into main
sreichel Jul 24, 2024
e939180
Merge branch 'OpenMage:main' into main
sreichel Jul 31, 2024
35c91ef
Merge branch 'OpenMage:main' into main
sreichel Jul 31, 2024
abb5279
Updated test
sreichel Aug 2, 2024
6aac86b
Added test
sreichel Aug 2, 2024
09ee18a
Added test
sreichel Aug 2, 2024
40559cf
Renamed and updated test
sreichel Aug 2, 2024
18f1903
Updated test
sreichel Aug 2, 2024
cf4340d
Updated test
sreichel Aug 2, 2024
656044b
Updated test
sreichel Aug 2, 2024
b9630c1
Updated test
sreichel Aug 2, 2024
6f0b4b7
Revert "Rector: CQ - UnusedForeachValueToArrayKeysRector (#1)"
sreichel Aug 2, 2024
aa92e88
Updated test (phpstan L9)
sreichel Aug 2, 2024
f9e7b6f
Updated test (fixed namespace)
sreichel Aug 2, 2024
671107f
Updated test (phpstan L9)
sreichel Aug 2, 2024
475b8d4
Added unit test to code style check and phpstan
sreichel Aug 2, 2024
6d45ed6
Some cleanup
sreichel Aug 2, 2024
7f91768
Some cleanup
sreichel Aug 2, 2024
25d70a0
Some cleanup
sreichel Aug 2, 2024
57bd2a4
Updated workflow
sreichel Aug 2, 2024
2509777
ddev shortcut [ski ci]
sreichel Aug 3, 2024
4242f3a
Moved phphunit config file
sreichel Aug 3, 2024
aa26cca
Merged phpunit & sonar workflow
sreichel Aug 3, 2024
f4935f1
PhpUnit fix
sreichel Aug 4, 2024
dee0422
Fix linefeed (?)
sreichel Aug 4, 2024
47f6cae
Fix config
sreichel Aug 4, 2024
3df607b
Fixed invalid php version
sreichel Aug 4, 2024
0033475
Use minimum version
sreichel Aug 4, 2024
b19c11f
Use minimum version for SonarScan
sreichel Aug 4, 2024
e60b5c8
Fix command [ski ci]
sreichel Aug 4, 2024
bf03ca8
Enable xdebug
sreichel Aug 4, 2024
154229e
Added test, ref #4123
sreichel Aug 5, 2024
ed786cf
Merge branch 'main' into unit-tests
sreichel Aug 5, 2024
67a20fa
Revert "Some cleanup"
sreichel Aug 5, 2024
a0e5f9d
Revert "PhpUnit fix"
sreichel Aug 5, 2024
85bb579
Updated test
sreichel Aug 5, 2024
3e59b09
Updated docblocks
sreichel Aug 5, 2024
6238847
Revert "Fix linefeed (?)"
sreichel Aug 6, 2024
d9ec2c4
Merge branch 'main' into unit-tests
kiatng Aug 9, 2024
0965de1
Added tests
sreichel Aug 20, 2024
98366f5
Added tests
sreichel Aug 21, 2024
0100b36
Added tests [skip ci]
sreichel Aug 21, 2024
5c2b8a7
Merge branch 'main' into unit-tests
sreichel Aug 22, 2024
e55c6f3
Reverted changes to Mage_Core_Model_Website
sreichel Aug 24, 2024
6deb92f
Merge branch 'main' into unit-tests
sreichel Aug 24, 2024
4cd3c64
Updated config
sreichel Aug 28, 2024
cc5b55a
Updated .gitignore
sreichel Aug 28, 2024
47dda7a
Updated workflow
sreichel Aug 28, 2024
9f3010e
Merge branch 'main' into unit-tests
sreichel Aug 28, 2024
77a14b9
Updated workflow typo
sreichel Aug 28, 2024
a52e67f
Updated workflow continue on error
sreichel Aug 28, 2024
2f6592b
Updated workflow if condition
sreichel Aug 28, 2024
9d9c582
Updated workflow [skip ci]
sreichel Aug 28, 2024
7c7f930
Moved tests to root (as common)
sreichel Aug 28, 2024
e439e28
Fixed paths
sreichel Aug 28, 2024
7f46713
Fixed paths
sreichel Aug 28, 2024
78b2a0d
Fixed paths
sreichel Aug 28, 2024
f80be8e
CS fix
sreichel Aug 29, 2024
2dc091a
Added test
sreichel Aug 29, 2024
433b537
Added test
sreichel Aug 29, 2024
f31b912
Merge branch 'main' into unit-tests
kiatng Aug 30, 2024
9448e58
Added groups/suites
sreichel Sep 2, 2024
0c362c6
Updated test
sreichel Sep 2, 2024
a6ffaca
CS fix
sreichel Sep 2, 2024
cda06c7
Merge branch 'main' into unit-tests
sreichel Sep 2, 2024
0f0626b
Merge branch 'main' into unit-tests
sreichel Sep 3, 2024
6f05fc9
Updated .gitignore
sreichel Sep 4, 2024
e229c16
Updated phpunit.xml.dist
sreichel Sep 4, 2024
3eb7b19
Added test
sreichel Sep 4, 2024
e0e3cba
Added tests
sreichel Sep 4, 2024
a44184c
Added tests
sreichel Sep 4, 2024
2b00b85
Added tests
sreichel Sep 4, 2024
dbd6ff8
Added tests
sreichel Sep 4, 2024
d66894c
Merge remote-tracking branch 'origin/unit-tests' into unit-tests
sreichel Sep 4, 2024
453d168
Merge branch 'main' into unit-tests
sreichel Sep 4, 2024
0744d25
CS fix
sreichel Sep 4, 2024
dbe197b
CS fix
sreichel Sep 4, 2024
32eeee8
Added tests
sreichel Sep 4, 2024
63951f8
Added tests
sreichel Sep 4, 2024
7f8208b
Added tests
sreichel Sep 4, 2024
75e548a
Added tests
sreichel Sep 4, 2024
ba8108a
CS/PhpStan fixes
sreichel Sep 4, 2024
b0819e5
Update
sreichel Sep 4, 2024
59e38ea
Nicer output?
sreichel Sep 4, 2024
5a2d48a
Don't wait for phpcs
sreichel Sep 4, 2024
19354fb
Revert output
sreichel Sep 4, 2024
48221e0
Merge branch 'main' into unit-tests
sreichel Sep 6, 2024
e91a8d5
Merge branch 'main' into unit-tests
sreichel Sep 9, 2024
e814547
Updated workflows
sreichel Sep 9, 2024
c1a1b5f
Added test
sreichel Sep 9, 2024
737c5bc
Added phpunit command to composer.json
sreichel Sep 9, 2024
d9bb9af
Updated DDEV commands
sreichel Sep 9, 2024
ca7c803
Updated composer scripts
sreichel Sep 10, 2024
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
7 changes: 7 additions & 0 deletions .ddev/commands/web/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

## Description: run PHPUnit
## Usage: phpunit
## Example: ddev phpunit

php vendor/bin/phpunit --no-coverage "$@" --testdox
9 changes: 9 additions & 0 deletions .ddev/commands/web/phpunit-coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

## Description: run PHPUnit with coverage
## Usage: phpunit-coverage
## Example: ddev phpunit-coverage

enable_xdebug
XDEBUG_MODE=coverage php vendor/bin/phpunit --testdox
disable_xdebug
9 changes: 9 additions & 0 deletions .ddev/commands/web/phpunit-coverage-local
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

## Description: run PHPUnit with local HTML coverage
## Usage: phpunit-coverage-local
## Example: ddev phpunit-coverage-local

enable_xdebug
XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-html build/coverage --testdox
disable_xdebug
5 changes: 2 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
/.phpcs.php.xml.dist export-ignore
/.phpcs.xml.dist export-ignore
/.phpmd.dist.xml export-ignore
/phpstan.dist.baseline.neon export-ignore
/phpstan.dist.issues.neon export-ignore
/phpstan.dist.neon export-ignore
/.phpstan.dist.baseline.neon export-ignore
/.phpstan.dist.neon export-ignore

/README.md export-ignore

Expand Down
21 changes: 4 additions & 17 deletions .github/workflows/check-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ on:
phpunit:
description: "Count changed PhpUnit files"
value: ${{ jobs.check.outputs.phpunit }}
sonar:
description: "Count changed Sonar files"
value: ${{ jobs.check.outputs.sonar }}
# Allow manually triggering the workflow.
workflow_dispatch:

Expand All @@ -54,7 +51,6 @@ jobs:
phpstan: ${{ steps.changes-phpstan.outputs.phpstan }}
phpunit-test: ${{ steps.changes-phpunit-test.outputs.phpunit-test }}
phpunit: ${{ steps.changes-phpunit.outputs.phpunit }}
sonar: ${{ steps.changes-sonar.outputs.sonar }}

steps:
- name: Checkout code
Expand Down Expand Up @@ -87,9 +83,8 @@ jobs:
**phpcs**
**php-cs-fixer**
**phpstan**
dev/tests/
dev/phpunit*
dev/sonar*
tests/
phpunit*

- name: Check if composer files changed
id: changes-composer
Expand Down Expand Up @@ -161,22 +156,14 @@ jobs:
id: changes-phpunit-test
if: steps.changed-files-specific.outputs.any_modified == 'true'
run: |
count="$(grep -oE "dev/tests/" <<< "${{ steps.changed-files-specific.outputs.all_modified_files }}" | wc -l)"
count="$(grep -oE "tests/" <<< "${{ steps.changed-files-specific.outputs.all_modified_files }}" | wc -l)"
echo "$count UnitTest test file(s) changed"
echo "phpunit-test=$count" >> $GITHUB_OUTPUT

- name: Check if PHPUnit files changed
id: changes-phpunit
if: steps.changed-files-specific.outputs.any_modified == 'true'
run: |
count="$(grep -oE "dev/phpunit*" <<< "${{ steps.changed-files-specific.outputs.all_modified_files }}" | wc -l)"
count="$(grep -oE "phpunit*" <<< "${{ steps.changed-files-specific.outputs.all_modified_files }}" | wc -l)"
echo "$count PHPUnit file(s) changed"
echo "phpunit=$count" >> $GITHUB_OUTPUT

- name: Check if Sonar files changed
id: changes-sonar
if: steps.changed-files-specific.outputs.any_modified == 'true'
run: |
count="$(grep -oE "dev/sonar*" <<< "${{ steps.changed-files-specific.outputs.all_modified_files }}" | wc -l)"
echo "$count Sonar file(s) changed"
echo "sonar=$count" >> $GITHUB_OUTPUT
100 changes: 80 additions & 20 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,39 @@ on:

jobs:
unit-tests:
runs-on: [ubuntu-latest]
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4', '8.3']
mysql-version: ['5.7', '8.0']

services:
mysql:
image: mysql:${{ matrix.mysql-version }}
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: db
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v4
- name: Validate mysql service
run: |
echo "Checking mysql service"
sudo apt-get install -y mysql-client
mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -uroot -proot -e "SHOW DATABASES"

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
repository: OpenMage/Testfield
path: ./
php-version: ${{ matrix.php-versions }}
coverage: pcov #optional, setup coverage driver
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Validate composer
run: composer validate
- uses: actions/checkout@v4

- name: Get composer cache directory
id: composer-cache
Expand All @@ -33,24 +56,61 @@ jobs:
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-reqs

- name: Checkout OpenMage repo
uses: actions/checkout@v4
with:
path: openmage
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*

- name: Install OpenMage dependencies
working-directory: ./openmage
run: composer install --prefer-dist --no-progress --ignore-platform-reqs --no-dev
- name: Install OpenMage
run: |
php -f install.php -- \
--license_agreement_accepted 'yes' \
--locale 'en_US' \
--timezone 'America/New_York' \
--db_host '127.0.0.1' \
--db_name 'db' \
--db_user 'root' \
--db_pass 'root' \
--db_prefix '' \
--url 'http://openmage.local' \
--use_rewrites 'yes' \
--use_secure 'yes' \
--secure_base_url 'http://openmage.local' \
--use_secure_admin 'yes' \
--admin_username 'admin' \
--admin_lastname 'Administrator' \
--admin_firstname 'OpenMage' \
--admin_email '[email protected]' \
--admin_password 'veryl0ngpassw0rd' \
--session_save 'files' \
--admin_frontname 'admin' \
--backend_frontname 'admin' \
--default_currency 'USD' \
--enable_charts 'yes' \
--skip_url_validation 'yes'

- name: run phpUnit
run: bash ./run_unit_tests.sh
- name: Run phpUnit
run: php -f vendor/bin/phpunit

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2.7
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
files: output/*.xml
files: tests/logging/*.xml

- name: prepare SonarCloud Scan Data
if: ${{ (matrix.php-versions == '7.4') && (matrix.mysql-version == '5.7') }}
run: |
head tests/coverage/clover.xml
sed -i 's@'$GITHUB_WORKSPACE'/@/github/workspace/@g' tests/logging/junit.xml
sed -i 's@'$GITHUB_WORKSPACE'/@/github/workspace/@g' tests/coverage/clover.xml
head ./tests/coverage/clover.xml

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
continue-on-error: true
if: ${{ (matrix.php-versions == '7.4') && (matrix.mysql-version == '5.7') }} && SONAR_TOKEN
with:
args: >
-Dproject.settings=tests/sonar-project.properties
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
71 changes: 0 additions & 71 deletions .github/workflows/sonar.yml

This file was deleted.

21 changes: 5 additions & 16 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ jobs:
uses: ./.github/workflows/phpstan.yml

# DOES NOT run by default
# runs on schedule or when worklfow changed
# runs on schedule or when workflow changed
syntax_php:
name: PHP Syntax
needs: [check, phpcs, php-cs-fixer]
needs: [check, php-cs-fixer]
if: needs.check.outputs.workflow > 0
uses: ./.github/workflows/syntax-php.yml

Expand All @@ -107,23 +107,12 @@ jobs:
uses: ./.github/workflows/syntax-xml.yml

# DOES NOT run by default
# runs on schedule or when worklfow or unit tests changed
sonar:
name: Unit Tests (Sonar)
needs: [check, phpcs, php-cs-fixer]
if: |
needs.check.outputs.phpunit-test > 0 ||
needs.check.outputs.phpunit > 0 ||
needs.check.outputs.sonar > 0 ||
needs.check.outputs.workflow > 0
uses: ./.github/workflows/sonar.yml

# DOES NOT run by default
# runs on schedule or when worklfow or unit tests changed
# runs on schedule or when workflow or unit tests changed
unit_tests:
name: Unit Tests (OpenMage)
needs: [check, sonar]
needs: [check, php-cs-fixer]
if: |
needs.check.outputs.php > 0 ||
needs.check.outputs.phpunit-test > 0 ||
needs.check.outputs.phpunit > 0 ||
needs.check.outputs.workflow > 0
Expand Down
17 changes: 10 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
/app/etc/modules/Cm_RedisSession.xml
/lib/Credis

# Add a base setup for running unit Tests with code coverage and send them to SonarCloud
# https://github.com/OpenMage/magento-lts/pull/1836
/dev/testfield
/dev/tests/clover.xml
/dev/tests/crap4j.xml
/dev/tests/junit.xml

# Add Gitpod online IDE config
# https://github.com/OpenMage/magento-lts/pull/1836
/dev/gitpod/docker-magento
Expand Down Expand Up @@ -76,6 +69,16 @@ phpstan*.neon
!.phpstan.dist.neon
!.phpstan.dist.*.neon

# PhpUnit
tests/coverage
tests/logging
.phpunit.result.cache
phpunit.xml
!phpunit.xml.dist

# build
/build

# dev scripts loaded via composer
/shell/update-copyright.php
/shell/translations.php
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
'lib/Magento/',
'lib/Varien/',
'shell/',
'tests/unit/',
])
->name('*.php')
->ignoreDotFiles(true)
Expand Down
1 change: 1 addition & 0 deletions .phpcs.php.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<file>lib/Magento/</file>
<file>lib/Varien/</file>
<file>shell/</file>
<file>tests/unit/</file>
<rule ref="PHPCompatibility" />
<rule ref="PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore">
<exclude-pattern>*/Varien/Object.php*</exclude-pattern>
Expand Down
1 change: 1 addition & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<file>lib/Magento/</file>
<file>lib/Varien/</file>
<file>shell/</file>
<file>tests/unit/</file>
<!-- file contains include/include_once/... -->
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<!-- controllers -->
Expand Down
1 change: 1 addition & 0 deletions .phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ parameters:
- lib/Magento
- lib/Varien
- shell
- tests/unit
excludePaths:
#incompatible interfaces
- app/code/core/Mage/Admin/Model/Acl/Assert/Ip.php
Expand Down
Loading