Hala's avatar
Level 3

Agent feature test

I'm doing feature test when i sent Agent user with headers and dd(new agent ()->platform) i got false , i checked the route using postman and it's all looks great how can i fix this issue ?

this is the test

    /** @test * */
public function app_version_api_return_404_for_not_exists_versions()
{
    $version=create(AppVersion::class);

   $response= $this->getJson("api/v1/check-update/{$version->id}/{$version->build}",['User-Agent'=>"Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko; googleweblight) Chrome/38.0.1025.166 Mobile Safari/535.1"]);
    $response->assertStatus(200);


}

CONTROLLER

public function index(Request $request)
{
    $agent=new Agent();
    dd($agent->platform());
   $version=AppVersion::findOrFail($request->version_id)->where('platform',$agent->platform());
}

}

platform

public function platform($userAgent = null) { return $this->findDetectionRulesAgainstUA(static::getPlatforms(), $userAgent); }

0 likes
6 replies
Hala's avatar
Level 3

it's from agent will return if the platform is ios or android

public function platform($userAgent = null) { return $this->findDetectionRulesAgainstUA(static::getPlatforms(), $userAgent); }

Sti3bas's avatar
Sti3bas
Best Answer
Level 53

@hala replace $agent=new Agent(); with $agent = app(Agent::class); (or app('agent');), or type-hint as a dependency in your action public function index(Request $request, Agent $agent).

1 like
Hala's avatar
Level 3

Would you please explain why when $agent was instance of Agent class was not working

Please or to participate in this conversation.