You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue was that later in the test, I was passing the mock as a constructor argument to the Class Under Test and then trying to serialize the CUT. I was getting the error: You cannot serialize or unserialize PDO instances
The thing is that MyClass did not have anything to do with the database, and neither did the CUT or any of its dependencies.
After a lot of debugging I found that the mock object had the instance of the exception stored as a data property a long way down the nested structure, and the exception itself had a trace property which included all of the global context from the test class, including the CakePHP fixture manager, which of course had a PDO instance inside it!
So this was really unexpected behaviour and after losing a few hours, in the end I could not use Phake to mock this class because of it.
I'm not sure if there is a solution to this. Perhaps Phake mocks could implement __sleep() in such a way as to exclude expected exceptions?
The text was updated successfully, but these errors were encountered:
I came across a bit of an edge-case in a test which touched the database. I was using a Phake mock as follows:
The issue was that later in the test, I was passing the mock as a constructor argument to the Class Under Test and then trying to serialize the CUT. I was getting the error:
You cannot serialize or unserialize PDO instances
The thing is that
MyClass
did not have anything to do with the database, and neither did the CUT or any of its dependencies.After a lot of debugging I found that the mock object had the instance of the exception stored as a data property a long way down the nested structure, and the exception itself had a
trace
property which included all of the global context from the test class, including the CakePHP fixture manager, which of course had a PDO instance inside it!So this was really unexpected behaviour and after losing a few hours, in the end I could not use Phake to mock this class because of it.
I'm not sure if there is a solution to this. Perhaps Phake mocks could implement
__sleep()
in such a way as to exclude expected exceptions?The text was updated successfully, but these errors were encountered: