Skip to content

Commit

Permalink
Add basic PHPUnit testing setup
Browse files Browse the repository at this point in the history
  • Loading branch information
kraftbj committed Feb 10, 2025
1 parent 9815acc commit a7a2ba7
Show file tree
Hide file tree
Showing 8 changed files with 2,256 additions and 67 deletions.
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.3'
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
9 changes: 5 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,3 @@ jspm_packages/
assets/build/**/*.css
assets/build/**/*.map
assets/build/**/*.js
/vendor/
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,12 +10,33 @@
],
"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"
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"phpcompatibility/phpcompatibility-wp": "^2.1.3",
"sirbrillig/phpcs-changed": "^2.11",
"automattic/wordbless": "^0.4.2"
},
"scripts": {
"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

0 comments on commit a7a2ba7

Please sign in to comment.