Skip to content

Commit

Permalink
Adds user agent string for Cli library. (#98)
Browse files Browse the repository at this point in the history
* Adds user agent string for Cli library.

* Adds test for user agent.

* Fixes trim stan error.
  • Loading branch information
typhonius authored Jun 22, 2020
1 parent 789d29c commit 34d42be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Cli/AcquiaCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ public function __construct(
throw new \Exception('No VERSION file');
}

// Configure global client options to set user agent.
$client->addOption('headers', [
'User-Agent' => sprintf("%s/%s (https://github.com/typhonius/acquia_cli)", self::NAME, $version)
]);

// Create application.
$this->setConfig($config);

$application = new Application(self::NAME, $version);

$application->getDefinition()->addOptions(
Expand Down
19 changes: 19 additions & 0 deletions tests/AcquiaCliApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ public function testClientOptions()
$this->assertSame($expectedQuery, $actualQuery);
}

public function testClientUserAgent()
{
$command = ['application:list'];

$this->execute($command);

$versionFile = sprintf('%s/VERSION', $this->root);
if ($file = @file_get_contents($versionFile)) {
$version = trim($file);
} else {
throw new \Exception('No VERSION file');
}
$expectedUserAgent = sprintf("%s/%s (https://github.com/typhonius/acquia_cli)", 'AcquiaCli', $version);

$actualOptions = $this->client->getOptions();
$actualUserAgent = $actualOptions['headers']['User-Agent'][0];
$this->assertSame($expectedUserAgent, $actualUserAgent);
}

public function testRealm()
{
$command = ['application:info', 'devcloud2', '--realm=devcloud'];
Expand Down

0 comments on commit 34d42be

Please sign in to comment.