Fix DonutCommandRedisCacheTest never exercising Redis storage - #184
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe pull request updates Redis test setup, makes error-handler restoration unconditional, and corrects a purge result variable name. ChangesTest maintenance
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
Found while reviewing #178. All three issues are pre-existing on
1.x; this PR is based on1.xand does not overlap with #178's SemanticLogger rebuild (merge conflicts there, if any, are expected and acceptable).1.
DonutCommandRedisCacheTestnever tested Redis (main fix)Two stacked reasons meant this
@requires extension redistest class has never exercised Redis storage:setUp ordering. The child
setUp()built a Redis-module injector and assigned$this->resource,$this->logger,$this->httpCachefrom it — then calledparent::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 theunserialize(serialize($httpCache))round-trip). Fixed by callingparent::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,ResourceStorageconsumesTagAwareAdapterInterfacepools (ResourceObjectPool/EtagPoolqualifiers). The deprecatedStorageRedisModuleonly bindsCacheItemPoolInterface@Shared/CacheItemPoolInterface@EtagPool, which nothing inResourceStorageinjects — the pools stayTagAwareAdapter(ArrayAdapter). I verified this empirically by building both injector stacks and reflecting onResourceStorage::$roPool/$etagPool:StorageRedisModulestack:roPool=TagAwareAdapter (items=ArrayAdapter)← no Redis anywhereStorageRedisDsnModulestack:roPool=RedisTagAwareAdapter, etagPool=RedisTagAwareAdapter← genuinely Redis-backed, and the serialize round-trip still succeedsSo the override is now
StorageRedisDsnModulewith DSNredis://127.0.0.1:6379— the current, non-deprecated Redis storage module (which the deprecated class itself points to). Theunserialize(serialize($httpCache))round-trip is kept; it works becauseResourceStorage::__serialize()persists the pool providers, and re-resolving them rebuilds the Redis connection on unserialize.2. Drive-by:
$puregeResulttypoRenamed to
$purgeResultintests/DonutQueryInterceptorPurgeTest.php(both occurrences, that file only).3. Drive-by: error-handler leak in
QueryRepositoryTest::testErrorInCacheReadrestore_error_handler()ran after the assertion, so a failed assertion would leak the custom error handler into later tests. The body is now wrapped intry/finally; logic and assertions are unchanged.Verification
DonutCommandRedisCacheTestskips locally (expected). Verified instead by replicating the exactsetUp()stacks in a throwaway script (with a stubbedRedisclass, 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.php→ OK (17 tests, 33 assertions, 3 skipped = the redis class).composer cs→ clean.RedisTagAwareAdapterrequires Redis ≥ 2.8 withnoeviction/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.