Skip to content

Commit

Permalink
Merge pull request #293 from rtalvarez/add-url-configs
Browse files Browse the repository at this point in the history
Add api_url and login_url config options
  • Loading branch information
christensenep committed Oct 5, 2023
2 parents 257ce41 + 7385938 commit 68ccc74
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
10 changes: 0 additions & 10 deletions .phpstan/baseline.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Call to function is_string\\(\\) with stdClass will always evaluate to false\\.$#"
count: 2
path: ../src/Bigcommerce/Api/Client.php

-
message: "#^Method Bigcommerce\\\\Api\\\\Client\\:\\:createCoupon\\(\\) has parameter \\$object with no type specified\\.$#"
count: 1
Expand Down Expand Up @@ -500,11 +495,6 @@ parameters:
count: 1
path: ../src/Bigcommerce/Api/Filter.php

-
message: "#^Method Bigcommerce\\\\Api\\\\Filter\\:\\:__set\\(\\) has no return type specified\\.$#"
count: 1
path: ../src/Bigcommerce/Api/Filter.php

-
message: "#^Method Bigcommerce\\\\Api\\\\Filter\\:\\:__set\\(\\) has parameter \\$parameter with no type specified\\.$#"
count: 1
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"ext-curl": "*"
},
"require-dev": {
"codeless/jugglecode": "1.0",
"friendsofphp/php-cs-fixer": "^3.13",
"php-coveralls/php-coveralls": "2.5",
"phpunit/phpunit": "^9.5",
Expand Down
16 changes: 12 additions & 4 deletions src/Bigcommerce/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ public static function configureOAuth($settings)
throw new Exception("'store_hash' must be provided");
}

if (isset($settings['api_url'])) {
self::$api_url = $settings['api_url'];
}

if (isset($settings['login_url'])) {
self::$login_url = $settings['login_url'];
}

self::$client_id = $settings['client_id'];
self::$auth_token = $settings['auth_token'];
self::$store_hash = $settings['store_hash'];
Expand Down Expand Up @@ -390,8 +398,8 @@ private static function mapCollectionObject($object)
* Map a single object to a resource class.
*
* @param string $resource name of the resource class
* @param \stdClass $object
* @return Resource
* @param \stdClass|boolean|string $object
* @return bool|\stdClass|string
*/
private static function mapResource($resource, $object)
{
Expand All @@ -407,8 +415,8 @@ private static function mapResource($resource, $object)
/**
* Map object representing a count to an integer value.
*
* @param \stdClass $object
* @return int
* @param \stdClass|boolean|string $object
* @return int|boolean
*/
private static function mapCount($object)
{
Expand Down
18 changes: 18 additions & 0 deletions test/Unit/Api/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1084,4 +1084,22 @@ public function testUpdatingOptionValuePutsToTheOptionValueResource()

Client::updateOptionValue(1, 1, array());
}

public function testConnectionUsesApiUrlOverride()
{
$this->connection->expects($this->once())
->method('get')
->with('https://api.url.com/time');

Client::configureOAuth([
'client_id' => '123',
'auth_token' => '123xyz',
'store_hash' => 'abc123',
'api_url' => 'https://api.url.com',
'login_url' => 'https://login.url.com',
]);
Client::setConnection($this->connection); // re-set the connection since Client::setConnection unsets it

Client::getTime();
}
}

0 comments on commit 68ccc74

Please sign in to comment.