Skip to content

Closes #36: Consolidate divergent getDefaultVfs() definitions - #45

Merged
remyperona merged 3 commits into
developfrom
fix/36-consolidate-getdefaultvfs
Aug 14, 2026
Merged

Closes #36: Consolidate divergent getDefaultVfs() definitions#45
remyperona merged 3 commits into
developfrom
fix/36-consolidate-getdefaultvfs

Conversation

@remyperona

@remyperona remyperona commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🤖 This pull request was generated with the assistance of AI.

Problem (issue #36)

getDefaultVfs() was defined multiple times across the package with divergent structures, and the precedence between them was confusing:

  • src/VirtualFilesystemTestTrait.php returned a WP-like tree.
  • src/Integration/VirtualFilesystemTestCase.php and src/Unit/VirtualFilesystemTestCase.php each overrode it with an identical Tests/{Integration,Unit} tree — copy/paste duplication, and rendering the trait's default dead.

Consumers (e.g. WP Rocket) override getDefaultVfs() again, so it was unclear which layer was authoritative.

Solution

  • Single source of truth in the trait. src/VirtualFilesystemTestTrait.php::getDefaultVfs() holds the package's default — a WP-like structure (wp-admin, wp-content/{mu-plugins,plugins,themes,uploads}, wp-includes, wp-config.php) — documented as the single intended override point for consumers.
  • Removed the duplicate src/ overrides in both Integration/ and Unit/ VirtualFilesystemTestCase classes.
  • Moved the Tests/{Integration,Unit} override to the one internal suite that needs itTests/Unit/VirtualFilesystemDirect/TestCase.php — using the sanctioned consumer override point rather than reintroducing a competing default inside the package. This suite's getListing/getDirsListing/getFilesListing data sets assert the exact root listing, so it supplies its own structure.

Tooling

  • Added declare(strict_types=1); to every modified file.
  • Added the modified files to the phpcs.xml.dist scope; composer phpcs passes with 0 errors. Pre-existing camelCase public-API names (e.g. getDefaultVfs, rootVirtualUrl) carry justified phpcs:ignore annotations — renaming them would be a breaking change for consumers.
  • composer phpstan: 0 errors (71 files).
  • The getDefaultVfs unit test uses a single @dataProvider-driven method sourcing a fixture from Tests/Fixtures/VirtualFilesystemTestTrait/.

Testing

  • composer test-unit: 96 tests, 298 assertions, 0 failures.
  • composer phpcs: 0 errors / 0 warnings.
  • composer phpstan: 0 errors.
  • Integration suite requires CI-only WordPress infrastructure (WP_TESTS_DIR + DB) and was not run locally.

Closes #36

getDefaultVfs() was defined three times with divergent structures:
the trait's wp-admin/wp-content tree was dead code because both
Unit\VirtualFilesystemTestCase and Integration\VirtualFilesystemTestCase
overrode it with an identical Tests/{Integration,Unit} tree.

Move that Tests/{Integration,Unit} structure into
VirtualFilesystemTestTrait::getDefaultVfs() as the single default,
remove the two identical test-case overrides plus a third redundant
copy in the trait's own unit test helper, and document the method as
the intended single override point for consumers.

Add a dedicated unit test asserting the default structure and its
use in mergeStructure().

Co-Authored-By: Sonnet 5 <noreply@anthropic.com>
@remyperona remyperona self-assigned this Aug 14, 2026
remyperona and others added 2 commits August 14, 2026 13:10
Follow-up to the earlier consolidation: the trait's getDefaultVfs()
default is now WP-like again (wp-admin/wp-content/wp-includes/
wp-config.php), restoring the original package default while keeping
the "single override point" principle from issue #36 (src/Integration
and src/Unit VirtualFilesystemTestCase no longer override it).

Internal test suites that need the Tests/{Integration,Unit} structure
instead override getDefaultVfs() at the sanctioned override point:
Tests/Unit/VirtualFilesystemDirect/TestCase.php, whose getListing/
getDirsListing/getFilesListing fixtures assert the exact, full root
listing.

Also:
- Add declare(strict_types=1) to every file touched this round.
- Add these files to phpcs.xml.dist's incremental scope and bring
  them to zero PHPCS errors; pre-existing camelCase public API names
  in the trait (getDefaultVfs, rootVirtualUrl, etc.) are annotated
  with phpcs:ignore, since renaming them would be a breaking change
  for consumers and is out of scope for this issue.
- Refactor the getDefaultVfs() unit test into a single
  @dataProvider-driven test method sourcing its expectations from
  Tests/Fixtures/VirtualFilesystemTestTrait/getDefaultVfs.php.

composer test-unit: 96 tests, 298 assertions, 0 failures.
composer phpcs: 0 errors across the scoped files.
composer phpstan: 0 errors across all 71 analyzed files.

Co-Authored-By: Sonnet 5 <noreply@anthropic.com>
)

Removing the getDefaultVfs() override from src/Unit/VirtualFilesystemTestCase.php
shifted PHPStan's attribution of three pre-existing ArrayTrait is_array()/is_null()
errors from the trait-using class to the trait's own file (src/ArrayTrait.php).
Repoint the two baseline entries so they match again, fixing the CI ignore.unmatched
failures. No code behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@remyperona
remyperona marked this pull request as ready for review August 14, 2026 18:03
@remyperona
remyperona merged commit 359bc05 into develop Aug 14, 2026
9 checks passed
@remyperona
remyperona deleted the fix/36-consolidate-getdefaultvfs branch August 14, 2026 18:04
@remyperona remyperona linked an issue Aug 14, 2026 that may be closed by this pull request
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.

getDefaultVfs() defined 3× with divergent structures — consolidate

1 participant