Skip to content

Add PHPUnit Testing Framework#133

Merged
GaryJones merged 15 commits intodevelopfrom
feature/add-phpunit-testing
Oct 1, 2025
Merged

Add PHPUnit Testing Framework#133
GaryJones merged 15 commits intodevelopfrom
feature/add-phpunit-testing

Conversation

@ovidiul
Copy link
Copy Markdown
Contributor

@ovidiul ovidiul commented Sep 25, 2025

What This Does

Adds PHPUnit testing framework.

Changes Made

🧪 PHPUnit Framework

  • PHPUnit 9.x configuration with proper test suites
  • WordPress test environment integration
  • PSR-4 compliant test structure and naming
  • Base TestCase with common WordPress testing utilities

📁 Proper Structure (Addresses Gary's Feedback)

  • PSR-4 Naming: TestCase.php, PluginTest.php, etc. (not class-*)
  • Namespaces: Automattic\Crowdsignal\Tests\* (simplified naming)
  • Clean Dependencies: Only wp-test-utils (includes everything needed)
  • PHP 5.6+: Maintains current minimum requirement
  • Directory Structure: tests/Unit/, tests/Integration/

🔧 Testing Tools

  • WordPress test environment bootstrap
  • Coverage reporting configuration
  • Install script for WordPress tests
  • Sample unit and integration tests

Usage

# Set up WordPress tests (one time)
bin/install-wp-tests.sh wordpress_test root '' localhost latest

# Install dependencies
composer install

# Run tests
composer test              # All tests
composer test:unit         # Unit tests only  
composer test:integration  # Integration tests only

Addresses Gary's Specific Feedback from PR #116 comments:

  • PSR-4 naming: All test files use proper PSR-4 conventions
  • Namespaces: Simplified Test_Case to namespaced TestCase
  • Dependencies: Removed redundant packages, only wp-test-utils
  • PHP version: Stays at 5.6 as requested
  • Single install: One install script, not duplicate

This provides a solid foundation for WordPress plugin testing following modern PHP and WordPress standards.

ovidiul added a commit that referenced this pull request Sep 25, 2025
Final PR in the focused series addressing Gary's "one tooling at a time" feedback.

FEATURES:
- Basic validation: PHP syntax, composer validation, coding standards
- Quality checks: Full PHPCS, PHP compatibility testing
- PHPUnit tests: Multi-version WordPress and PHP testing
- Focused scope: Only essential CI/CD, no excessive complexity

WORKFLOWS:
- basic-validation.yml: Quick checks for every PR
- quality-checks.yml: Comprehensive testing matrix
- MySQL service for WordPress tests
- PHP 5.6-8.2 compatibility validation

APPROACH:
- Builds on previous PRs (PHPCS #132, PHPUnit #133)
- Simple, maintainable configuration
- Follows WordPress.org plugin standards
- No overengineering or excessive features

Third and final PR completing the tooling foundation:
✅ PR #132: WordPress Coding Standards (PHPCS)
✅ PR #133: PHPUnit Testing Framework
✅ This PR: GitHub Actions CI/CD

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add composer.json with Yoast WP Test Utils for WordPress testing
- Add phpunit.xml configuration for unit and integration test suites
- Add phpunit-unit.xml for standalone testing without WordPress
- Add tests/bootstrap.php for WordPress test environment
- Add tests/TestCase.php base class with PSR-4 namespace
- Add SampleTest.php to verify framework functionality
- Include PHPUnit test scripts and coverage reporting

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread tests/Unit/SampleTest.php Outdated
Comment thread tests/bootstrap.php Outdated
Comment thread tests/TestCase.php Outdated
Comment thread composer.json
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The presence of this file is going to conflict once #132 has been merged.

Comment thread phpunit-unit.xml Outdated
Comment thread phpunit.xml.dist Outdated
Comment thread phpunit.xml.dist Outdated
Comment thread .gitignore Outdated
Comment thread phpunit.xml.dist Outdated
Comment thread .gitignore Outdated
ovidiul and others added 13 commits September 30, 2025 16:30
- Add trailing newline to tests/bootstrap.php
- Ensures all test files follow proper file ending conventions
- Addresses Gary's review feedback on PR #133

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Merge PHPCS configuration from PR #132 with PHPUnit testing setup
- Combine both testing and coding standards dependencies
- Remove unnecessary dealerdirect/phpcodesniffer-composer-installer dependency
- Add phpcs.xml configuration for WordPress coding standards
- Update .gitignore for PHPCS cache
- Fix support URLs to use correct repository paths

This resolves the potential conflict between PR #132 (PHPCS) and PR #133 (PHPUnit)
by combining both functionalities into a single comprehensive configuration.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove duplicate phpunit-unit.xml file (only need one config)
- Rename phpunit.xml to phpunit.xml.dist for distributed version
- Update PHPUnit schema from 9.5 to 9.6
- Remove test:standalone script that referenced deleted config
- Update .gitignore to ignore phpunit.xml (allows custom local configs)

Addresses Gary's review feedback on PR #133 about PHPUnit configuration.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: Gary Jones <gary.jones@automattic.com>
Co-authored-by: Gary Jones <gary.jones@automattic.com>
Co-authored-by: Gary Jones <gary.jones@automattic.com>
Co-authored-by: Gary Jones <gary.jones@automattic.com>
Co-authored-by: Gary Jones <gary.jones@automattic.com>
Co-authored-by: Gary Jones <gary.jones@automattic.com>
Co-authored-by: Gary Jones <gary.jones@automattic.com>
Co-authored-by: Gary Jones <gary.jones@automattic.com>
Co-authored-by: Gary Jones <gary.jones@automattic.com>
- Add declare(strict_types = 1) to all test files
- Add namespace to tests/bootstrap.php
- Implement conditional WordPress loading (only for integration tests)
- Use modern PHP syntax with closures and proper typing
- Bootstrap now checks for --testsuite integration argument
- Unit tests run without WordPress dependency

Addresses Gary's review feedback about separating unit tests from WordPress
and using modern PHP practices with strict typing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ovidiul
Copy link
Copy Markdown
Contributor Author

ovidiul commented Sep 30, 2025

Updates made to address review feedback:

Fixed missing newlines - Added trailing newlines to all test files
Resolved composer.json conflict - Merged PHPCS configuration from PR #132
Cleaned up PHPUnit config - Removed duplicate files, renamed to phpunit.xml.dist, updated schema 9.5→9.6
Enhanced bootstrap - Added strict types, namespacing, conditional WordPress loading for integration tests only
Removed unnecessary dependencies - Cleaned up composer.json per feedback

The PR now combines both PHPCS and PHPUnit functionality without conflicts. All review points have been addressed.

@GaryJones
Copy link
Copy Markdown
Contributor

The PR now combines both PHPCS and PHPUnit functionality without conflicts

Incorrect. There are merge conflicts which need resolving.

@ovidiul
Copy link
Copy Markdown
Contributor Author

ovidiul commented Oct 1, 2025

Merge conflicts solved.

@GaryJones GaryJones added this to the 3.1.3 milestone Oct 1, 2025
@GaryJones GaryJones merged commit 767b2fe into develop Oct 1, 2025
@GaryJones GaryJones deleted the feature/add-phpunit-testing branch October 1, 2025 11:46
@GaryJones GaryJones mentioned this pull request Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants