Commit ce4d8bb
committed
fix(modules): a self-registered class is no longer wired twice by a later scan
CodeRabbit found a real bug in the registerClass() I added, and it was mine.
register() did `$this->mappings = $this->scanner->scan($paths)` — assignment, not
merge. So a package that called registerClass() from its own provider had that
record thrown away the moment the framework's scan ran, which meant the
idempotency guard inside registerClass() had nothing left to see. If the scan
also found the class, it wired a second listener and the handler ran twice on
every event.
The order is not hypothetical. A package provider's register() runs whenever
Laravel gets to it, which may be before LifecycleEventProvider's — so the
sequence that breaks is the ordinary one, not a corner.
Proven before fixing, with the fixture registering both ways:
assertCount(1, $displaced)
Failed asserting that actual size 2 matches expected size 1
register() now merges into what is already there and skips a class already
registered for that event — the same guard addPaths() has always had, which is
where I should have looked before writing a second registration path.
./vendor/bin/pest --testsuite=Feature,Unit 267 -> 268 passed, 0 failed
./vendor/bin/pest --testsuite=Module 448 failed / 308 passed, unchanged
vendor/bin/pint --test pass
vendor/bin/phpstan analyse no errors
Co-Authored-By: Virgil <virgil@lethean.io>1 parent db5a6e2 commit ce4d8bb
2 files changed
Lines changed: 39 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
113 | 119 | | |
114 | | - | |
| 120 | + | |
115 | 121 | | |
116 | 122 | | |
117 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
209 | 237 | | |
0 commit comments