diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 710b5b8..f5c1d5d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,7 +39,7 @@ jobs: needs: [ install_dependencies ] strategy: matrix: - php-versions: [ "7.4", "8.0", "8.1", "8.2" ] + php-versions: [ "7.4", "8.0", "8.1", "8.2", "8.3" ] runs-on: ubuntu-latest @@ -69,4 +69,4 @@ jobs: run: composer install --prefer-dist --no-progress - name: Run test suite - run: composer run-script test \ No newline at end of file + run: composer run-script test diff --git a/src/Connection.php b/src/Connection.php index 7c1c85b..1fec7d5 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -33,7 +33,7 @@ class Connection private const TOKEN_URL = '/oauth/token'; - private const VERSION = '1.0.1'; + private const VERSION = '1.0.2'; /** @var Client|null */ private ?Client $client = null; @@ -59,6 +59,9 @@ class Connection /** @var string The URL as configured with the OAuth client */ private string $redirectUrl; + /** @var string The appendix for the user agent */ + private string $userAgentAppendix = ''; + /** @var mixed */ private $state = null; @@ -87,12 +90,14 @@ public function getClient(): Client $userAgent .= ' OAuth/2.0'; } + $userAgent .= " {$this->userAgentAppendix}"; + $this->client = new Client([ 'http_errors' => true, 'expect' => false, 'base_uri' => self::BASE_URL, 'headers' => [ - 'User-Agent' => $userAgent, + 'User-Agent' => trim($userAgent), ] ]); @@ -107,6 +112,17 @@ public function setClient(Client $client): void $this->client = $client; } + /** + * @param string $userAgentAppendix + * @return Connection + */ + public function setUserAgentAppendix(string $userAgentAppendix): Connection + { + $this->userAgentAppendix = $userAgentAppendix; + + return $this; + } + /** * @param string $clientId * @return Connection diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 1ac7589..8adcff4 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -23,7 +23,15 @@ public function testUserAgentIsSet(): void $connection = new Connection(); $this->assertEquals( - sprintf('Sendy/1.0.1 PHP/%s', phpversion()), + sprintf('Sendy/1.0.2 PHP/%s', phpversion()), + $connection->getClient()->getConfig('headers')['User-Agent'] + ); + + $connection = new Connection(); + $connection->setUserAgentAppendix('WooCommerce/6.2'); + + $this->assertEquals( + sprintf('Sendy/1.0.2 PHP/%s WooCommerce/6.2', phpversion()), $connection->getClient()->getConfig('headers')['User-Agent'] ); @@ -31,7 +39,7 @@ public function testUserAgentIsSet(): void $connection->setOauthClient(true); $this->assertEquals( - sprintf('Sendy/1.0.1 PHP/%s OAuth/2.0', phpversion()), + sprintf('Sendy/1.0.2 PHP/%s OAuth/2.0', phpversion()), $connection->getClient()->getConfig('headers')['User-Agent'] ); }