Skip to content

test: add failing tests for #126 — objects with __serialize and closure array properties#127

Draft
esetnik wants to merge 2 commits intolaravel:2.xfrom
esetnik:test/serialize-object-with-closure-array-properties
Draft

test: add failing tests for #126 — objects with __serialize and closure array properties#127
esetnik wants to merge 2 commits intolaravel:2.xfrom
esetnik:test/serialize-object-with-closure-array-properties

Conversation

@esetnik
Copy link

@esetnik esetnik commented Feb 24, 2026

Summary

Adds failing test cases for #126 — objects implementing __serialize that have closures in array properties (or other non-typed-Closure properties) fail to serialize since v2.0.9.

Tests added

Test Description
closure use variable referencing object with __serialize and closure array property Closure captures the object via use
closure bound to object with __serialize and closure array property Closure bound to the object via $this
closure use variable referencing object with __serialize preserves closure array values Round-trip preserving the closure array values

All 9 tests (3 cases × 3 serializers: Native, Signed, Unsigned) currently fail with Serialization of 'Closure' is not allowed.

phpunit.xml.dist fix

The new test file and the existing TypedClosurePropertyTest.php (added in #122) were both missing from phpunit.xml.dist, which uses explicit <file> entries rather than directory scanning. This meant those tests were never executed in CI. This PR adds both to a new serializer-regression test suite in the config.

Root cause

The wrapClosures() / mapByReference() change in #122 skips all objects with __serialize, so nested closures inside those objects are never wrapped with Native instances. When PHP later calls __serialize(), the raw \Closure values pass through and hit PHP's native serialization restriction.

Note: this is distinct from the TypedClosurePropertyTest cases which pass because ClassWithTypedClosureProperty manually wraps its closure in SerializableClosure inside __serialize(). The new fixture (ClassWithSerializeAndClosureArrayProperty) does not manually wrap — it just returns its properties as-is, which is the common case for user-defined classes that aren't aware of laravel/serializable-closure.

Ref: #126

esetnik and others added 2 commits February 24, 2026 12:09
…y properties

Objects implementing __serialize that have closures in array properties
(or other non-typed-Closure properties) fail to serialize since v2.0.9.

The wrapClosures/mapByReference change in laravel#122 skips all objects with
__serialize, so nested closures are never wrapped with Native instances.
When PHP later calls __serialize() on these objects, the raw Closure
values pass through and hit "Serialization of 'Closure' is not allowed".

These tests cover:
- Closure capturing such an object via use variable
- Closure bound to such an object via $this
- Round-trip preserving closure array values

All 9 tests (3 cases x 3 serializers) currently fail.

Ref: laravel#126
Co-authored-by: Cursor <cursoragent@cursor.com>
…d closure array properties

Objects implementing __serialize that have closures in array properties
(or other non-typed-Closure properties) fail to serialize since v2.0.9.

The wrapClosures/mapByReference change in laravel#122 skips all objects with
__serialize, so nested closures are never wrapped with Native instances.
When PHP later calls __serialize() on these objects, the raw Closure
values pass through and hit "Serialization of 'Closure' is not allowed".

These tests cover:
- Closure capturing such an object via use variable
- Closure bound to such an object via $this
- Round-trip preserving closure array values

All 9 tests (3 cases x 3 serializers) currently fail.

Also adds the existing TypedClosurePropertyTest and the new test to
phpunit.xml.dist so they are actually run in CI (previously both were
missing from the explicit file list).

Ref: laravel#126
Co-authored-by: Cursor <cursoragent@cursor.com>
@taylorotwell
Copy link
Member

Any suggestions on fix?

@taylorotwell taylorotwell marked this pull request as draft February 25, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants