jenssegers / jenssegers/agent

How to get device information by phpunit

Open
#115 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
4.9k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

I wrote below on phpunit.
public function testAccessAsiPhone()
{
$headers = [
'User-Agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
];
$this->withServerVariables($this->transformHeadersToServerVars($headers));
$this->visit('/')
->see('iPhone')
->see('iOS')
->see('Safari');
}
}

but, device informatons look like don't get.

I wrote like this on controller.
public function index(Request $request){
$device = $this->agent->device();
$platform = $this->agent->platform();
$browser = $this->agent->browser();
return Response::view('index',
[
'device' => $device,
'platform' => $platform,
'browser' => $browser
]
);
}

Is it not possible to get device informations by phpunit?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing testAccessAsiPhone with the shown User-Agent and compare its output with the controller's index(Request $request) entry point. Check whether the transformed server variables reach the agent's device, platform, and browser methods, and define done as those values being detected consistently in the test.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.