faraz73's avatar

getting request paramiters in test

Hi, i'm passing a request in my test like so:

$response = $this->get(route('2factor.requestToken',[
            'email' => $email,
            'client' => 'android'
        ]));

and in a Facade i've write it code :

class ResponderFacade extends Facade
{
    protected static function getFacadeAccessor()
    {
        dump('here we go');
        dd(request()->all());
        if(request()->get('client') == 'android'){

            return AndroidResponses::class;

        }

        return VueResponses::class;
    }

}

Unfortunately i'm unable to get email & client values.

0 likes
6 replies
tisuchi's avatar

@faraz73 I believe, the problem is in your test, you're passing parameters as query parameters to a GET request. The parameters are passed as an associative array to the route function.

You're trying to access the parameters using request()->get('client') instead you use query.

For example:

class ResponderFacade extends Facade
{
    protected static function getFacadeAccessor()
    {
        dump('here we go');
        dd(request()->all());
        if(request()->query('client') == 'android'){
            return AndroidResponses::class;
        }

        return VueResponses::class;
    }
}
faraz73's avatar

@tisuch nope, request()->query('client') returns null too in this test

faraz73's avatar

all of these return null :

dump(request()->get('client'));// null
dump(request()->input('client'));//null
dump(request()->query('client'));//null
dd(request()->all()); // []
jaseofspades88's avatar

I would advise against using a request parameter inside of a facade class to choose the respective binding to resolve, just create a different facade.

jaseofspades88's avatar

Separation of concerns is important, @faraz73. I can't give you an example of something I've not done. I have never seen a facade class that does anything in getFacadeAccessor other than return a string. Consider the purpose of a facade, map to a container binding... why would you wish to add possible confusion to that process?

Please or to participate in this conversation.