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

fixes serialization issue with enrollment class. #65

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

stopfstedt
Copy link
Member

@stopfstedt stopfstedt commented Nov 1, 2024

Running Moodle-core test coverage with this enrollment plugin integrated causes several failures, all with a Exception: Serialization of 'Closure' is not allowed.

Here is one example:

stefan@nichtsnutz: ~/dev/projects/moodle44 on MOODLE_404_STABLE[?]
$ vendor/bin/phpunit --filter=test_data_saved admin/tool/uploadcourse/tests/course_test.php
Moodle 4.4.4+ (Build: 20241101), 99b5729824524e0bdc6a64ff1b0e4423d1d4b37a
Php: 8.3.13, mysqli: 8.0.39, OS: Linux 6.8.0-48-generic x86_64
PHPUnit 9.6.18 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 00:44.495, Memory: 82.50 MB

There was 1 error:

1) tool_uploadcourse\course_test::test_data_saved
Exception: Serialization of 'Closure' is not allowed

/home/stefan/dev/projects/moodle44/cache/stores/static/lib.php:243
/home/stefan/dev/projects/moodle44/cache/stores/static/lib.php:338
/home/stefan/dev/projects/moodle44/cache/classes/loaders.php:903
/home/stefan/dev/projects/moodle44/cache/classes/loaders.php:826
/home/stefan/dev/projects/moodle44/admin/tool/uploadcourse/classes/helper.php:184
/home/stefan/dev/projects/moodle44/admin/tool/uploadcourse/classes/helper.php:161
/home/stefan/dev/projects/moodle44/admin/tool/uploadcourse/classes/course.php:821
/home/stefan/dev/projects/moodle44/admin/tool/uploadcourse/tests/course_test.php:535
/home/stefan/dev/projects/moodle44/lib/phpunit/classes/advanced_testcase.php:76

ERRORS!
Tests: 1, Assertions: 5, Errors: 1.

Using a step-through debugger, I was able to pinpoint the problem - the Ilios API client cannot be set as class member during serialization, since brings in closures of the underlying HTTP client (Guzzle).

See screenshot below with highlighted closures:

image

I'm side-stepping this issue by getting the client inside the only function that's actually using it. that get's around this problem since the methods in an object will not be saved, only the name of the class.

after the change/for comparison:

image

Copy link
Member

@jrjohnson jrjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple, works. ✅

@jrjohnson jrjohnson merged commit 7b07e07 into ilios:MOODLE_404_STABLE Nov 1, 2024
4 checks passed
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