Repository navigation
Use Double across core framework tests - #111
Conversation
Replace direct Mockery doubles across AI, API clients, authentication, broadcasting, bus, top-level cache, connection pools and non-scheduler console tests. Keep Mockery-backed framework APIs and existing PHPUnit doubles intact. Preserve required arguments, object identity, forbidden calls and verification counts with native doubles. Use initialized partials and real containers where appropriate, explicit callback capture, and local operation sequences for cross-double ordering. Declare dynamic Redis and console methods in typed test fixtures without changing production APIs. Consolidate duplicate Redis lock suites while retaining all distinct acquisition, ownership, callback and cleanup coverage. Verify ApiResource's unknown-method behavior against the real response rather than a mocking-library exception. Strengthen the untouched-parent timestamp assertion and correct the Redis integration comment. Validation: every changed test class and fixture consumer passed individually, including coroutine, cleanup and cancellation cases. Existing serializer-build skips remain. Root, type-fixture and skeleton static analysis passed; repository and skeleton formatting completed; git diff --check passed.
Replace direct Mockery doubles in the Redis cache suite, remaining scheduler cases, Context, Cookie, Coordinator, Core, Coroutine, Data and the first Database test group. Preserve explicit call counts, forbidden calls, argument checks, cancellation ownership and cross-call ordering. Exercise Redis operations through initialized connections and strict native client doubles. Reuse concrete scan fixtures where cursor arguments must be updated by reference, retaining pagination and concurrent membership-repair coverage. Record scan inputs and metadata operations for existing assertions; remove one duplicate page test and an unreachable native null-scan case. Use real request, DTO and dispatcher objects where mocking adds no value. Keep scheduler default stubs from absorbing forbidden or excess calls. Resolve the database CLI Process through the existing container with explicit parameters, retaining fresh process ownership, launch options and streamed output while removing constructor interception and isolated test processes. Validation: every changed test file passed independently. The affected Redis cache group passed 491 tests with 2803 assertions. Source, type-fixture and skeleton static analysis passed, as did root/skeleton formatting and the final changed-file formatting and whitespace checks.
Replace remaining direct Mockery doubles across database lifecycle tests, DI, Doctor, Encryption, Engine, Filesystem, Fortify and Foundation. Preserve call counts, argument checks, ordering, exception identity and the existing framework APIs that still use Mockery internally. Use real configuration and exception objects where no double is needed. Exercise Flysystem forwarding through real adapters, keep stream reads in call resolvers, and record database trait ordering in its existing fixture. Make the renderer isolation test actually interleave its coroutines, remove redundant framework cleanup, and delete an unused query-builder test base. Complete ViewFinderInterface with getHints(), alongside its existing namespace-registration methods. Remove concrete-finder assumptions from view caching and analyzer discovery, cover namespaced roots in the command test, and document the contract requirements for custom implementations. Tighten tagged-cache flush tests to reject extra native Redis commands and incorrect keys while preserving the two checks needed for racing writers. Validation: each changed test file passed, including the existing analyzer namespace-discovery and cache-invalidation tests. The existing GCS skip is unchanged. Full static analysis, formatting and whitespace checks passed.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
PR Summary by QodoUse Double across core framework tests
AI Description
Diagram
High-Level Assessment
Files changed (268)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can choose which labels appear on a finding, and whether they show icons or text |
[Medium impact] Most effects stay in framework tests, while view-finder changes reach custom finders and view discovery. The older-phpredis test failure still needs fixing before merge.
|
|
|
||
| return $connection; | ||
| // Unexpected commands must fail: an extra Redis round trip is a regression. | ||
| $client = Double::for(Redis::class)->strict(); |
There was a problem hiding this comment.
Older Redis clients break tests
These native doubles make the affected unit tests require phpredis 6.3, although composer.json supports ^6.1. On 6.1/6.2, the native classes lack hsetex, so expectations in DoctorCommandTest and AnyTag/PutManyTest cannot target a declared method. Previously these commands were mocked on RedisConnection.
Declare the newer commands in a test fixture, or skip only the affected cases on older clients. The RedisCluster helper needs the same treatment.
There was a problem hiding this comment.
This finding is valid. A separate follow-up PR will raise the framework-wide PhpRedis minimum to 6.3 and remove the obsolete older-client checks. This PR intentionally leaves that requirement change to the follow-up; CI already uses PhpRedis 6.3. We will not add fake native methods or skip these cases.
| $this->swoole->expects('get')->with('foo')->returns(null); | ||
| $this->redis->expects('get')->with('foo')->returns(['expiration' => 123]); |
There was a problem hiding this comment.
Malformed writes escape the test
testMalformedLowerRecordRemainsAMiss() no longer catches writes of the malformed record. Both stores are now lenient doubles, while the only assertion checks the returned null. An unwanted put() or forever() call can pass unnoticed; the previous Mockery stores rejected it.
Make these doubles strict or explicitly forbid writes so the test still catches malformed records being copied into the upper cache.
There was a problem hiding this comment.
Fixed: stack cache layers and tagged cache doubles are strict, restoring protection against unexpected writes and deletions. Existing explicit negative assertions and compensation tests remain. The affected tests pass.
Make the disabled-pruning query builder and stack cache layer doubles strict so unconfigured reads, writes and deletions fail as they did before the Double conversion. Apply the same protection to tagged cache layers while retaining explicit negative assertions and real-store compensation coverage. All three affected test files pass. Full formatting and the final targeted formatting check pass. No production behavior or dependency requirements change.
Test doubles
Replace direct Mockery doubles with Double across AI, authentication, cache, console, coroutine, Data, database, filesystem, Fortify and Foundation tests, including their supporting packages. Keep existing PHPUnit doubles and framework APIs backed by Mockery.
The conversion preserves required calls, arguments, ordering, forbidden calls and exception behavior. Tests use real objects where mocking adds no value. Redis cache tests exercise real connection forwarding with strict native-client doubles, and scan tests use concrete clients to preserve cursor updates by reference. Duplicate Redis lock coverage is consolidated and an unused query-builder test base is removed.
Supporting changes
getHints()toViewFinderInterface, alongside namespace registration. View caching and static analysis can discover namespaced views through the contract without assumingFileViewFinder. Document the requirements for custom finders.Verification
Changed test files and affected fixture consumers pass individually, including Redis cache coverage and analyzer view-discovery/cache-invalidation tests. Existing dependency and serializer-build skips remain unchanged. Full static analysis, root and skeleton formatting, and whitespace checks pass.
Summary by cubic
Replaces direct Mockery doubles with Double across AI, authentication, cache, console, coroutine, Data, database, filesystem, Fortify, and Foundation tests, including their supporting packages. PHPUnit doubles and framework APIs backed by Mockery remain unchanged.
getHints()toViewFinderInterfacealongside namespace registration; view caching and static analysis now discover namespaced views without assumingFileViewFinder. Custom finders must implement the new method.Supporting changes
Written for commit 4d4ad4a. Summary will update on new commits.
Note
Migrate core framework tests from Mockery to JMac test doubles
VerifiesDoublestrait and converts return, throw, call-count, callback, and never-called expectations to the newexpects/allows/returns/resolvesAPI.PruneRedisClusterClientrecording calls for explicit assertions.getHints(): arrayto ViewFinderInterface.php and removesFileViewFinderinstanceof guards in the phpstan view helpers; updates view docs and the porting guide accordingly.Processthrough the container instead of constructing it directly.ViewFinderInterfaceimplementers must now providegetHints(); several tests now assert exact Redis return values (e.g.falseinstead ofnullfor failed SET NX,trueinstead of1for expire) and recorded call orderings instead of Mockery global ordering.Macroscope summarized 4d4ad4a.