Skip to content

Add basic PHPUnit testing setup #29

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

Merged
merged 4 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: PHPUnit Tests

on:
push:
branches: [ trunk ]
pull_request:
branches: [ trunk ]

jobs:
test:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest

strategy:
matrix:
include:
# Minimum supported PHP
- php: '7.4'
# Latest stable PHP
- php: '8.4'
fail-fast: false

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2

- name: Install dependencies
run: |
composer install --no-progress --prefer-dist --no-interaction

- name: Run PHPUnit
run: composer test:php
12 changes: 8 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Standard gitignore file

# Node.js
node_modules/
npm-debug.log
yarn-error.log

Expand All @@ -12,6 +9,11 @@ logs/

# Dependency directories
jspm_packages/
/vendor/
/node_modules/

# WorDBless
/wordpress/

# Optional npm cache directory
.npm
Expand Down Expand Up @@ -42,4 +44,6 @@ jspm_packages/
assets/build/**/*.css
assets/build/**/*.map
assets/build/**/*.js
/vendor/

# PHPUnit result cache
.phpunit.result.cache
35 changes: 21 additions & 14 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,48 +1,55 @@
<?xml version="1.0"?>
<ruleset>
<!-- Check all PHP files in directory tree by default. -->
<arg name="extensions" value="php"/>
<ruleset name="Secure Custom Fields">
<file>.</file>

<!-- Exclude package files -->
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/node_modules/*</exclude-pattern>
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/node_modules/</exclude-pattern>
<exclude-pattern>/lang/*</exclude-pattern>

<!-- Confirm PHP compat. -->
<config name="testVersion" value="7.4-"/>
<rule ref="PHPCompatibilityWP" />

<!-- Display sniff code -->
<arg value="s"/>
<!-- How to scan -->
<arg value="sp"/> <!-- Show sniff and progress -->
<arg name="colors"/>
<arg name="extensions" value="php"/>

<!-- Rules: WordPress Coding Standards -->
<config name="minimum_supported_wp_version" value="6.0"/>
<rule ref="WordPress">
<exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores" /> <!-- 'acf/hookname' is used throughout. -->
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" /> <!-- This is trivial and not really useful today. -->
<exclude name="WordPress.Files.FileName.InvalidClassFileName" /> <!-- Refactoring of this scale is not in scope yet.-->
</rule>

<rule ref="WordPress.Security.EscapeOutput">
<properties>
<property name="customEscapingFunctions" type="array">
<element value="acf_esc_attrs" /> <!-- This function takes an associated array and escapes both the attr title and attr value. -->
<property name="customEscapingFunctions" type="array">
<element value="acf_esc_attrs" /> <!-- This function takes an associated array and escapes both the attr title and attr value. -->
<element value="acf_esc_html" />
</property>
</property>
</properties>
</rule>

<rule ref="WordPress.Security.ValidatedSanitizedInput">
<properties>
<property name="customSanitizingFunctions" type="array">
<element value="acf_sanitize_request_args" />
</property>
</properties>
</rule>

<rule ref="WordPress.Security.NonceVerification">
<properties>
<property name="customNonceVerificationFunctions" type="array">
<element value="acf_verify_ajax" />
</property>
</properties>
</rule>

<!-- Rules: PHPCompatibility -->
<config name="testVersion" value="7.4-"/>
<rule ref="PHPCompatibilityWP"/>

<!-- Rules: Text Domain -->
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
Expand Down
29 changes: 25 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wordpress/secure-custom-fields",
"description": "Secure Custom Fields",
"type": "project",
"type": "wordpress-plugin",
"license": "GPL-2.0-or-later",
"authors": [
{
Expand All @@ -10,15 +10,28 @@
],
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"roots/wordpress-core-installer": true
},
"platform": {
"php": "7.4"
}
},
"require": {
"php": ">=7.4"
},
"require-dev": {
"yoast/phpunit-polyfills": "^1.1.0",
"phpunit/phpunit": "^9.6",
"wp-coding-standards/wpcs": "^3.0",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"sirbrillig/phpcs-changed": "^2.11",
"nikic/php-parser": "^4.0",
"symfony/finder": "^5.0|^6.0"
"symfony/finder": "^5.0|^6.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"phpcompatibility/phpcompatibility-wp": "^2.1.3",
"sirbrillig/phpcs-changed": "^2.11",
"automattic/wordbless": "^0.5.0"
},
"scripts": {
"docs:manifest": "php docs/bin/generate-manifest.php",
Expand All @@ -32,6 +45,14 @@
"@docs:fix",
"@docs:lint",
"@docs:manifest"
]
],
"test": "@test:php",
"test:php": "phpunit",
"lint": "@lint:php",
"lint:php": "phpcs",
"format": "@format:php",
"format:php": "phpcbf",
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy"
}
}
Loading