Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Aug 15, 2023
1 parent 44f6790 commit 16abe51
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ private static function _defaultHeaders($apiKey, $clientInfo = null)
'X-Stripe-Client-User-Agent' => \json_encode($ua),
'User-Agent' => $uaString,
'Authorization' => 'Bearer ' . $apiKey,
'Stripe-Version' => Stripe::getApiVersion(),
];
}

Expand Down Expand Up @@ -393,9 +394,6 @@ function ($key) use ($params) {
$absUrl = $this->_apiBase . $url;
$params = self::_encodeObjects($params);
$defaultHeaders = $this->_defaultHeaders($myApiKey, $clientUAInfo);
if (Stripe::$apiVersion) {
$defaultHeaders['Stripe-Version'] = Stripe::$apiVersion;
}

if (Stripe::$accountId) {
$defaultHeaders['Stripe-Account'] = Stripe::$accountId;
Expand Down
5 changes: 2 additions & 3 deletions lib/Stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Stripe
/** @var string The base URL for the Stripe API uploads endpoint. */
public static $apiUploadBase = 'https://files.stripe.com';

/** @var null|string The version of the Stripe API to use for requests. */
/** @var string The version of the Stripe API to use for requests. */
public static $apiVersion = \Stripe\Util\ApiVersion::CURRENT;

/** @var null|string The account ID for connected accounts requests. */
Expand Down Expand Up @@ -119,8 +119,7 @@ public static function setClientId($clientId)
}

/**
* @return string The API version used for requests. null if we're using the
* latest version.
* @return string The API version used for requests.
*/
public static function getApiVersion()
{
Expand Down
5 changes: 5 additions & 0 deletions tests/Stripe/ApiRequestorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public function testDefaultHeaders()
'Stripe/v1 PhpBindings/' . Stripe::VERSION . ' MyTestApp/1.2.34 (https://mytestapp.example)'
);

static::assertSame(
$headers['Stripe-Version'],
Stripe::getApiVersion()
);

static::assertSame($headers['Authorization'], 'Bearer ' . $apiKey);
}

Expand Down
2 changes: 0 additions & 2 deletions tests/TestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ protected function setUpConfig()
Stripe::$apiUploadBase = \defined('MOCK_URL') ? MOCK_URL : 'http://localhost:12111';
Stripe::setApiKey('sk_test_123');
Stripe::setClientId('ca_123');
Stripe::setApiVersion(null);
Stripe::setAccountId(null);

// Set up the HTTP client mocker
Expand All @@ -63,7 +62,6 @@ protected function tearDownConfig()
Stripe::setEnableTelemetry(false);
Stripe::setApiKey($this->origApiKey);
Stripe::setClientId($this->origClientId);
Stripe::setApiVersion($this->origApiVersion);
Stripe::setAccountId($this->origAccountId);
}

Expand Down

0 comments on commit 16abe51

Please sign in to comment.