Repository navigation
Add support for Doctrine Collections 3 - #200
X-Coder264 wants to merge 1 commit into
Conversation
3ace93b to
c117c58
Compare
Select TestsQueue's add signature from ArrayCollection's native return type. Keep the existing bool return value and deprecation with Collections 1/2, and declare void with Collections 3. Preserve the direct parent class and private collection state for Fastest 1.x compatibility. Load separate trait implementations lazily so static analysis sees only the active signature and Composer classmaps remain unambiguous. Cover path wrapping, object identity, randomization, filtering, return values and deprecations. Check caller and subclass contracts at runtime and with PHPStan across old and new Collections versions, including authoritative Composer autoloading.
c117c58 to
1701f91
Compare
|
@DonCallisto any chance we could get this merged and released? 🙏 |
|
I'm gonna review it ASAP, pinky promise :) |
| // Keep the variants outside PSR-4 directories so classmaps and static analysis | ||
| // see only the installed native signature. Register lazily to preserve bootstrap behavior. |
There was a problem hiding this comment.
This comment is a little bit deceptive as this namespace is loaded through PSR-4. The only evidence that a trait or the other is loaded is via composer.json. I would prefer to have an explicit comment about that.
There was a problem hiding this comment.
Why a different workflow only for collections? Couldn't this be integrate in the main build.yaml, maybe with a little tweaking in order to run this kind of scenarios in a one-fit-all fashion?
I'm worried about those files to go "out-of-date" with versions and all related things
|
Sorry i've reviewed it with my other (not personal) account but it's still me 😂 |
Fastest currently cannot load
TestsQueuewith Doctrine Collections 3:TestsQueue::add(): boolis incompatible with the nativeArrayCollection::add(): voidsignature.This adds Collections 3 support to the current 1.x line, retaining the existing
^1.2and^2.0constraints and PHP^8.0requirement. An internal lazy loader selects the trait implementation from the installed parent's native return type:add(): boolstill returnstrueand emits exactly the existing deprecation from Doctrine collections compatibility #188add(): voidsatisfies the parent's native signaturePath wrapping and existing
TestSuiteobjects behave as before.TestsQueuestill directly extendsArrayCollection, its private state stays in the same class, and existing subclasses remain compatible when using Collections 1/2. The README explains the return-type requirement for subclasses opting into Collections 3. This does not remove the legacy return value globally or require a Fastest 2.0 release.The first implementation put two declarations of the same internal trait in an
if/elsein one file. It inspected the installedArrayCollection::add()return type and declared either theboolorvoidvariant. This worked at runtime, but upon review it became clear that both PHPStan 1.12.21 and 2.3.2 selected the first declaration (void) without evaluating the condition. Existing callers using theboolresult and subclasses overridingadd(): boolthen failed static analysis even with Collections 1/2 installed. That would regress compatibility for existing 1.x users. The resultingmethod.childReturnTypeerror in an existing subclass is non-ignorable, so adding an ignore annotation in Fastest would not address the consumer regression.The replacement puts the two implementations in separate files under
compat/. They still declare the same internal trait name, and only the matching file is loaded. Keeping these files outside the PSR-4 directories and the normal analysis roots avoids duplicate classmap entries and lets PHPStan resolve the active signature.Composer's
autoload.filesloads a small bootstrap that callsspl_autoload_register()with a callback dedicated to that trait. When the trait is requested, the callback reflects the parent's native return type and requires the appropriate implementation. Registering the callback instead of choosing the variant immediately keepsArrayCollectionunloaded until needed, preserving lazy dependency loading. The callback is prepended to the autoloader stack so it can resolve the trait before Composer, including with an authoritative classmap where neither variant is mapped.New tests cover construction, wrapping, identity, randomization, filtering, empty paths, native return types and the legacy deprecation. A separate workflow exercises Collections 1.2, 1.8, 2.0, 2.6, 3.0 and 3.1, including authoritative Composer autoloading, runtime and PHPStan checks for callers and subclasses, and the existing runner/Behat commands. The workflow uses PHPUnit 9.6 as a standalone PHAR so its Composer dependency on deep-copy does not prevent installing Collections 1.2; the XML runner and Behat preload that PHAR to access PHPUnit classes.