Skip to content

Instantly share code, notes, and snippets.

@docteurklein
Created April 26, 2013 13:24
Show Gist options
  • Save docteurklein/5467363 to your computer and use it in GitHub Desktop.
Save docteurklein/5467363 to your computer and use it in GitHub Desktop.
phpspec mock Symfony's request
<?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;
}
@peterjmit
Copy link

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.

@peterjmit
Copy link

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