Created
April 26, 2013 13:24
-
-
Save docteurklein/5467363 to your computer and use it in GitHub Desktop.
phpspec mock Symfony's request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param Symfony\Component\HttpFoundation\Request $request | |
* @param Symfony\Component\HttpFoundation\ParameterBag $bag | |
*/ | |
function let($request, $bag) | |
{ | |
$bag->get('id')->willReturn(1); | |
$request->query = $bag; | |
} |
Maybe it is a quirk of the version of mockery/PHPspec we are currently using but
$request->query = $mock_of_parameter_bag;
does not work.
Instead a colleague has told me that the following is needed
$request->getWrappedSubject()->query = $mock_of_parameter_bag;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Florian, as I tweeted, I am a little embarrassed because it is so obvious - but I have missed it for so long!
I am so used to working with APIs that have getters/setters that the thought of it being a public property that I could set never entered my mind.