diff --git a/src/Cli/AcquiaCli.php b/src/Cli/AcquiaCli.php index d459553..e55928b 100644 --- a/src/Cli/AcquiaCli.php +++ b/src/Cli/AcquiaCli.php @@ -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( diff --git a/tests/AcquiaCliApplicationTest.php b/tests/AcquiaCliApplicationTest.php index 150adf7..31a8bfe 100644 --- a/tests/AcquiaCliApplicationTest.php +++ b/tests/AcquiaCliApplicationTest.php @@ -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'];