Skip to content

Commit 06114a9

Browse files
committed
chore: Refactor PHPUnit configuration and enhance test bootstrap
1 parent 7c6dc46 commit 06114a9

6 files changed

Lines changed: 168 additions & 12 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Desktop (please complete the following information):**
27+
- OS: [e.g. iOS]
28+
- Browser [e.g. chrome, safari]
29+
- Version [e.g. 22]
30+
31+
**Smartphone (please complete the following information):**
32+
- Device: [e.g. iPhone6]
33+
- OS: [e.g. iOS8.1]
34+
- Browser [e.g. stock browser, safari]
35+
- Version [e.g. 22]
36+
37+
**Additional context**
38+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.github/workflows/cs.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Coding Standards
2+
3+
on:
4+
# Run on all pushes and on all pull requests.
5+
# Prevent the build from running when there are only irrelevant changes.
6+
push:
7+
paths-ignore:
8+
- '**.md'
9+
- '**.txt'
10+
pull_request:
11+
paths-ignore:
12+
- '**.md'
13+
- '**.txt'
14+
# Allow manually triggering the workflow.
15+
workflow_dispatch:
16+
17+
jobs:
18+
checkcs:
19+
name: 'PHPCS check'
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Install PHP
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: '8.0'
30+
tools: cs2pr
31+
coverage: none
32+
33+
# Install dependencies and handle caching in one go.
34+
# @link https://github.com/marketplace/actions/install-composer-dependencies
35+
- name: Install Composer dependencies
36+
uses: "ramsey/composer-install@v3"
37+
38+
# Check the code-style consistency of the PHP files.
39+
- name: Check PHP code style
40+
continue-on-error: true
41+
run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml
42+
43+
- name: Show PHPCS results in PR
44+
run: cs2pr --graceful-warnings ./phpcs-report.xml

.github/workflows/phpcompat.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: PHP Compatibility
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- '**.md'
7+
- '**.txt'
8+
pull_request:
9+
paths-ignore:
10+
- '**.md'
11+
- '**.txt'
12+
workflow_dispatch: {}
13+
14+
jobs:
15+
phpcompat:
16+
name: 'PHP Compatibility Check'
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Install PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: '8.0'
27+
coverage: none
28+
29+
# Create isolated environment for PHPCompatibility with PHPCS 4.x
30+
- name: Setup PHPCompatibility
31+
run: |
32+
mkdir phpcompat-tools
33+
cd phpcompat-tools
34+
composer init --name="temp/phpcompat" --type=project --no-interaction
35+
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
36+
composer require --dev \
37+
squizlabs/php_codesniffer:"^4.0" \
38+
phpcompatibility/php-compatibility:"dev-develop" \
39+
dealerdirect/phpcodesniffer-composer-installer:"^1.0" \
40+
--no-interaction
41+
42+
# Check PHP 7.4 through 8.5 compatibility
43+
- name: Check PHP Compatibility (7.4-8.5)
44+
run: |
45+
cd phpcompat-tools
46+
./vendor/bin/phpcs -p \
47+
--standard=PHPCompatibility \
48+
--runtime-set testVersion 7.4-8.5 \
49+
--extensions=php \
50+
--ignore=*/vendor/*,*/node_modules/*,*/tests/*,*/phpunit/*,*/freemius/* \
51+
../ || exit_code=$?
52+
53+
# Exit with the phpcs exit code (if set)
54+
exit ${exit_code:-0}

phpunit.xml.dist

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
5-
bootstrap="phpunit/bootstrap.php"
6-
backupGlobals="false"
7-
colors="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd" bootstrap="phpunit/bootstrap.php" backupGlobals="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true">
123
<testsuites>
134
<testsuite name="default">
145
<directory suffix=".php">phpunit/tests/</directory>
@@ -17,7 +8,13 @@
178

189
<filter>
1910
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="false">
20-
<directory>./src/</directory>
11+
<directory>./</directory>
12+
<exclude>
13+
<directory>./vendor/</directory>
14+
<directory>./node_modules/</directory>
15+
<directory>./phpunit/</directory>
16+
<directory>./build/</directory>
17+
</exclude>
2118
</whitelist>
2219
</filter>
2320
</phpunit>

phpunit/bootstrap.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
require_once $_tests_dir . '/includes/functions.php';
2525

2626
function _manually_load_plugin() {
27-
require dirname( __DIR__ ) . '/freemkit.php';
27+
$plugin_file = dirname( __DIR__ ) . '/freemkit.php';
28+
if ( file_exists( $plugin_file ) ) {
29+
require $plugin_file;
30+
}
2831
}
2932
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
3033

0 commit comments

Comments
 (0)