Mocking functions with parameters passed by reference
Posted: Mon Dec 21, 2009 7:37 am
Hi there,
We've started unit testing our application with PHPUnit 1 month ago (meaning we're doing "test after", unfortunately).
The last trouble I'm running into is that there doesn't seem to be a way to mock values returned via
parameters passed by-reference.
For example, I can't mock the $user returned by getUser(&$user, $userId), where the first parameter is used
to return the user (the function's return type being a status code).
You can't do this with returnCallback() since values assigned to the parameters passed by ref. are lost...
Has anybody ran into this trouble and already found a workaround ?
(for now mine is using hand crafted stubs, but this becomes cumbersome very quickly)
Thanks in advance!
We've started unit testing our application with PHPUnit 1 month ago (meaning we're doing "test after", unfortunately).
The last trouble I'm running into is that there doesn't seem to be a way to mock values returned via
parameters passed by-reference.
For example, I can't mock the $user returned by getUser(&$user, $userId), where the first parameter is used
to return the user (the function's return type being a status code).
You can't do this with returnCallback() since values assigned to the parameters passed by ref. are lost...
Has anybody ran into this trouble and already found a workaround ?
(for now mine is using hand crafted stubs, but this becomes cumbersome very quickly)
Thanks in advance!