Skip to content

Fix DonutCommandRedisCacheTest never exercising Redis storage - #184

Merged
koriym merged 1 commit into
bearsunday:1.xfrom
koriym:fix/donut-redis-cache-test-setup
Aug 2, 2026
Merged

Fix DonutCommandRedisCacheTest never exercising Redis storage#184
koriym merged 1 commit into
bearsunday:1.xfrom
koriym:fix/donut-redis-cache-test-setup

Conversation

@koriym

@koriym koriym commented Jul 31, 2026

Copy link
Copy Markdown
Member

Found while reviewing #178. All three issues are pre-existing on 1.x; this PR is based on 1.x and does not overlap with #178's SemanticLogger rebuild (merge conflicts there, if any, are expected and acceptable).

1. DonutCommandRedisCacheTest never tested Redis (main fix)

Two stacked reasons meant this @requires extension redis test class has never exercised Redis storage:

setUp ordering. The child setUp() built a Redis-module injector and assigned $this->resource, $this->logger, $this->httpCache from it — then called parent::setUp() last. The parent (DonutCommandInterceptorTest::setUp()) unconditionally re-assigns the same three properties from a non-Redis module, silently discarding the Redis setup (and the object produced by the unserialize(serialize($httpCache)) round-trip). Fixed by calling parent::setUp() first, so the child overrides win while any parent behavior is preserved.

Wrong storage module. Even with the ordering fixed, the test would still not touch Redis. On 1.x, ResourceStorage consumes TagAwareAdapterInterface pools (ResourceObjectPool / EtagPool qualifiers). The deprecated StorageRedisModule only binds CacheItemPoolInterface@Shared / CacheItemPoolInterface@EtagPool, which nothing in ResourceStorage injects — the pools stay TagAwareAdapter(ArrayAdapter). I verified this empirically by building both injector stacks and reflecting on ResourceStorage::$roPool / $etagPool:

  • StorageRedisModule stack: roPool=TagAwareAdapter (items=ArrayAdapter) ← no Redis anywhere
  • StorageRedisDsnModule stack: roPool=RedisTagAwareAdapter, etagPool=RedisTagAwareAdapter ← genuinely Redis-backed, and the serialize round-trip still succeeds

So the override is now StorageRedisDsnModule with DSN redis://127.0.0.1:6379 — the current, non-deprecated Redis storage module (which the deprecated class itself points to). The unserialize(serialize($httpCache)) round-trip is kept; it works because ResourceStorage::__serialize() persists the pool providers, and re-resolving them rebuilds the Redis connection on unserialize.

2. Drive-by: $puregeResult typo

Renamed to $purgeResult in tests/DonutQueryInterceptorPurgeTest.php (both occurrences, that file only).

3. Drive-by: error-handler leak in QueryRepositoryTest::testErrorInCacheRead

restore_error_handler() ran after the assertion, so a failed assertion would leak the custom error handler into later tests. The body is now wrapped in try/finally; logic and assertions are unchanged.

Verification

  • Local PHP 8.4 has no ext-redis, so DonutCommandRedisCacheTest skips locally (expected). Verified instead by replicating the exact setUp() stacks in a throwaway script (with a stubbed Redis class, not committed) and asserting the resolved storage adapter classes as shown above.
  • ./vendor/bin/phpunit tests/DonutCommandRedisCacheTest.php tests/DonutQueryInterceptorPurgeTest.php tests/DonutCommandInterceptorTest.php tests/QueryRepositoryTest.phpOK (17 tests, 33 assertions, 3 skipped = the redis class).
  • composer cs → clean.
  • CI installs redis-server + ext-redis on ubuntu/macos/windows for PHP 8.2–8.4, so the fixed test will really run there. RedisTagAwareAdapter requires Redis ≥ 2.8 with noeviction/volatile-* policy; CI's default redis-server configuration satisfies this.

Out of scope (follow-up)

PHPUnit 11 deprecates doc-comment metadata (@covers, @depends, @requires extension). Migrating these to attributes would touch many files that #178 rewrites, so it is intentionally left for a later PR.

The child setUp() assigned Redis-backed instances and then called
parent::setUp() last, which re-assigned resource/logger/httpCache from
a non-Redis module and silently discarded the Redis setup. Run
parent::setUp() first so the Redis overrides win, and switch the
override to StorageRedisDsnModule: ResourceStorage consumes
TagAwareAdapterInterface pools, which the deprecated StorageRedisModule
never binds, so even a correctly ordered setUp would have kept using
the ArrayAdapter pools.

Also fix two drive-by test bugs:
- Rename $puregeResult to $purgeResult in DonutQueryInterceptorPurgeTest
- Restore the error handler in QueryRepositoryTest::testErrorInCacheRead
  via try/finally so a failed assertion cannot leak the custom handler
  into later tests
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b4484e4e-7bd1-454e-bff9-b99bb072d08d

📥 Commits

Reviewing files that changed from the base of the PR and between 1e2700c and ac88429.

📒 Files selected for processing (3)
  • tests/DonutCommandRedisCacheTest.php
  • tests/DonutQueryInterceptorPurgeTest.php
  • tests/QueryRepositoryTest.php

📝 Walkthrough

Walkthrough

The pull request updates Redis test setup, makes error-handler restoration unconditional, and corrects a purge result variable name.

Changes

Test maintenance

Layer / File(s) Summary
Redis test setup
tests/DonutCommandRedisCacheTest.php
The test calls parent::setUp() and configures Redis with StorageRedisDsnModule('redis://127.0.0.1:6379').
Test cleanup and naming
tests/QueryRepositoryTest.php, tests/DonutQueryInterceptorPurgeTest.php
The cache error test restores its error handler in a finally block. The purge test renames the result variable to $purgeResult.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main fix: making DonutCommandRedisCacheTest exercise Redis storage.
Description check ✅ Passed The description directly explains the Redis test fix and the two related test corrections.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1e2700c) to head (ac88429).

Additional details and impacted files
@@             Coverage Diff             @@
##                 1.x      #184   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       254       254           
===========================================
  Files             53        53           
  Lines            765       765           
===========================================
  Hits             765       765           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@koriym

koriym commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@koriym
koriym merged commit 89399c6 into bearsunday:1.x Aug 2, 2026
20 checks passed
@koriym
koriym deleted the fix/donut-redis-cache-test-setup branch August 2, 2026 06:13
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