diff --git a/composer.json b/composer.json index 39a73f90..c00a2d4c 100644 --- a/composer.json +++ b/composer.json @@ -9,24 +9,24 @@ "ecommerce", "business" ], - "homepage": "http://developer.bigcommerce.com", + "homepage": "https://developer.bigcommerce.com", "license": "MIT", "authors": [ { "name": "Bigcommerce", - "homepage": "http://www.bigcommerce.com" + "homepage": "https://www.bigcommerce.com" } ], "require": { - "php": ">=7.0", + "php": ">=7.1", "firebase/php-jwt": "~3.0 || ~5.0", "ext-curl": "*" }, "require-dev": { "codeless/jugglecode": "1.0", - "friendsofphp/php-cs-fixer": "^2.13", - "php-coveralls/php-coveralls": "2.1", - "phpunit/phpunit": "^6.4 || ^7.4" + "friendsofphp/php-cs-fixer": "^3.13", + "php-coveralls/php-coveralls": "2.5", + "phpunit/phpunit": "^9.5" }, "autoload": { "psr-0": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index edaa9fbe..321bcb62 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,30 +1,22 @@ - - - - - - - - - - - test/ - - - - - src/ - - + + + + src/ + + + + + + + + + + + + + + test/ + + diff --git a/src/Bigcommerce/Api/Client.php b/src/Bigcommerce/Api/Client.php index 578ee540..22263756 100644 --- a/src/Bigcommerce/Api/Client.php +++ b/src/Bigcommerce/Api/Client.php @@ -353,7 +353,7 @@ private static function mapCollection($resource, $object) $baseResource = __NAMESPACE__ . '\\' . $resource; self::$resource = (class_exists($baseResource)) ? $baseResource : 'Bigcommerce\\Api\\Resources\\' . $resource; - return array_map(array('self', 'mapCollectionObject'), $object); + return array_map(array(self::class, 'mapCollectionObject'), $object); } /** diff --git a/src/Bigcommerce/Api/Connection.php b/src/Bigcommerce/Api/Connection.php index c333d677..ffe8a6fa 100644 --- a/src/Bigcommerce/Api/Connection.php +++ b/src/Bigcommerce/Api/Connection.php @@ -241,6 +241,16 @@ public function removeHeader($header) unset($this->headers[$header]); } + /** + * Return the request headers + * + * @return array + */ + public function getRequestHeaders() + { + return $this->headers; + } + /** * Get the MIME type that should be used for this request. * diff --git a/test/Unit/Api/ClientTest.php b/test/Unit/Api/ClientTest.php index b3d11da3..6af2cb05 100644 --- a/test/Unit/Api/ClientTest.php +++ b/test/Unit/Api/ClientTest.php @@ -14,7 +14,7 @@ class ClientTest extends TestCase private $connection; private $basePath = ''; - public function setUp() + public function setUp(): void { $methods = array( 'useXml', @@ -37,7 +37,7 @@ public function setUp() 'getHeaders', '__destruct' ); - $this->basePath = $this->getStaticAttribute('Bigcommerce\\Api\\Client', 'api_path'); + $this->basePath = Client::$api_path; $this->connection = $this->getMockBuilder('Bigcommerce\\Api\\Connection') ->disableOriginalConstructor() ->setMethods($methods) @@ -45,7 +45,7 @@ public function setUp() Client::setConnection($this->connection); } - public function tearDown() + public function tearDown(): void { Client::configure(array('username' => '', 'api_key' => '', 'store_url' => '')); unset($this->connection); @@ -138,7 +138,9 @@ public function testGetCustomerLoginTokenReturnsValidLoginToken() ); $token = Client::getCustomerLoginToken(1); $actualPayload = (array)\Firebase\JWT\JWT::decode($token, 'zyx', array('HS256')); - $this->assertArraySubset($expectedPayload, $actualPayload); + foreach ($expectedPayload as $value) { + $this->assertContains($value, $actualPayload); + } } public function testGetCustomerLoginTokenThrowsIfNoClientSecret() @@ -189,7 +191,7 @@ public function testGetCollectionReturnsCollectionOfSpecifiedTypes() Client::configure(array('store_url' => 'http://storeurl', 'username' => 'whatever', 'api_key' => 'whatever')); Client::setConnection($this->connection); // re-set the connection since Client::configure unsets it $resources = Client::getCollection('/whatever'); - $this->assertInternalType('array', $resources); + $this->assertIsArray($resources); foreach ($resources as $resource) { $this->assertInstanceOf('Bigcommerce\\Api\\Resource', $resource); } @@ -308,7 +310,7 @@ public function testGettingASpecificResourceReturnsACollectionOfThatResource($pa ->will($this->returnValue(array(array(), array()))); $collection = Client::$fnName(); - $this->assertInternalType('array', $collection); + $this->assertIsArray($collection); foreach ($collection as $resource) { $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\' . $class, $resource); } @@ -438,7 +440,7 @@ public function testGettingProductImagesReturnsCollectionOfProductImages() ->will($this->returnValue(array(array(), array()))); $collection = Client::getProductImages(1); - $this->assertInternalType('array', $collection); + $this->assertIsArray($collection); $this->assertContainsOnlyInstancesOf('Bigcommerce\\Api\\Resources\\ProductImage', $collection); } @@ -450,7 +452,7 @@ public function testGettingProductCustomFieldsReturnsCollectionOfProductCustomFi ->will($this->returnValue(array(array(), array()))); $collection = Client::getProductCustomFields(1); - $this->assertInternalType('array', $collection); + $this->assertIsArray($collection); foreach ($collection as $resource) { $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\ProductCustomField', $resource); } @@ -497,7 +499,7 @@ public function testGettingCustomerAddressesReturnsCollectionOfCustomerAddresses ->will($this->returnValue(array(array(), array()))); $collection = Client::getCustomerAddresses(1); - $this->assertInternalType('array', $collection); + $this->assertIsArray($collection); foreach ($collection as $resource) { $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Address', $resource); } @@ -511,7 +513,7 @@ public function testGettingOptionValuesReturnsCollectionOfOptionValues() ->will($this->returnValue(array(array(), array()))); $collection = Client::getOptionValues(); - $this->assertInternalType('array', $collection); + $this->assertIsArray($collection); foreach ($collection as $resource) { $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\OptionValue', $resource); } @@ -713,7 +715,7 @@ public function testGettingOrderProductsReturnsTheOrderProductsCollection() ->will($this->returnValue(array(array(), array()))); $collection = Client::getOrderProducts(1); - $this->assertInternalType('array', $collection); + $this->assertIsArray($collection); foreach ($collection as $resource) { $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\OrderProduct', $resource); } @@ -727,7 +729,7 @@ public function testGettingOrderShipmentsReturnsTheOrderShipmentsResource() ->will($this->returnValue(array(array(), array()))); $collection = Client::getShipments(1); - $this->assertInternalType('array', $collection); + $this->assertIsArray($collection); foreach ($collection as $resource) { $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Shipment', $resource); } @@ -788,7 +790,7 @@ public function testGettingOrderShippingAddressesReturnsTheAddressResource() ->will($this->returnValue(array(array(), array()))); $collection = Client::getOrderShippingAddresses(1); - $this->assertInternalType('array', $collection); + $this->assertIsArray($collection); foreach ($collection as $resource) { $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Address', $resource); } @@ -858,7 +860,7 @@ public function testGettingWebhooksReturnsAllWebhooks() ->with($this->basePath . '/hooks', false) ->will($this->returnValue(array(new \Bigcommerce\Api\Resource(),new \Bigcommerce\Api\Resource()))); $collection = Client::listWebhooks(); - $this->assertInternalType('array', $collection); + $this->assertIsArray($collection); foreach ($collection as $resource) { $this->assertInstanceOf('Bigcommerce\\Api\\Resource', $resource); } diff --git a/test/Unit/Api/ConnectionTest.php b/test/Unit/Api/ConnectionTest.php index 0d4a123a..c69a6b3e 100644 --- a/test/Unit/Api/ConnectionTest.php +++ b/test/Unit/Api/ConnectionTest.php @@ -12,23 +12,15 @@ class ConnectionTest extends TestCase */ protected $object; - public function setUp() + public function setUp(): void { $this->object = new Connection(); } - public function testFailOnError() - { - $this->object->failOnError(false); - $this->assertAttributeSame(false, 'failOnError', $this->object); - $this->object->failOnError(true); - $this->assertAttributeSame(true, 'failOnError', $this->object); - } - public function testAddHeader() { $this->object->addHeader('Content-Length', 4); - $this->assertAttributeContains('Content-Length: 4', 'headers', $this->object); + $this->assertContains('Content-Length: 4', $this->object->getRequestHeaders()); } /** @@ -38,6 +30,6 @@ public function testRemoveHeader() { $this->object->addHeader('Content-Length', 4); $this->object->removeHeader('Content-Length'); - $this->assertAttributeNotContains('Content-Length: 4', 'headers', $this->object); + $this->assertNotContains('Content-Length: 4', $this->object->getRequestHeaders()); } } diff --git a/test/Unit/Api/Resources/ProductTest.php b/test/Unit/Api/Resources/ProductTest.php index 8e7d136b..5c613dbd 100644 --- a/test/Unit/Api/Resources/ProductTest.php +++ b/test/Unit/Api/Resources/ProductTest.php @@ -63,7 +63,7 @@ public function testPropertyCollectionsPassThroughToTheConnection($property, $cl ->will($this->returnValue(array(array(), array()))); $collection = $product->$property; - $this->assertInternalType('array', $collection); + $this->assertIsArray($collection); foreach ($collection as $value) { $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\' . $className, $value); } diff --git a/test/Unit/Api/Resources/ResourceTestBase.php b/test/Unit/Api/Resources/ResourceTestBase.php index 4baeca9d..11987e29 100644 --- a/test/Unit/Api/Resources/ResourceTestBase.php +++ b/test/Unit/Api/Resources/ResourceTestBase.php @@ -13,7 +13,7 @@ class ResourceTestBase extends TestCase protected $connection; protected $basePath = ''; - public function setUp() + public function setUp(): void { $methods = array( 'useXml', @@ -40,7 +40,7 @@ public function setUp() ->disableOriginalConstructor() ->setMethods($methods) ->getMock(); - $this->basePath = $this->getStaticAttribute('Bigcommerce\\Api\\Client', 'api_path'); + $this->basePath = Client::$api_path; Client::setConnection($this->connection); } } diff --git a/test/Unit/Api/Resources/RuleTest.php b/test/Unit/Api/Resources/RuleTest.php index eeaabadc..5ada5a95 100644 --- a/test/Unit/Api/Resources/RuleTest.php +++ b/test/Unit/Api/Resources/RuleTest.php @@ -38,7 +38,7 @@ public function testConditionsPassesThroughToConnection() ->will($this->returnValue(array(array(), array()))); $collection = $rule->conditions; - $this->assertInternalType('array', $collection); + $this->assertIsArray($collection); foreach ($collection as $condition) { $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\RuleCondition', $condition); }