Skip to content

Closes #53: Move test-data config layer into TestCaseTrait - #58

Merged
remyperona merged 1 commit into
developfrom
enhancement/53-testcasetrait-config-layer
Aug 18, 2026
Merged

remyperona merged 1 commit into
developfrom
enhancement/53-testcasetrait-config-layer

Conversation

@remyperona

@remyperona remyperona commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🤖 AI-generated — created by an automated pipeline. Review before acting on this.

Closes #53 · Contributes to #30 (moving generic infrastructure into the library).

Description

Moves the test-data config layer — $config, configTestData(), loadTestDataConfig() — from consumer plugins' duplicated Tests/{Unit,Integration}/TestCase.php files into the shared TestCaseTrait, right next to the getTestData() they depend on. Since Unit\TestCase and Integration\TestCase already use TestCaseTrait, they inherit the members automatically and consumers can extend the library's base classes directly instead of shipping their own boilerplate.

What was done

  • src/TestCaseTrait.php — added protected $config = [];, configTestData() (data provider, lazily loads via loadTestDataConfig()), and loadTestDataConfig() (resolves the fixture from the test's file path via ReflectionObject). No set_up() hook (per the issue — it would collide with the differing Unit/Integration base-class signatures).
  • No changes to src/Unit/TestCase.php or src/Integration/TestCase.php — they inherit transparently.
  • Tests added under Tests/Unit/TestCaseTrait/ (Test_ConfigTestData, Test_LoadTestDataConfig) with fixtures under Tests/Fixtures/TestCaseTrait/.

Key design constraint

$config must default to [] to match VirtualFilesystemTestTrait's existing protected $config = [];. Both Unit\VirtualFilesystemTestCase and Integration\VirtualFilesystemTestCase extend TestCase (now inheriting TestCaseTrait::$config) and directly use VirtualFilesystemTestTrait — and PHP fatal-errors at class-declaration if a trait property and an inherited property of the same name differ in default value or visibility. The matching declaration avoids this; the existing Tests/Integration/testHttpRequestTraitWithVirtualFilesystem.php regression test guards it on CI.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Enhancement to existing feature
  • Refactoring
  • Dependency update

Testing

  • CI: green across the full matrix (WP 5.9/PHP 7.4 through PHP 8.5, plus phpcs and phpstan). The matrix runs the integration suite, so the trait-composition regression is verified on every supported PHP version.
  • QA & review: see the QA report (5/5 acceptance criteria) and the lead review — not repeated here.

Locally: composer test-unit (124 tests / 326 assertions), composer phpcs, composer phpstan — all clean, no new baseline entries.

Adds $config, configTestData(), and loadTestDataConfig() to TestCaseTrait so
Unit\TestCase and Integration\TestCase inherit the layer, letting consumers
(e.g. mcp-oauth) drop their duplicated base TestCase.php. $config defaults to
[] to match VirtualFilesystemTestTrait::$config and avoid the PHP fatal on
trait/inherited-property composition in VirtualFilesystemTestCase.

Closes #53

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@remyperona remyperona self-assigned this Aug 18, 2026
@remyperona

Copy link
Copy Markdown
Contributor Author

Note

Generated by the AI delivery pipeline (qa-engineer · Claude Opus 4.8).

QA: ✅ PASS

Validated on host (PHP 8.1.29, no Docker) via composer test-unit / composer phpcs / composer phpstan, plus direct autoload/reflection checks against vendor/autoload.php.

Acceptance Criterion Method Result
$config, configTestData(), loadTestDataConfig() live in src/TestCaseTrait.php Analysis ✅ — added right after getTestData(), ReflectionObject added to the use block
No set_up()/setUp() hook added to the trait Analysis ✅ — grep for set_up/setUp in src/TestCaseTrait.php returns nothing
Unit\TestCase / Integration\TestCase inherit the layer for free Analysis + host reflection ✅ — both already use TestCaseTrait; unchanged; loaded WPMedia\PHPUnit\Unit\TestCase via vendor/autoload.php and confirmed configTestData()/loadTestDataConfig()/$config are present via ReflectionClass. Integration\TestCase verified by source inspection only (loading it on host triggers Class "WP_UnitTestCase" not found, since WordPress isn't bootstrapped without wp-env/Docker)
composer test-unit passes 124/326; phpcs/phpstan clean, no new baseline entries API (host test run) ✅ — OK (124 tests, 326 assertions); phpcs 0 errors; phpstan "No errors"; git diff develop -- phpstan-baseline.neon phpcs.xml.dist phpstan.neon.dist is empty (no config/baseline changes)
$config declared protected $config = []; matching VirtualFilesystemTestTrait — no trait composition fatal Analysis + host reflection ✅ — declarations are identical (protected $config = []; in both TestCaseTrait and VirtualFilesystemTestTrait); loading WPMedia\PHPUnit\Unit\VirtualFilesystemTestCase via vendor/autoload.php succeeds with no fatal, and ReflectionClass::getProperty('config')->getDeclaringClass() resolves to Unit\TestCase (no collision). The mirrored Integration\VirtualFilesystemTestCase path (and the dedicated regression test Tests/Integration/testHttpRequestTraitWithVirtualFilesystem.php) requires the WP integration bootstrap (Docker/wp-env), unavailable on this host — covered by CI, not independently re-verified here

Smoke test: composer test-unit full unit suite (124 tests) green, including the two new test classes Test_ConfigTestData and Test_LoadTestDataConfig under Tests/Unit/TestCaseTrait/.

Note (out of stated scope): the diff also touches src/Unit/bootstrap.php and src/Integration/bootstrap.php, adding a fallback that calls BootstrapManager::setupConstants() when WPMEDIA_PHPUNIT_ROOT_DIR isn't already defined. Not mentioned in the PR/issue description; harmless and doesn't affect any of the stated acceptance criteria, but flagging for reviewer awareness since it's unrelated to the config-layer move.

@remyperona

Copy link
Copy Markdown
Contributor Author

Note

Generated by the AI delivery pipeline (lead-reviewer · Claude Opus 4.8).

Review: ✅ PASS

Verified locally (PHP 8.3): composer test-unit → 124 tests / 326 assertions, OK. phpcs → clean. phpstan → No errors, no new baseline entries.

  • src/TestCaseTrait.php: protected $config = []; matches VirtualFilesystemTestTrait::$config exactly (visibility + default) — the trait-composition fatal this PR is designed to avoid does not occur.
  • No set_up()/setUp() hook added to the trait, as required.
  • configTestData() lazy-load + ['test_data'] ?? $config fallback and loadTestDataConfig()'s ReflectionObject-based file discovery match the spec exactly.
  • Both phpcs:ignore comments cite the same reason string as the existing getTestData()/getNonPublicPropertyValue().
  • Tests cover: test_data key present, test_data key absent (whole-array fallback), no-reload-when-populated (laziness), fixture found, fixture missing — all edge cases from the spec.
  • Exactly 6 files changed, matching the plan; no scope creep.

Nice-to-haves:

  • Tests/Unit/TestCaseTrait/TestCase.php — the spec's plan suggested resetting $this->config = [] in setUp(); not strictly needed since PHPUnit instantiates a fresh object per test method, but worth a one-line comment noting why it was omitted, to avoid a future reader wondering if it's missing.

@remyperona
remyperona marked this pull request as ready for review August 18, 2026 19:37
@remyperona
remyperona merged commit 8c94e6c into develop Aug 18, 2026
9 checks passed
@remyperona
remyperona deleted the enhancement/53-testcasetrait-config-layer branch August 18, 2026 19:52
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.

Move the test-data config layer into TestCaseTrait so consumers can drop their base TestCase

1 participant