Skip to content

Util/Cache: add unit tests - #1480

Open
ozanuslan wants to merge 5 commits into
PHPCSStandards:4.xfrom
ozanuslan:feature/util-cache-tests
Open

Util/Cache: add unit tests#1480
ozanuslan wants to merge 5 commits into
PHPCSStandards:4.xfrom
ozanuslan:feature/util-cache-tests

Conversation

@ozanuslan

@ozanuslan ozanuslan commented Aug 13, 2026

Copy link
Copy Markdown

Description

Util\Cache currently has no test coverage. This PR adds a unit test suite for it, pinning down the current
behaviour before anyone changes it.

Two test classes under tests/Core/Util/Cache/:

  • GetSetGetSizeTestget, set, and getSize
  • LoadSaveTestload / save, including an explicit --cache= file, entries being cleared when the
    stamped config no longer matches, and the auto-chosen cache path (XDG_CACHE_HOME, system temp fallback,
    shared ancestor of the scanned files, empty file list)

They follow the existing Core Util patterns: separate processes for the static store, ConfigDouble, temp files
removed in tearDown(), XDG_CACHE_HOME restored afterwards. Assertions are on observable behaviour and on
where the cache file ends up, not on the internal hash values, so these shouldn't get in the way if the hash
composition changes later.

I ran into the gap while reading the cache code for #1479. This stands on its own regardless of what happens
with that proposal — the coverage seemed worth having either way, including for any changes you'd want to make
to Cache yourselves. Happy to adjust the file split, naming or scope if it doesn't match how you'd like Util
tests laid out.

Suggested changelog entry

n/a

Related issues/external references

#1479 — where the missing coverage came up.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement
  • None of the above; tests only

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.
  • I have opened a sister-PR in the documentation repository to update the Wiki.

@ozanuslan

Copy link
Copy Markdown
Author

Thanks for taking a look when you get to this — and for the earlier note on #1479 about covering Cache first.

On CI: the two red checks don’t look related to the new Cache tests. PHP: 8.6 (Win) fails in existing Generator docs-title fallback tests (HTML / Markdown / Text), and Linux 8.6 plus the rest of the matrix (including the Cache suite and CS) are green. QA Markdown is crashing in mdast-util-gfm-table on README.md / CHANGELOG-*.md, which this PR doesn’t touch. I also checked a handful of recent PRs and both jobs were still passing there (last green PHP: 8.6 (Win) I saw was on #1475); the Windows 8.6 job here is on a newer 8.6.0-dev build than that run.

Happy to dig further or adjust anything on the Cache tests if you’d like.

@jrfnl

jrfnl commented Aug 16, 2026

Copy link
Copy Markdown
Member

On CI: the two red checks don’t look related to the new Cache tests. PHP: 8.6 (Win) fails in existing Generator docs-title fallback tests (HTML / Markdown / Text), and Linux 8.6 plus the rest of the matrix (including the Cache suite and CS) are green. QA Markdown is crashing in mdast-util-gfm-table on README.md / CHANGELOG-*.md, which this PR doesn’t touch. I also checked a handful of recent PRs and both jobs were still passing there (last green PHP: 8.6 (Win) I saw was on #1475); the Windows 8.6 job here is on a newer 8.6.0-dev build than that run.

No need to worry about those unrelated CI failures. The markdown failure should be fixed via #1483. And PHP 8.6 builds are not required to pass yet.

For now, I've isolated the issue with the Generator code on PHP 8.6/Windows and have reported the problem to PHP Core: php/php-src#23326. If this is a deliberate change for PHP 8.6, I will fix the PHPCS code to handle the new format, but for now, we should wait to hear back from PHP Core whether this is a bug or a feature.

@jrfnl

jrfnl commented Aug 16, 2026

Copy link
Copy Markdown
Member

... for now, we should wait to hear back from PHP Core whether this is a bug or a feature.

Based on the discussion in the PHP Core issue, this is an intentional change coming from a more recent libxml version.
PR #1485 should fix the impact on PHPCS.

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