Reputation: 283
I would like to test one controller that it has:
$deviceGet = strtolower($request->query->get('device'));
My question is: How can I mock it to test in my controller?
class SetDeviceListenerTest extends \PHPUnit_Framework_TestCase {
/**
* @test
* @dataProvider deviceGetCases
*/
public function shouldSetRequestDeviceWithDeviceGetOnMasterRequest(
?string $device
): void {
$request = $this->getRequestMock();
$request->expects($this->once())
->method('get')
->with('device')
->willReturn($device);
/* @var Request $request */
$request->server = new ServerBag();
$request->headers = new HeaderBag();
$event = $this->getEventMock();
$event->expects($this->once())
->method('isMasterRequest')
->willReturn(true);
It return error because
$request->expects($this->once())
->method('get')
->with('device')
->willReturn($device);
fails
thank you!!
Upvotes: 1
Views: 2028
Reputation: 283
I found the answer myself (I just needed a friend):
$request->query= new ParameterBag(['device'=>$device]);
Upvotes: 6