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

Serialize on mocked object throw error in PHP 7.4 #447

Open
alexander-schranz opened this issue Oct 18, 2019 · 5 comments
Open

Serialize on mocked object throw error in PHP 7.4 #447

alexander-schranz opened this issue Oct 18, 2019 · 5 comments

Comments

@alexander-schranz
Copy link
Contributor

alexander-schranz commented Oct 18, 2019

When in PHP 7.4 a mocked object get serialized e.g.:

$metadataMock = $this->prophesize(Test::class);
$metadata = $metadataMock->reveal();
// call some function I want to test:
$myClassToTest->test($metadata);
// which does do the following:
serialize($metadata)

The following exception is thrown:

Exception: Serialization of 'ReflectionParameter' is not allowed

Related PHP migration: https://www.php.net/manual/de/migration74.incompatible.php

@ciaranmcnulty
Copy link
Member

Why are you serialising the prophet before revealing? Can you expand on the use case?

@alexander-schranz
Copy link
Contributor Author

Sorry it is revealed updated the example.

@georgecoca
Copy link

Same here, after upgrading to PHP 7.4 the error came up. It worked just fine on PHP 7.2

$site = $this->prophesize(Site::class);
$branch = $this->prophesize(Branch::class);
$url = 'http://fake.url';

$event = new NewUrlAddressFound($site->reveal(), $branch->reveal(), $url);
$serialized = serialize($event);

Exception: Serialization of 'Closure' is not allowed

@alexander-schranz did you managed to solve the issue?

@alexander-schranz
Copy link
Contributor Author

@GEODeveloper I refractored the tests and avoided to mock that objects and created real instances of that objects. So I learned for myself avoid mocks where it is possible.

@georgecoca
Copy link

@alexander-schranz I ended doing that too, avoiding serializing mock objects. Thanks for your time!

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

3 participants