Fix route:cache failing on signal webhook routes (Serialization of 'ReflectionMethod' is not allowed)#398
Conversation
Signal webhook route closures captured the ReflectionMethod instance, so php artisan route:cache failed with "Serialization of 'ReflectionMethod' is not allowed" for any app with a #[Webhook] signal method. Capture the method name instead.
b2fe9ca to
77d32d4
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #398 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 666 666
===========================================
Files 63 63
Lines 2266 2267 +1
===========================================
+ Hits 2266 2267 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes Laravel route:cache failures caused by webhook signal routes capturing a ReflectionMethod inside a closure (which is not serializable). It updates webhook route registration to capture only the signal method name (string) and adds a unit test that mirrors Laravel’s route caching serialization behavior.
Changes:
- Update signal webhook route closure to capture
$signalMethod(string) instead of aReflectionMethodinstance. - Invoke the signal method via the captured name to avoid serializing reflection objects during
route:cache. - Add a unit test that calls
prepareForSerialization()+serialize()on workflow webhook routes to ensure route caching compatibility.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Webhooks.php |
Avoids capturing ReflectionMethod in signal webhook route closures by capturing the method name string instead. |
tests/Unit/WebhooksTest.php |
Adds coverage ensuring workflow webhook routes can be prepared and serialized like php artisan route:cache does. |
|
Confirmed this also affected the v2 branch. The v2 fix is now released in |
Problem
With any workflow that has a
#[SignalMethod]+#[Webhook]method registered viaWebhooks::routes(),php artisan route:cachefails:Laravel serializes closure-based routes with
SerializableClosure(all supported versions, 9 through 13, do this inRoute::prepareForSerialization()), which serializes the closure's captured variables. The signal webhook closure captures theReflectionMethodinstance:and PHP refuses to serialize reflection objects. Since
route:cache/optimizeruns in most production deploys, adding the first#[Webhook]signal method breaks deployment. The start webhook closure is fine — it only captures the class-name string.Fix
Capture the method name (a string) instead of the
ReflectionMethod; the closure only ever used$method->getName().Test
testWebhookRoutesCanBeSerializedForRouteCachingmirrors whatroute:cachedoes (prepareForSerialization()+serialize()on each registered webhook route). It fails on master with the exception above and passes with this change.Note: the
v2branch has the same capture in itssrc/Webhooks.php, so this is worth porting there too.