Skip to content

Run PHPUnit integration tests in wp-env - #529

Open
Rahe wants to merge 4 commits into
masterfrom
test/unit-tests
Open

Rahe wants to merge 4 commits into
masterfrom
test/unit-tests

Conversation

@Rahe

@Rahe Rahe commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Why

The theme had no automated PHP tests on master (an old WP_Mock attempt lived on feature/tests, 268 commits behind). Since local development now runs on wp-env, the tests run against a real WordPress there instead of mocking it, so they stay close to production behaviour.

What

  • Isolated test environment: .wp-env.test.json (port 8889, PHP 8.4, testsEnvironment: false, theme active, ACF loaded), separate from the dev environment and using its own wptests_ tables.
  • PHPUnit bootstrap: tests/bootstrap.php, tests/wp-tests-config.php (WP_DEFAULT_THEME, so functions.php and the services boot as in production), phpunit.xml.dist.
  • 293 integration tests in tests/php/, mirroring inc/, on WP_UnitTestCase (factories, real registries, wp_scripts(), go_to(), real attachments…). No mocking library. Classes with static caches run in separate processes. Tests never read dist/: fixtures in tests/assets/ are wired through the theme_file_path / theme_file_uri filters.
  • Tooling: phpunit/phpunit 9.6.38 and yoast/phpunit-polyfills 4.0.0 (Composer), @wordpress/env 12.0.0 and env:* / test:php scripts (npm).
  • CI: new tests-php.yml workflow, PHPUnit on WordPress 6.3 (minimum declared in style.css) and latest stable with PHP 8.4. Coverage is generated locally only (npm run env:start-tests).
  • Docs: new "Tests PHP" section in the README.
  • PHP 8.4: the theme now targets PHP 8.4 like current projects (Requires PHP, dev and test wp-env, Composer platform 8.4.99, PHPCompatibility testVersion, php-quality workflow). This reverts the 8.3 alignment of d73e2dc.

Suspected bugs found (not fixed here, current behaviour pinned in tests)

  • Svg::get_inline_icon_markup() / Icon::resolve_icons_directory(): containment check without trailing separator, a sibling folder such as dist/images-outside is accepted.
  • Service_Container: get_service( Some::class ) returns the class name string; calling boot_services() twice throws an Error.
  • Editor::register() reads the global container instead of the given one (depends on service order).
  • get_theme_static_image_dimensions() calls a method on get_service( 'assets' ) without checking for false.
  • get_the_link() button mode: "Undefined array key" warnings for rel / target without target="_blank".
  • Share links: the shared URL is not URL-encoded.
  • Body_Class::add() accepts an array per its doc but makes body_class() throw a TypeError.
  • Icon::unregister_core_icon_collection(): _doing_it_wrong notice when core is already unregistered.
  • Minor: icon slugs drop underscores, raw > breadcrumb separator, gutenberg_blocks_allowed() only removes the first duplicate.

Test plan

  • npm run env:start-ci && npm run test:php: 293 tests, 706 assertions, green on WordPress 7.1.4 / PHP 8.4
  • Same suite on WordPress 6.3 / PHP 8.4 (WP_ENV_CORE=WordPress/WordPress#6.3): green, 13 Icon tests skipped (icon API requires WP 7.1)
  • npm run env:start-tests && npm run test:php -- --coverage-html=coverage/ --coverage-text: 97.3 % lines
  • composer cs clean, GrumPHP pre-commit checks pass
  • Dev wp-env (.wp-env.json) starts on PHP 8.4.27, theme and ACF active, home page returns 200
  • PHP Tests workflow green on this PR

🤖 Generated with Claude Code


Note

Medium Risk
No production inc/ changes, but raising the minimum PHP version affects all theme consumers; the new CI gate depends on Docker/wp-env reliability.

Overview
Adds PHPUnit integration tests that run inside a dedicated wp-env stack (.wp-env.test.json, port 8889, wptests_ tables), with bootstrap wiring for real WordPress, active theme, and ACF—plus ~293 tests under tests/php/, asset fixtures, and npm scripts (env:start-tests, env:start-ci, test:php). CI gains .github/workflows/tests-php.yml (WordPress 6.3 and latest, PHP 8.4); quality tooling excludes tests/ from PHPCS/Psalm and documents the workflow in the README.

Separately, the theme standardizes on PHP 8.4 (style.css, Composer platform, .wp-env.json, PHPCompatibility, php-quality.yml), adds PHPUnit dev dependencies and @wordpress/env, and keeps tests off theme export bundles via .gitattributes.

Reviewed by Cursor Bugbot for commit 58f3cb2. Bugbot is set up for automated code reviews on this repo. Configure here.

Rahe and others added 4 commits November 5, 2026 18:08
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant