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

Serialization of mocked objects in PHP 7.4 #1038

Open
okdewit opened this issue Feb 12, 2020 · 10 comments
Open

Serialization of mocked objects in PHP 7.4 #1038

okdewit opened this issue Feb 12, 2020 · 10 comments

Comments

@okdewit
Copy link

okdewit commented Feb 12, 2020

This snippet of code:

serialize(Mockery::mock(User::class))

works with Mockery 1.3.1, using PHP 7.3.
Using PHP 7.4, keeping all else equal, it gives the exception:

Exception : Serialization of 'ReflectionClass' is not allowed

I suspect it's because of the changes merged into 7.4 after this RFC:
https://wiki.php.net/rfc/custom_object_serialization
However, that RFC claims to not have any BC-breaking changes.

Is there something that can be done to remedy this from the side of Mockery, or should this be considered a core PHP bug?

@okdewit
Copy link
Author

okdewit commented Feb 12, 2020

I see this has been "fixed" in 7.4 RC1:
php/php-src@96da1fe

So I think this means mocks can not be serialized anymore.

@GrahamCampbell
Copy link
Contributor

Mockery could, if it really wanted, make its mocks serializable, at least naively, by making sure the mocks own usage of reflection stuff was restored using custom code. However, serializing of partial mocks or mocks that have reflection stuff as expected return values, etc, will need more care (and maybe should not be supported).

@lcaliani
Copy link

I having the same issue here when trying to execute some tests

Serialization of 'Reflection Class' is not allowed

Any leads?

@ITPL-Krunal
Copy link

Serialization of 'TYPO3\CMS\Extbase\Reflection\MethodReflection' is not allowed in typo3 8.7.8 with php 7.4

This error not come when we use php 7.2 so why come in php 7.4.

Any solution?

@over-engineer
Copy link

Any updates on this?

2 similar comments
@olsona-hologram
Copy link

Any updates on this?

@udidol
Copy link

udidol commented Aug 30, 2022

Any updates on this?

@alinpop
Copy link

alinpop commented May 10, 2023

For me it happens with \Exception used inside the test and only when

  • there is an error in the test
  • and combined with the usage of
    -- @runTestsInSeparateProcesses and
    -- @preserveGlobalState disabled.

If the test is correct, the error will not show.

If there is something wrong in the test, I disable @runTestsInSeparateProcesses / @preserveGlobalState disabled, I fix the tests and then enable those again.

@ciltocruz
Copy link

For me it happens with \Exception used inside the test and only when

  • there is an error in the test
  • and combined with the usage of
    -- @runTestsInSeparateProcesses and
    -- @preserveGlobalState disabled.

If the test is correct, the error will not show.

If there is something wrong in the test, I disable @runTestsInSeparateProcesses / @preserveGlobalState disabled, I fix the tests and then enable those again.

Same conditions for me

@Chi-teck
Copy link

Chi-teck commented Mar 13, 2024

Exception stacktrace may contain unseralizable objects like Closure or Reflection. Since PHP 7.4 you need to enable zend.exception_ignore_args setting in php.ini when running tests.

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

No branches or pull requests

10 participants