Skip to content

Commit

Permalink
allow override User Agent from parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed Jul 21, 2017
1 parent bc67396 commit c6c18f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Service/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public function __construct(Client $client, $host, $prefix, $app_client)
*/
public function get($path, array $options = [])
{
$options['headers'] = isset($options['headers']) ? $options['headers'] : [];
$options['headers']['User-Agent'] = $this->app_client;
$options['headers'] = array_merge(
['User-Agent' => $this->app_client],
isset($options['headers']) ? $options['headers'] : []
);

$response = $this->client->request('GET', $this->host.$this->prefix.$path, $options);

Expand Down
24 changes: 23 additions & 1 deletion tests/Service/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,23 @@ protected function setUp()
$this->browser = new Browser($this->client, $this->host, $this->prefix, $this->app_client);
}

public function testGet()
/**
* @return array
*/
public function appClients()
{
return [
[''],
['Override User Agent'],
];
}

/**
* @dataProvider appClients
*
* @param string $app_client
*/
public function testGet($app_client)
{
$path = '/foo';
$params = ['bar' => 'baz'];
Expand All @@ -70,6 +86,12 @@ public function testGet()
'User-Agent' => $this->app_client,
],
];

if ($app_client) {
$options['headers']['User-Agent'] = $app_client;
$params['headers']['User-Agent'] = $app_client;
}

$expected = ['Hello, world!'];
$content = json_encode($expected);

Expand Down

0 comments on commit c6c18f9

Please sign in to comment.