Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] 5.8.29 tagged today breaks queue deserializing with Model::newCollection() #29196

Merged
merged 2 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ protected function restoreCollection($value)

$collection = $collection->keyBy->getKey();

return new EloquentCollection(
$collectionClass = get_class($collection);

return new $collectionClass(
collect($value->id)->map(function ($id) use ($collection) {
return $collection[$id];
})
Expand Down
30 changes: 30 additions & 0 deletions tests/Integration/Queue/ModelSerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,20 @@ public function test_it_serializes_a_collection_in_correct_order()
$this->assertEquals($unserialized->users->first()->email, '[email protected]');
$this->assertEquals($unserialized->users->last()->email, '[email protected]');
}

public function test_it_can_unserialize_custom_collection()
{
ModelSerializationTestCustomUser::create(['email' => '[email protected]']);
ModelSerializationTestCustomUser::create(['email' => '[email protected]']);

$serialized = serialize(new CollectionSerializationTestClass(
ModelSerializationTestCustomUser::all()
));

$unserialized = unserialize($serialized);

$this->assertInstanceOf(ModelSerializationTestCustomUserCollection::class, $unserialized->users);
}
}

class ModelSerializationTestUser extends Model
Expand All @@ -244,6 +258,22 @@ class ModelSerializationTestUser extends Model
public $timestamps = false;
}

class ModelSerializationTestCustomUserCollection extends Collection
{
}

class ModelSerializationTestCustomUser extends Model
{
public $table = 'users';
public $guarded = ['id'];
public $timestamps = false;

public function newCollection(array $models = [])
{
return new ModelSerializationTestCustomUserCollection($models);
}
}

class Order extends Model
{
public $guarded = ['id'];
Expand Down