Skip to content

Commit 24d11ae

Browse files
committed
Update PHP and testing requirements; enhance CI configuration and PHP CodeSniffer rules
- Updated PHP version requirement to >= 8.1 in composer.json and CI configuration. - Added PHPUnit setup instructions in CLAUDE.md. - Enhanced PHP CodeSniffer rules for better code quality checks. - Refactored test scripts for improved compatibility with PHP 8.1. - Updated PHPUnit configuration to align with the latest standards.
1 parent 7b02351 commit 24d11ae

9 files changed

Lines changed: 346 additions & 180 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
strategy:
2828
fail-fast: true
2929
matrix:
30-
php: ["7.4", "8.4"]
30+
php: ["8.1", "8.4"]
3131

3232
name: PHP ${{ matrix.php }}
3333
steps:
@@ -55,7 +55,7 @@ jobs:
5555
with:
5656
# caching node_modules
5757
path: vendor
58-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
58+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
5959
restore-keys: |
6060
${{ runner.os }}-build-${{ env.cache-name }}-
6161
${{ runner.os }}-build-
@@ -131,10 +131,8 @@ jobs:
131131
run: ./tests/install-wp-tests.sh wordpress_test root rootpassword 127.0.0.0 latest
132132
shell: bash
133133

134-
- name: PHPunit
134+
- name: PHPUnit
135135
run: |
136-
composer require "phpunit/phpunit=8.*"
137-
composer require "yoast/phpunit-polyfills"
138-
vendor/phpunit/phpunit/phpunit --version
139-
WP_MULTISITE=1 vendor/phpunit/phpunit/phpunit
136+
vendor/bin/phpunit --version
137+
WP_MULTISITE=1 vendor/bin/phpunit
140138

CLAUDE.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ npm run build # Build CSS/JS for production (Vite)
1919
```bash
2020
npm run lint # Run ESLint
2121
npm run prettier # Format JS files with Prettier
22-
composer install # Install PHP dependencies (required for PHPCS)
22+
composer install # Install PHP dependencies (PHPCS, PHPUnit, etc.; requires PHP >= 8.1)
2323
./tests/test_phpcs.sh # Run PHP CodeSniffer
2424
./tests/test_phpcs.sh file.php # Run PHPCS on specific files
2525
./vendor/bin/phpcbf # Auto-fix PHPCS errors
2626
./tests/test_eslint.sh # Run ESLint + Prettier check
2727
```
2828

29+
### PHPUnit (after WordPress test lib install)
30+
```bash
31+
./tests/install-wp-tests.sh <db-name> <db-user> <db-pass> [db-host]
32+
composer install
33+
composer run test # or: WP_MULTISITE=1 vendor/bin/phpunit
34+
```
35+
2936
## Architecture
3037

3138
### Core Module Structure
@@ -92,7 +99,7 @@ Husky runs lint-staged on commit:
9299
## CI Requirements
93100

94101
Pull requests must pass:
95-
1. PHP syntax check
102+
1. PHP syntax check (PHP 8.1+ in CI)
96103
2. PHPCS on changed PHP files
97104
3. ESLint + Prettier
98105
4. Vite build (compiled assets must match expected output)

composer.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
{
2+
"require": {
3+
"php": ">=8.1",
4+
"kucrut/vite-for-wp": "^0.12.0"
5+
},
26
"require-dev": {
3-
"dealerdirect/phpcodesniffer-composer-installer": "1.*",
4-
"wp-coding-standards/wpcs": "3.1.*",
5-
"squizlabs/php_codesniffer": "*"
7+
"dealerdirect/phpcodesniffer-composer-installer": "^1.2",
8+
"phpunit/phpunit": "^9.6",
9+
"squizlabs/php_codesniffer": "^3.13.5",
10+
"wp-coding-standards/wpcs": "^3.3",
11+
"yoast/phpunit-polyfills": "^4.0"
612
},
713
"scripts": {
814
"lint": "vendor/bin/phpcs",
9-
"lintfix": "vendor/bin/phpcbf"
15+
"lintfix": "vendor/bin/phpcbf",
16+
"test": "vendor/bin/phpunit"
1017
},
1118
"config": {
1219
"allow-plugins": {
1320
"dealerdirect/phpcodesniffer-composer-installer": true
1421
}
15-
},
16-
"require": {
17-
"kucrut/vite-for-wp": "^0.12.0"
1822
}
1923
}

phpcs.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@
181181

182182
<!-- Keeping these ones: -->
183183
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
184-
<rule ref="Generic.Debug.ClosureLinter"/>
185184
<rule ref="Generic.Files.ByteOrderMark"/>
186185
<rule ref="Generic.Files.LineEndings"/>
187186
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
@@ -196,7 +195,10 @@
196195
<rule ref="Generic.WhiteSpace.ScopeIndent">
197196
<properties>
198197
<property name="indent" value="4"/>
199-
<property name="ignoreIndentationTokens" type="array" value="T_COMMENT,T_DOC_COMMENT_OPEN_TAG"/>
198+
<property name="ignoreIndentationTokens" type="array">
199+
<element value="T_COMMENT"/>
200+
<element value="T_DOC_COMMENT_OPEN_TAG"/>
201+
</property>
200202
</properties>
201203
</rule>
202204
<rule ref="PSR2.ControlStructures.ElseIfDeclaration"/>

phpunit.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0"?>
22
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
35
bootstrap="tests/bootstrap.php"
46
backupGlobals="false"
57
colors="true"

tests/bootstrap.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
* @package Disciple.Tools
66
*/
77

8+
$autoload = dirname( __DIR__ ) . '/vendor/autoload.php';
9+
if ( file_exists( $autoload ) ) {
10+
require_once $autoload;
11+
}
12+
813
$_tests_dir = getenv( 'WP_TESTS_DIR' );
914

1015
if ( !$_tests_dir ) {

tests/install-wp-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ install_db() {
138138

139139
if ! [ -z $DB_HOSTNAME ] ; then
140140
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
141-
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
141+
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT"
142142
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
143143
EXTRA=" --socket=$DB_SOCK_OR_PORT"
144144
elif ! [ -z $DB_HOSTNAME ] ; then

tests/test_phpcs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ set -e
44

55
cd "$(dirname "${BASH_SOURCE[0]}")/../"
66

7-
if [ "$(php -r 'echo version_compare( phpversion(), "7.0", ">=" ) ? 1 : 0;')" != 1 ] ; then
7+
if [ "$(php -r 'echo version_compare( phpversion(), "8.1", ">=" ) ? 1 : 0;')" != 1 ] ; then
88
vendor/bin/phpcs functions.php
99
exit
1010
fi
1111

12-
eval vendor/bin/phpcs $args
12+
vendor/bin/phpcs "$@"

0 commit comments

Comments
 (0)