I am writing a php website using Symfony.
I am writing a module that listens for a FilterUserResponseEvent
object.
I would like to create a mock FilterUserResponseEvent
object that will contain a suitable request object that contains a cookie that I can set.
i.e. I would like to manufacture a suitable $event
variable to pass into the function below. I would like to be able to pre-define the result of $value = $request->cookies->get('cookie');
inside my test.
use FOS\UserBundle\Event\FilterUserResponseEvent;
public function onRegistrationCompleted(FilterUserResponseEvent $event)
{
$response = $event->getResponse();
$request = $event->getRequest();
// get cookie
$value = $request->cookies->get('cookie');
}
How could I do that? I am trying the following code
$request = new stdClass();
$request->cookies = new stdClass();
$request->cookies->get = function($key){
return 'cookie';
};
print( $request->cookies->get('asd'));
but it gives me this error:
Error: Call to undefined method stdClass::get()