From ef9348e2895ef900a3b6dd01f6394240a9cc3d9b Mon Sep 17 00:00:00 2001 From: Ivan Shcherbak Date: Wed, 10 Jan 2024 10:16:35 +0200 Subject: [PATCH 1/9] Upgrade to php 8.1 Use phpunit:10 --- composer.json | 7 +- src/Bigcommerce/Api/Connection.php | 4 +- test/Unit/Api/ClientTest.php | 323 ++++++++---------- test/Unit/Api/ConnectionTest.php | 4 +- test/Unit/Api/ErrorTest.php | 4 +- test/Unit/Api/FilterTest.php | 8 +- test/Unit/Api/ResourceTest.php | 66 ++-- test/Unit/Api/Resources/BrandTest.php | 2 +- test/Unit/Api/Resources/CategoryTest.php | 4 +- test/Unit/Api/Resources/CouponTest.php | 2 +- test/Unit/Api/Resources/CurrencyTest.php | 10 +- test/Unit/Api/Resources/CustomerTest.php | 10 +- .../Api/Resources/OptionSetOptionTest.php | 8 +- test/Unit/Api/Resources/OptionSetTest.php | 8 +- test/Unit/Api/Resources/OptionTest.php | 6 +- test/Unit/Api/Resources/OptionValueTest.php | 10 +- test/Unit/Api/Resources/OrderTest.php | 30 +- test/Unit/Api/Resources/PageTest.php | 6 +- .../Api/Resources/ProductCustomFieldTest.php | 6 +- test/Unit/Api/Resources/ProductImageTest.php | 6 +- test/Unit/Api/Resources/ProductOptionTest.php | 6 +- test/Unit/Api/Resources/ProductTest.php | 47 +-- test/Unit/Api/Resources/RealTest.php | 0 test/Unit/Api/Resources/ResourceTestBase.php | 25 +- test/Unit/Api/Resources/RuleConditionTest.php | 4 +- test/Unit/Api/Resources/RuleTest.php | 17 +- test/Unit/Api/Resources/ShipmentTest.php | 8 +- .../Unit/Api/Resources/ShippingMethodTest.php | 51 +-- test/Unit/Api/Resources/ShippingZoneTest.php | 18 +- test/Unit/Api/Resources/SkuOptionTest.php | 8 +- test/Unit/Api/Resources/SkuTest.php | 12 +- 31 files changed, 273 insertions(+), 447 deletions(-) delete mode 100644 test/Unit/Api/Resources/RealTest.php diff --git a/composer.json b/composer.json index 6affced7..00fd016c 100644 --- a/composer.json +++ b/composer.json @@ -18,15 +18,16 @@ } ], "require": { - "php": ">=8.0", + "php": ">=8.1", "firebase/php-jwt": "~5.0 || ~6.0", "ext-curl": "*" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.13", "php-coveralls/php-coveralls": "2.5", - "phpunit/phpunit": "^9.5", - "phpstan/phpstan": "^1.10" + "phpunit/phpunit": "^10.0", + "phpstan/phpstan": "^1.10", + "rector/rector": "^0.19.0" }, "autoload": { "psr-0": { diff --git a/src/Bigcommerce/Api/Connection.php b/src/Bigcommerce/Api/Connection.php index a91f6585..707acac4 100644 --- a/src/Bigcommerce/Api/Connection.php +++ b/src/Bigcommerce/Api/Connection.php @@ -609,6 +609,8 @@ public function getHeaders() */ public function __destruct() { - curl_close($this->curl); + if ($this->curl !== null) { + curl_close($this->curl); + } } } diff --git a/test/Unit/Api/ClientTest.php b/test/Unit/Api/ClientTest.php index 0a3890f4..6491e5f6 100644 --- a/test/Unit/Api/ClientTest.php +++ b/test/Unit/Api/ClientTest.php @@ -16,38 +16,17 @@ class ClientTest extends TestCase public function setUp(): void { - $methods = array( - 'useXml', - 'failOnError', - 'authenticate', - 'setTimeout', - 'useProxy', - 'verifyPeer', - 'addHeader', - 'getLastError', - 'get', - 'post', - 'head', - 'put', - 'delete', - 'getStatus', - 'getStatusMessage', - 'getBody', - 'getHeader', - 'getHeaders', - '__destruct' - ); + $methods = ['useXml', 'failOnError', 'authenticate', 'setTimeout', 'useProxy', 'verifyPeer', 'addHeader', 'getLastError', 'get', 'post', 'head', 'put', 'delete', 'getStatus', 'getStatusMessage', 'getBody', 'getHeader', 'getHeaders', '__destruct']; $this->basePath = Client::$api_path; - $this->connection = $this->getMockBuilder('Bigcommerce\\Api\\Connection') + $this->connection = $this->getMockBuilder(\Bigcommerce\Api\Connection::class) ->disableOriginalConstructor() - ->setMethods($methods) ->getMock(); Client::setConnection($this->connection); } public function tearDown(): void { - Client::configure(array('username' => '', 'api_key' => '', 'store_url' => '')); + Client::configure(['username' => '', 'api_key' => '', 'store_url' => '']); unset($this->connection); } @@ -55,31 +34,31 @@ public function testConfigureRequiresStoreUrl() { $this->expectException('\\Exception'); $this->expectExceptionMessage("'store_url' must be provided"); - Client::configure(array('username' => 'whatever', 'api_key' => 'whatever')); + Client::configure(['username' => 'whatever', 'api_key' => 'whatever']); } public function testConfigureRequiresUsername() { $this->expectException('\\Exception'); $this->expectExceptionMessage("'username' must be provided"); - Client::configure(array('store_url' => 'whatever', 'api_key' => 'whatever')); + Client::configure(['store_url' => 'whatever', 'api_key' => 'whatever']); } public function testConfigureRequiresApiKey() { $this->expectException('\\Exception'); $this->expectExceptionMessage("'api_key' must be provided"); - Client::configure(array('username' => 'whatever', 'store_url' => 'whatever')); + Client::configure(['username' => 'whatever', 'store_url' => 'whatever']); } public function testFailOnErrorPassesThroughToConnection() { - $this->connection->expects($this->exactly(2)) - ->method('failOnError') - ->withConsecutive( - array(true), - array(false) - ); + $matcher = $this->exactly(2); + $this->connection->expects($matcher) + ->method('failOnError')->willReturnCallback(fn() => match ($matcher->numberOfInvocations()) { + 1 => [true], + 2 => [false], + }); Client::failOnError(true); Client::failOnError(false); } @@ -94,12 +73,12 @@ public function testUseXmlPassesThroughToConnection() public function testVerifyPeerPassesThroughToConnection() { - $this->connection->expects($this->exactly(2)) - ->method('verifyPeer') - ->withConsecutive( - array(true), - array(false) - ); + $matcher = $this->exactly(2); + $this->connection->expects($matcher) + ->method('verifyPeer')->willReturnCallback(fn() => match ($matcher->numberOfInvocations()) { + 1 => [true], + 2 => [false], + }); Client::verifyPeer(true); Client::verifyPeer(false); } @@ -124,18 +103,8 @@ public function testGetLastErrorGetsErrorFromConnection() public function testGetCustomerLoginTokenReturnsValidLoginToken() { - Client::configureOAuth(array( - 'client_id' => '123', - 'auth_token' => 'def', - 'store_hash' => 'abc', - 'client_secret' => 'zyx' - )); - $expectedPayload = array( - 'iss' => '123', - 'operation' => 'customer_login', - 'store_hash' => 'abc', - 'customer_id' => 1, - ); + Client::configureOAuth(['client_id' => '123', 'auth_token' => 'def', 'store_hash' => 'abc', 'client_secret' => 'zyx']); + $expectedPayload = ['iss' => '123', 'operation' => 'customer_login', 'store_hash' => 'abc', 'customer_id' => 1]; $token = Client::getCustomerLoginToken(1); $key = new \Firebase\JWT\Key('zyx', 'HS256'); $actualPayload = (array)\Firebase\JWT\JWT::decode($token, $key); @@ -146,11 +115,7 @@ public function testGetCustomerLoginTokenReturnsValidLoginToken() public function testGetCustomerLoginTokenThrowsIfNoClientSecret() { - Client::configureOAuth(array( - 'client_id' => '123', - 'auth_token' => 'def', - 'store_hash' => 'abc' - )); + Client::configureOAuth(['client_id' => '123', 'auth_token' => 'def', 'store_hash' => 'abc']); $this->expectException('\Exception'); $this->expectExceptionMessage('Cannot sign customer login tokens without a client secret'); Client::getCustomerLoginToken(1); @@ -161,12 +126,12 @@ public function testGetResourceReturnsSpecifiedType() $this->connection->expects($this->once()) ->method('get') ->with('http://storeurl' . $this->basePath . '/whatever', false) - ->will($this->returnValue(array(array()))); + ->will($this->returnValue([[]])); - Client::configure(array('store_url' => 'http://storeurl', 'username' => 'whatever', 'api_key' => 'whatever')); + Client::configure(['store_url' => 'http://storeurl', 'username' => 'whatever', 'api_key' => 'whatever']); Client::setConnection($this->connection); // re-set the connection since Client::configure unsets it $resource = Client::getResource('/whatever'); - $this->assertInstanceOf('Bigcommerce\\Api\\Resource', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resource::class, $resource); } public function testGetCountReturnsSpecifiedCount() @@ -174,9 +139,9 @@ public function testGetCountReturnsSpecifiedCount() $this->connection->expects($this->once()) ->method('get') ->with('http://storeurl' . $this->basePath . '/whatever', false) - ->will($this->returnValue((object)array('count' => 5))); + ->will($this->returnValue((object)['count' => 5])); - Client::configure(array('store_url' => 'http://storeurl', 'username' => 'whatever', 'api_key' => 'whatever')); + Client::configure(['store_url' => 'http://storeurl', 'username' => 'whatever', 'api_key' => 'whatever']); Client::setConnection($this->connection); // re-set the connection since Client::configure unsets it $count = Client::getCount('/whatever'); $this->assertSame(5, $count); @@ -187,26 +152,26 @@ public function testGetCollectionReturnsCollectionOfSpecifiedTypes() $this->connection->expects($this->once()) ->method('get') ->with('http://storeurl' . $this->basePath . '/whatever', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); - Client::configure(array('store_url' => 'http://storeurl', 'username' => 'whatever', 'api_key' => 'whatever')); + Client::configure(['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->assertIsArray($resources); foreach ($resources as $resource) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resource', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resource::class, $resource); } } public function testCreateResourcePostsToTheRightPlace() { - $new = array(rand() => rand()); + $new = [random_int(0, mt_getrandmax()) => random_int(0, mt_getrandmax())]; $this->connection->expects($this->once()) ->method('post') ->with('http://storeurl' . $this->basePath . '/whatever', (object)$new) ->will($this->returnValue($new)); - Client::configure(array('store_url' => 'http://storeurl', 'username' => 'whatever', 'api_key' => 'whatever')); + Client::configure(['store_url' => 'http://storeurl', 'username' => 'whatever', 'api_key' => 'whatever']); Client::setConnection($this->connection); // re-set the connection since Client::configure unsets it $result = Client::createResource('/whatever', $new); $this->assertSame($new, $result); @@ -214,13 +179,13 @@ public function testCreateResourcePostsToTheRightPlace() public function testUpdateResourcePutsToTheRightPlace() { - $update = array(rand() => rand()); + $update = [random_int(0, mt_getrandmax()) => random_int(0, mt_getrandmax())]; $this->connection->expects($this->once()) ->method('put') ->with('http://storeurl' . $this->basePath . '/whatever', (object)$update) ->will($this->returnValue($update)); - Client::configure(array('store_url' => 'http://storeurl', 'username' => 'whatever', 'api_key' => 'whatever')); + Client::configure(['store_url' => 'http://storeurl', 'username' => 'whatever', 'api_key' => 'whatever']); Client::setConnection($this->connection); // re-set the connection since Client::configure unsets it $result = Client::updateResource('/whatever', $update); $this->assertSame($update, $result); @@ -233,7 +198,7 @@ public function testDeleteResourceDeletesToTheRightPlace() ->with('http://storeurl' . $this->basePath . '/whatever') ->will($this->returnValue("Successfully deleted")); - Client::configure(array('store_url' => 'http://storeurl', 'username' => 'whatever', 'api_key' => 'whatever')); + Client::configure(['store_url' => 'http://storeurl', 'username' => 'whatever', 'api_key' => 'whatever']); Client::setConnection($this->connection); // re-set the connection since Client::configure unsets it $result = Client::deleteResource('/whatever'); $this->assertSame("Successfully deleted", $result); @@ -252,7 +217,7 @@ public function testGetTimeReturnsTheExpectedTime() public function testGetStoreReturnsTheResultBodyDirectly() { - $body = array(rand() => rand()); + $body = [random_int(0, mt_getrandmax()) => random_int(0, mt_getrandmax())]; $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/store') @@ -284,7 +249,7 @@ public function testGetRequestsRemainingRequestsTimeWhenNoValueAvailable() $this->assertSame(12345, Client::getRequestsRemaining()); } - public function collections() + public static function collections() { return [ // path function classname @@ -300,15 +265,13 @@ public function collections() ]; } - /** - * @dataProvider collections - */ + #[\PHPUnit\Framework\Attributes\DataProvider('collections')] public function testGettingASpecificResourceReturnsACollectionOfThatResource($path, $fnName, $class) { $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/' . $path, false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $collection = Client::$fnName(); $this->assertIsArray($collection); @@ -317,22 +280,20 @@ public function testGettingASpecificResourceReturnsACollectionOfThatResource($pa } } - /** - * @dataProvider collections - */ + #[\PHPUnit\Framework\Attributes\DataProvider('collections')] public function testGettingTheCountOfACollectionReturnsThatCollectionsCount($path, $fnName, $class) { $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/' . $path . '/count', false) - ->will($this->returnValue((object)array('count' => 7))); + ->will($this->returnValue((object)['count' => 7])); $fnName .= 'Count'; $count = Client::$fnName(); $this->assertSame(7, $count); } - public function resources() + public static function resources() { return [ // path function classname @@ -349,37 +310,31 @@ public function resources() ]; } - /** - * @dataProvider resources - */ + #[\PHPUnit\Framework\Attributes\DataProvider('resources')] public function testGettingASpecificResourceReturnsThatResource($path, $fnName, $class) { $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/' . $path . '/1', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $fnName = sprintf($fnName, 'get'); $resource = Client::$fnName(1); $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\' . $class, $resource); } - /** - * @dataProvider resources - */ + #[\PHPUnit\Framework\Attributes\DataProvider('resources')] public function testCreatingASpecificResourcePostsToThatResource($path, $fnName, $class) { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/' . $path, (object)array()); + ->with($this->basePath . '/' . $path, (object)[]); $fnName = sprintf($fnName, 'create'); - Client::$fnName(array()); + Client::$fnName([]); } - /** - * @dataProvider resources - */ + #[\PHPUnit\Framework\Attributes\DataProvider('resources')] public function testDeletingASpecificResourceDeletesToThatResource($path, $fnName, $class) { $this->connection->expects($this->once()) @@ -390,9 +345,7 @@ public function testDeletingASpecificResourceDeletesToThatResource($path, $fnNam Client::$fnName(1); } - /** - * @dataProvider resources - */ + #[\PHPUnit\Framework\Attributes\DataProvider('resources')] public function testUpdatingASpecificResourcePutsToThatResource($path, $fnName, $class) { $this->connection->expects($this->once()) @@ -400,7 +353,7 @@ public function testUpdatingASpecificResourcePutsToThatResource($path, $fnName, ->with($this->basePath . '/' . $path . '/1'); $fnName = sprintf($fnName, 'update'); - Client::$fnName(1, array()); + Client::$fnName(1, []); } // hand-test the Sku resource because of the wonky urls @@ -408,18 +361,18 @@ public function testCreatingASkuPostsToTheSkuResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/products/1/skus', (object)array()); + ->with($this->basePath . '/products/1/skus', (object)[]); - Client::createSku(1, array()); + Client::createSku(1, []); } public function testUpdatingASkuPutsToTheSkuResource() { $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/products/skus/1', (object)array()); + ->with($this->basePath . '/products/skus/1', (object)[]); - Client::updateSku(1, array()); + Client::updateSku(1, []); } public function testGettingProductGoogleProductSearch() @@ -427,10 +380,10 @@ public function testGettingProductGoogleProductSearch() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/products/1/googleproductsearch') - ->will($this->returnValue((object)array())); + ->will($this->returnValue((object)[])); $resource = Client::getGoogleProductSearch(1); - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\ProductGoogleProductSearch', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\ProductGoogleProductSearch::class, $resource); } public function testGettingProductImagesReturnsCollectionOfProductImages() @@ -438,11 +391,11 @@ public function testGettingProductImagesReturnsCollectionOfProductImages() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/products/1/images', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $collection = Client::getProductImages(1); $this->assertIsArray($collection); - $this->assertContainsOnlyInstancesOf('Bigcommerce\\Api\\Resources\\ProductImage', $collection); + $this->assertContainsOnlyInstancesOf(\Bigcommerce\Api\Resources\ProductImage::class, $collection); } public function testGettingProductCustomFieldsReturnsCollectionOfProductCustomFields() @@ -450,12 +403,12 @@ public function testGettingProductCustomFieldsReturnsCollectionOfProductCustomFi $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/products/1/custom_fields', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $collection = Client::getProductCustomFields(1); $this->assertIsArray($collection); foreach ($collection as $resource) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\ProductCustomField', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\ProductCustomField::class, $resource); } } @@ -464,10 +417,10 @@ public function testGettingASpecifiedProductImageReturnsThatProductImage() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/products/1/images/1', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $resource = Client::getProductImage(1, 1); - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\ProductImage', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\ProductImage::class, $resource); } public function testGettingASpecifiedProductCustomFieldReturnsThatProductCustomField() @@ -475,10 +428,10 @@ public function testGettingASpecifiedProductCustomFieldReturnsThatProductCustomF $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/products/1/custom_fields/1', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $resource = Client::getProductCustomField(1, 1); - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\ProductCustomField', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\ProductCustomField::class, $resource); } public function testGettingASpecifiedOptionValueReturnsThatOptionValue() @@ -486,10 +439,10 @@ public function testGettingASpecifiedOptionValueReturnsThatOptionValue() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/options/1/values/1', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $resource = Client::getOptionValue(1, 1); - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\OptionValue', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\OptionValue::class, $resource); } public function testGettingCustomerAddressesReturnsCollectionOfCustomerAddresses() @@ -497,12 +450,12 @@ public function testGettingCustomerAddressesReturnsCollectionOfCustomerAddresses $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/customers/1/addresses', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $collection = Client::getCustomerAddresses(1); $this->assertIsArray($collection); foreach ($collection as $resource) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Address', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Address::class, $resource); } } @@ -511,12 +464,12 @@ public function testGettingOptionValuesReturnsCollectionOfOptionValues() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/options/values', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $collection = Client::getOptionValues(); $this->assertIsArray($collection); foreach ($collection as $resource) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\OptionValue', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\OptionValue::class, $resource); } } @@ -524,63 +477,63 @@ public function testCreatingAnOptionSetPostsToTheOptionSetsResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/optionsets', (object)array()); + ->with($this->basePath . '/optionsets', (object)[]); - Client::createOptionSet(array()); + Client::createOptionSet([]); } public function testCreatingAnOptionPostsToTheOptionResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/options', (object)array()); + ->with($this->basePath . '/options', (object)[]); - Client::createOption(array()); + Client::createOption([]); } public function testCreatingAnOptionSetOptionPostsToTheOptionSetsOptionsResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/optionsets/1/options', (object)array()); + ->with($this->basePath . '/optionsets/1/options', (object)[]); - Client::createOptionSetOption(array(), 1); + Client::createOptionSetOption([], 1); } public function testCreatingAProductImagePostsToTheProductImageResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/products/1/images', (object)array()); + ->with($this->basePath . '/products/1/images', (object)[]); - Client::createProductImage(1, array()); + Client::createProductImage(1, []); } public function testCreatingAProductCustomFieldPostsToTheProductCustomFieldResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/products/1/custom_fields', (object)array()); + ->with($this->basePath . '/products/1/custom_fields', (object)[]); - Client::createProductCustomField(1, array()); + Client::createProductCustomField(1, []); } public function testUpdatingAProductImagePutsToTheProductImageResource() { $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/products/1/images/1', (object)array()); + ->with($this->basePath . '/products/1/images/1', (object)[]); - Client::updateProductImage(1, 1, array()); + Client::updateProductImage(1, 1, []); } public function testUpdatingAProductCustomFieldPutsToTheProductCustomFieldResource() { $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/products/1/custom_fields/1', (object)array()); + ->with($this->basePath . '/products/1/custom_fields/1', (object)[]); - Client::updateProductCustomField(1, 1, array()); + Client::updateProductCustomField(1, 1, []); } public function testDeletingAProductImageDeletesToTheProductImageResource() @@ -633,10 +586,10 @@ public function testGettingASpecifiedCouponReturnsThatCoupon() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/coupons/1', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $resource = Client::getCoupon(1); - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Coupon', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Coupon::class, $resource); } public function testGettingASpecifiedOrderStatusReturnsThatOrderStatus() @@ -644,10 +597,10 @@ public function testGettingASpecifiedOrderStatusReturnsThatOrderStatus() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/order_statuses/1', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $resource = Client::getOrderStatus(1); - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\OrderStatus', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\OrderStatus::class, $resource); } public function testDeletingAllOrdersDeletesToTheOrderResource() @@ -691,7 +644,7 @@ public function testGettingOrderProductsCountCountsToTheOrderProductsResource() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/orders/1/products/count', false) - ->will($this->returnValue((object)array('count' => 7))); + ->will($this->returnValue((object)['count' => 7])); $count = Client::getOrderProductsCount(1); $this->assertSame(7, $count); @@ -702,10 +655,10 @@ public function testGettingOrderShipmentReturnsTheOrderShipmentResource() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/orders/1/shipments/1', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $resource = Client::getShipment(1, 1); - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Shipment', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Shipment::class, $resource); } public function testGettingOrderProductsReturnsTheOrderProductsCollection() @@ -713,12 +666,12 @@ public function testGettingOrderProductsReturnsTheOrderProductsCollection() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/orders/1/products', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $collection = Client::getOrderProducts(1); $this->assertIsArray($collection); foreach ($collection as $resource) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\OrderProduct', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\OrderProduct::class, $resource); } } @@ -727,12 +680,12 @@ public function testGettingOrderShipmentsReturnsTheOrderShipmentsResource() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/orders/1/shipments', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $collection = Client::getShipments(1); $this->assertIsArray($collection); foreach ($collection as $resource) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Shipment', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Shipment::class, $resource); } } @@ -740,18 +693,18 @@ public function testCreatingOrderShipmentsPostsToTheOrderShipmentsResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/orders/1/shipments', (object)array()); + ->with($this->basePath . '/orders/1/shipments', (object)[]); - Client::createShipment(1, array()); + Client::createShipment(1, []); } public function testUpdatingOrderShipmentsPutsToTheOrderShipmentsResource() { $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/orders/1/shipments/1', (object)array()); + ->with($this->basePath . '/orders/1/shipments/1', (object)[]); - Client::updateShipment(1, 1, array()); + Client::updateShipment(1, 1, []); } public function testDeletingAllOrderShipmentsDeletesToTheOrderShipmentResource() @@ -777,10 +730,10 @@ public function testGettingOrderShippingAddressReturnsTheAddressResource() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/orders/1/shipping_addresses/1', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $resource = Client::getOrderShippingAddress(1, 1); - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Address', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Address::class, $resource); } public function testGettingOrderShippingAddressesReturnsTheAddressResource() @@ -788,12 +741,12 @@ public function testGettingOrderShippingAddressesReturnsTheAddressResource() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/orders/1/shipping_addresses', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $collection = Client::getOrderShippingAddresses(1); $this->assertIsArray($collection); foreach ($collection as $resource) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Address', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Address::class, $resource); } } @@ -801,9 +754,9 @@ public function testCreatingGiftCertificatePostsToTheGiftCertificateResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/gift_certificates', (object)array()); + ->with($this->basePath . '/gift_certificates', (object)[]); - Client::createGiftCertificate(array()); + Client::createGiftCertificate([]); } public function testGettingSpecifiedGiftCertificateReturnsTheSpecifiedGiftCertificate() @@ -811,7 +764,7 @@ public function testGettingSpecifiedGiftCertificateReturnsTheSpecifiedGiftCertif $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/gift_certificates/1', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); Client::getGiftCertificate(1); } @@ -821,7 +774,7 @@ public function testGettingGiftCertificatesReturnsTheGiftCertificates() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/gift_certificates', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); Client::getGiftCertificates(); } @@ -830,9 +783,9 @@ public function testUpdatingSpecifiedGiftCertificatePutsToTheSpecifiedGiftCertif { $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/gift_certificates/1', (object)array()); + ->with($this->basePath . '/gift_certificates/1', (object)[]); - Client::updateGiftCertificate(1, array()); + Client::updateGiftCertificate(1, []); } public function testDeletingSpecifiedGiftCertificateDeletesToTheSpecifiedGiftCertificateResource() @@ -859,11 +812,11 @@ public function testGettingWebhooksReturnsAllWebhooks() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/hooks', false) - ->will($this->returnValue(array(new \Bigcommerce\Api\Resource(),new \Bigcommerce\Api\Resource()))); + ->will($this->returnValue([new \Bigcommerce\Api\Resource(), new \Bigcommerce\Api\Resource()])); $collection = Client::listWebhooks(); $this->assertIsArray($collection); foreach ($collection as $resource) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resource', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resource::class, $resource); } } @@ -874,22 +827,22 @@ public function testGettingSpecifiedWebhookReturnsTheSpecifiedWebhook() ->with($this->basePath . '/hooks/1', false) ->will($this->returnValue(new \Bigcommerce\Api\Resource())); $resource = Client::getWebhook(1); - $this->assertInstanceOf('Bigcommerce\\Api\\Resource', $resource); + $this->assertInstanceOf(\Bigcommerce\Api\Resource::class, $resource); } public function testCreatingWebhookPostsToTheSpecifiedResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/hooks', (object)array()); - Client::createWebhook(array()); + ->with($this->basePath . '/hooks', (object)[]); + Client::createWebhook([]); } public function testUpdatingWebhookPutsToTheSpecifiedResource() { $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/hooks/1', (object)array()); - Client::updateWebhook(1, array()); + ->with($this->basePath . '/hooks/1', (object)[]); + Client::updateWebhook(1, []); } public function testDeleteWebhookDeletesToTheSpecifiedResource() @@ -904,27 +857,27 @@ public function testCreatingProductReviewPostsToTheProductReviewResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/products/1/reviews', (object)array()); + ->with($this->basePath . '/products/1/reviews', (object)[]); - Client::createProductReview(1, array()); + Client::createProductReview(1, []); } public function testCreatingProductBulkPricingRulesPostsToTheProductBulkPricingRulesResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/products/1/discount_rules', (object)array()); + ->with($this->basePath . '/products/1/discount_rules', (object)[]); - Client::createProductBulkPricingRules(1, array()); + Client::createProductBulkPricingRules(1, []); } public function testCreatingMarketingBannerPostsToTheMarketingBannerResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/banners', (object)array()); + ->with($this->basePath . '/banners', (object)[]); - Client::createMarketingBanner(array()); + Client::createMarketingBanner([]); } public function testGettingMarketingBannersReturnsTheMarketingBanners() @@ -932,7 +885,7 @@ public function testGettingMarketingBannersReturnsTheMarketingBanners() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/banners', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); Client::getMarketingBanners(); } @@ -959,36 +912,36 @@ public function testUpdatingMarketingBannerPutsToTheMarketingBannerResource() { $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/banners/1', (object)array()); + ->with($this->basePath . '/banners/1', (object)[]); - Client::updateMarketingBanner(1, array()); + Client::updateMarketingBanner(1, []); } public function testCreatingCustomerAddressPostsToTheCustomerAddressResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/customers/1/addresses', (object)array()); + ->with($this->basePath . '/customers/1/addresses', (object)[]); - Client::createCustomerAddress(1, array()); + Client::createCustomerAddress(1, []); } public function testCreatingProductRulePostsToTheProductRuleResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/products/1/rules', (object)array()); + ->with($this->basePath . '/products/1/rules', (object)[]); - Client::createProductRule(1, array()); + Client::createProductRule(1, []); } public function testCreatingCustomerGroupPostsToTheCustomerGroupResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/customer_groups', (object)array()); + ->with($this->basePath . '/customer_groups', (object)[]); - Client::createCustomerGroup(array()); + Client::createCustomerGroup([]); } public function testGettingASpecifiedCustomerGroupsReturnsTheCustomerGroups() @@ -996,7 +949,7 @@ public function testGettingASpecifiedCustomerGroupsReturnsTheCustomerGroups() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/customer_groups', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); Client::getCustomerGroups(); } @@ -1033,7 +986,7 @@ public function testGettingASpecifiedProductOptionsReturnsThoseProductOptions() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/products/1/options', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); Client::getProductOptions(1); } @@ -1043,7 +996,7 @@ public function testGettingASpecifiedProductOptionReturnsThatProductOption() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/products/1/options/1', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); Client::getProductOption(1, 1); } @@ -1053,7 +1006,7 @@ public function testGettingASpecifiedProductRuleReturnsThatProductRule() $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/products/1/rules/1', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); Client::getProductRule(1, 1); } @@ -1062,9 +1015,9 @@ public function testCreatingOptionValuePostsToTheOptionValueResource() { $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/options/1/values', (object)array()); + ->with($this->basePath . '/options/1/values', (object)[]); - Client::createOptionValue(1, array()); + Client::createOptionValue(1, []); } public function testDeletingAllOptionSetsDeletesToTheOptionSetsResource() @@ -1080,9 +1033,9 @@ public function testUpdatingOptionValuePutsToTheOptionValueResource() { $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/options/1/values/1', (object)array()); + ->with($this->basePath . '/options/1/values/1', (object)[]); - Client::updateOptionValue(1, 1, array()); + Client::updateOptionValue(1, 1, []); } public function testConnectionUsesApiUrlOverride() diff --git a/test/Unit/Api/ConnectionTest.php b/test/Unit/Api/ConnectionTest.php index c69a6b3e..047671c9 100644 --- a/test/Unit/Api/ConnectionTest.php +++ b/test/Unit/Api/ConnectionTest.php @@ -23,9 +23,7 @@ public function testAddHeader() $this->assertContains('Content-Length: 4', $this->object->getRequestHeaders()); } - /** - * @depends testAddHeader - */ + #[\PHPUnit\Framework\Attributes\Depends('testAddHeader')] public function testRemoveHeader() { $this->object->addHeader('Content-Length', 4); diff --git a/test/Unit/Api/ErrorTest.php b/test/Unit/Api/ErrorTest.php index 923013b0..e862438e 100644 --- a/test/Unit/Api/ErrorTest.php +++ b/test/Unit/Api/ErrorTest.php @@ -8,8 +8,8 @@ class ErrorTest extends TestCase { public function testConstructorHandlesArrayOfMessageObjects() { - $messageObj = (object)array('message' => 'message here'); - $error = new Error(array($messageObj), 0, []); + $messageObj = (object)['message' => 'message here']; + $error = new Error([$messageObj], 0, []); $this->assertSame('message here', $error->getMessage()); } diff --git a/test/Unit/Api/FilterTest.php b/test/Unit/Api/FilterTest.php index 7d976e5f..82ee9869 100644 --- a/test/Unit/Api/FilterTest.php +++ b/test/Unit/Api/FilterTest.php @@ -8,13 +8,13 @@ class FilterTest extends TestCase { public function testToQueryBuildsAnAppropriateQueryString() { - $filter = new Filter(array('a' => 1, 'b' => 'orange')); + $filter = new Filter(['a' => 1, 'b' => 'orange']); $this->assertSame('?a=1&b=orange', $filter->toQuery()); } public function testUpdateParameter() { - $filter = new Filter(array('a' => 'b')); + $filter = new Filter(['a' => 'b']); $this->assertSame('?a=b', $filter->toQuery()); $filter->a = 'c'; $this->assertSame('?a=c', $filter->toQuery()); @@ -28,14 +28,14 @@ public function testStaticCreateMethodAssumesIntegerParameterIsPageNumber() public function testStaticCreateMethodReturnsFilterObjectIfCalledWithFilterObject() { - $original = new Filter(array('a' => 'b')); + $original = new Filter(['a' => 'b']); $filter = Filter::create($original); $this->assertSame($original, $filter); } public function testStaticCreateMethodReturnsCorrectlyConfiguredFilter() { - $filter = Filter::create(array('a' => 'b')); + $filter = Filter::create(['a' => 'b']); $this->assertSame('?a=b', $filter->toQuery()); } } diff --git a/test/Unit/Api/ResourceTest.php b/test/Unit/Api/ResourceTest.php index cb3f1a48..bfdd853c 100644 --- a/test/Unit/Api/ResourceTest.php +++ b/test/Unit/Api/ResourceTest.php @@ -8,91 +8,67 @@ class ResourceTest extends TestCase { public function testGetCreateFieldsReturnsAllFieldsNotMarkedIgnore() { - $product = new Resource((object)array( - 'date_created' => 'abc123', - 'id' => 1 - )); + $product = new Resource((object)['date_created' => 'abc123', 'id' => 1]); - $this->setProtectedProperty($product, 'ignoreOnCreate', array('date_created')); + $this->setProtectedProperty($product, 'ignoreOnCreate', ['date_created']); - $this->assertEquals((object)array('id' => 1), $product->getCreateFields()); + $this->assertEquals((object)['id' => 1], $product->getCreateFields()); } public function testGetUpdateFieldsReturnsAllFieldsNotMarkedIgnore() { - $product = new Resource((object)array( - 'id' => 1, - 'custom_url' => '/whatever/' - )); + $product = new Resource((object)['id' => 1, 'custom_url' => '/whatever/']); - $this->setProtectedProperty($product, 'ignoreOnUpdate', array('id')); + $this->setProtectedProperty($product, 'ignoreOnUpdate', ['id']); - $this->assertEquals((object)array('custom_url' => '/whatever/'), $product->getUpdateFields()); + $this->assertEquals((object)['custom_url' => '/whatever/'], $product->getUpdateFields()); } public function testGetUpdateFieldsIgnoresNullFields() { - $product = new Resource((object)array( - 'id' => 1, - 'custom_url' => '/whatever/', - 'ignored' => null, - )); + $product = new Resource((object)['id' => 1, 'custom_url' => '/whatever/', 'ignored' => null]); - $this->setProtectedProperty($product, 'ignoreOnUpdate', array('id')); + $this->setProtectedProperty($product, 'ignoreOnUpdate', ['id']); - $this->assertEquals((object)array('custom_url' => '/whatever/'), $product->getUpdateFields()); + $this->assertEquals((object)['custom_url' => '/whatever/'], $product->getUpdateFields()); } public function testGetUpdateFieldsIgnoresEmptyDateFields() { - $product = new Resource((object)array( - 'id' => 1, - 'date_created' => '2015', - 'date_updated' => '', - )); + $product = new Resource((object)['id' => 1, 'date_created' => '2015', 'date_updated' => '']); - $this->setProtectedProperty($product, 'ignoreOnUpdate', array('id')); + $this->setProtectedProperty($product, 'ignoreOnUpdate', ['id']); - $this->assertEquals((object)array('date_created' => '2015'), $product->getUpdateFields()); + $this->assertEquals((object)['date_created' => '2015'], $product->getUpdateFields()); } public function testGetUpdateFieldsIgnoresFieldsThatAreForbiddenToBeZeroWhenZero() { - $product = new Resource((object)array( - 'id' => 1, - 'custom_url' => '/whatever/', - 'cannot_be_zero' => 0, - )); + $product = new Resource((object)['id' => 1, 'custom_url' => '/whatever/', 'cannot_be_zero' => 0]); - $this->setProtectedProperty($product, 'ignoreOnUpdate', array('id')); - $this->setProtectedProperty($product, 'ignoreIfZero', array('cannot_be_zero')); + $this->setProtectedProperty($product, 'ignoreOnUpdate', ['id']); + $this->setProtectedProperty($product, 'ignoreIfZero', ['cannot_be_zero']); - $this->assertEquals((object)array('custom_url' => '/whatever/'), $product->getUpdateFields()); + $this->assertEquals((object)['custom_url' => '/whatever/'], $product->getUpdateFields()); } public function testConstructorUnwrapsArrays() { - $product = new Resource(array((object)array( - 'id' => 1 - ))); + $product = new Resource([(object)['id' => 1]]); $this->assertSame(1, $product->id); } public function testMagicGetReturnsAssignedValue() { - $product = new Resource((object)array( - 'custom_url' => '/whatever/' - )); + $product = new Resource((object)['custom_url' => '/whatever/']); $this->assertSame('/whatever/', $product->custom_url); } public function testMagicSetUpdatesAssignedValue() { - $product = new Resource((object)array( - 'custom_url' => '/whatever/' - )); + $product = new Resource((object)['custom_url' => '/whatever/']); $this->assertSame('/whatever/', $product->custom_url); $product->custom_url = '/other'; @@ -101,9 +77,7 @@ public function testMagicSetUpdatesAssignedValue() public function testMagicIssetCorrectlyFindsFields() { - $product = new Resource((object)array( - 'custom_url' => '/whatever/' - )); + $product = new Resource((object)['custom_url' => '/whatever/']); $this->assertTrue(isset($product->custom_url)); $this->assertFalse(isset($product->id)); diff --git a/test/Unit/Api/Resources/BrandTest.php b/test/Unit/Api/Resources/BrandTest.php index 3585f3d7..5331dc28 100644 --- a/test/Unit/Api/Resources/BrandTest.php +++ b/test/Unit/Api/Resources/BrandTest.php @@ -18,7 +18,7 @@ public function testCreatePassesThroughToConnection() public function testUpdatePassesThroughToConnection() { - $brand = new Brand((object)(array('id' => 1))); + $brand = new Brand((object)(['id' => 1])); $this->connection->expects($this->once()) ->method('put') ->with($this->basePath . '/brands/1', $brand->getUpdateFields()); diff --git a/test/Unit/Api/Resources/CategoryTest.php b/test/Unit/Api/Resources/CategoryTest.php index 896bfdf5..50bc1b4e 100644 --- a/test/Unit/Api/Resources/CategoryTest.php +++ b/test/Unit/Api/Resources/CategoryTest.php @@ -18,7 +18,7 @@ public function testCreatePassesThroughToConnection() public function testUpdatePassesThroughToConnection() { - $category = new Category((object)(array('id' => 1))); + $category = new Category((object)(['id' => 1])); $this->connection->expects($this->once()) ->method('put') ->with($this->basePath . '/categories/1', $category->getUpdateFields()); @@ -28,7 +28,7 @@ public function testUpdatePassesThroughToConnection() public function testDeletePassesThroughToConnection() { - $category = new Category((object)(array('id' => 1))); + $category = new Category((object)(['id' => 1])); $this->connection->expects($this->once()) ->method('delete') ->with($this->basePath . '/categories/1'); diff --git a/test/Unit/Api/Resources/CouponTest.php b/test/Unit/Api/Resources/CouponTest.php index ab9082dc..85a16db2 100644 --- a/test/Unit/Api/Resources/CouponTest.php +++ b/test/Unit/Api/Resources/CouponTest.php @@ -18,7 +18,7 @@ public function testCreatePassesThroughToConnection() public function testUpdatePassesThroughToConnection() { - $coupon = new Coupon((object)(array('id' => 1))); + $coupon = new Coupon((object)(['id' => 1])); $this->connection->expects($this->once()) ->method('put') ->with($this->basePath . '/coupons/1', $coupon->getUpdateFields()); diff --git a/test/Unit/Api/Resources/CurrencyTest.php b/test/Unit/Api/Resources/CurrencyTest.php index 05421da0..56cbb5f0 100644 --- a/test/Unit/Api/Resources/CurrencyTest.php +++ b/test/Unit/Api/Resources/CurrencyTest.php @@ -8,27 +8,27 @@ class CurrencyTest extends ResourceTestBase { public function testCreatePassesThroughToConnection() { - $currency = new Currency((object)array('id' => 1)); + $currency = new Currency((object)['id' => 1]); $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/currencies', (object)array('id' => 1)); + ->with($this->basePath . '/currencies', (object)['id' => 1]); $currency->create(); } public function testUpdatePassesThroughToConnection() { - $currency = new Currency((object)array('id' => 1)); + $currency = new Currency((object)['id' => 1]); $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/currencies/1', (object)array()); + ->with($this->basePath . '/currencies/1', (object)[]); $currency->update(); } public function testDeletePassesThroughToConnection() { - $currency = new Currency((object)array('id' => 1)); + $currency = new Currency((object)['id' => 1]); $this->connection->expects($this->once()) ->method('delete') ->with($this->basePath . '/currencies/1'); diff --git a/test/Unit/Api/Resources/CustomerTest.php b/test/Unit/Api/Resources/CustomerTest.php index 7ef8805b..785d6e69 100644 --- a/test/Unit/Api/Resources/CustomerTest.php +++ b/test/Unit/Api/Resources/CustomerTest.php @@ -8,14 +8,14 @@ class CustomerTest extends ResourceTestBase { public function testAddressesPassesThroughToConnection() { - $customer = new Customer((object)array('addresses' => (object)array('resource' => '/customers/1/addresses'))); + $customer = new Customer((object)['addresses' => (object)['resource' => '/customers/1/addresses']]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/customers/1/addresses') - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); foreach ($customer->addresses as $address) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Address', $address); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Address::class, $address); } } @@ -31,7 +31,7 @@ public function testCreatePassesThroughToConnection() public function testUpdatePassesThroughToConnection() { - $customer = new Customer((object)(array('id' => 1))); + $customer = new Customer((object)(['id' => 1])); $this->connection->expects($this->once()) ->method('put') ->with($this->basePath . '/customers/1', $customer->getUpdateFields()); @@ -41,7 +41,7 @@ public function testUpdatePassesThroughToConnection() public function testDeletePassesThroughToConnection() { - $customer = new Customer((object)(array('id' => 1))); + $customer = new Customer((object)(['id' => 1])); $this->connection->expects($this->once()) ->method('delete') ->with($this->basePath . '/customers/1'); diff --git a/test/Unit/Api/Resources/OptionSetOptionTest.php b/test/Unit/Api/Resources/OptionSetOptionTest.php index 76b840cc..70d7a171 100644 --- a/test/Unit/Api/Resources/OptionSetOptionTest.php +++ b/test/Unit/Api/Resources/OptionSetOptionTest.php @@ -8,13 +8,13 @@ class OptionSetOptionTest extends ResourceTestBase { public function testOptionPassesThroughToConnection() { - $optionsetoption = new OptionSetOption((object)array('option' => (object)array('resource' => '/options/1'))); + $optionsetoption = new OptionSetOption((object)['option' => (object)['resource' => '/options/1']]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/options/1') - ->will($this->returnValue(array(array()))); + ->will($this->returnValue([[]])); - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Option', $optionsetoption->option); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Option::class, $optionsetoption->option); } public function testCreatePassesThroughToConnection() @@ -29,7 +29,7 @@ public function testCreatePassesThroughToConnection() public function testUpdatePassesThroughToConnection() { - $optionsetoption = new OptionSetOption((object)(array('id' => 1))); + $optionsetoption = new OptionSetOption((object)(['id' => 1])); $this->connection->expects($this->once()) ->method('put') ->with($this->basePath . '/optionsets/options/1', $optionsetoption->getUpdateFields()); diff --git a/test/Unit/Api/Resources/OptionSetTest.php b/test/Unit/Api/Resources/OptionSetTest.php index 0a83a804..566c244b 100644 --- a/test/Unit/Api/Resources/OptionSetTest.php +++ b/test/Unit/Api/Resources/OptionSetTest.php @@ -8,14 +8,14 @@ class OptionSetTest extends ResourceTestBase { public function testOptionsPassesThroughToConnection() { - $optionset = new OptionSet((object)array('options' => (object)array('resource' => '/optionsets/1/options'))); + $optionset = new OptionSet((object)['options' => (object)['resource' => '/optionsets/1/options']]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/optionsets/1/options') - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); foreach ($optionset->options as $value) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\OptionSetOption', $value); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\OptionSetOption::class, $value); } } @@ -31,7 +31,7 @@ public function testCreatePassesThroughToConnection() public function testUpdatePassesThroughToConnection() { - $optionset = new OptionSet((object)array('id' => 1)); + $optionset = new OptionSet((object)['id' => 1]); $this->connection->expects($this->once()) ->method('put') ->with($this->basePath . '/optionsets/1', $optionset->getUpdateFields()); diff --git a/test/Unit/Api/Resources/OptionTest.php b/test/Unit/Api/Resources/OptionTest.php index 3d850de5..c76fabd9 100644 --- a/test/Unit/Api/Resources/OptionTest.php +++ b/test/Unit/Api/Resources/OptionTest.php @@ -8,14 +8,14 @@ class OptionTest extends ResourceTestBase { public function testValuesPassesThroughToConnection() { - $option = new Option((object)array('values' => (object)array('resource' => '/options/1/values'))); + $option = new Option((object)['values' => (object)['resource' => '/options/1/values']]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/options/1/values') - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); foreach ($option->values as $value) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\OptionValue', $value); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\OptionValue::class, $value); } } } diff --git a/test/Unit/Api/Resources/OptionValueTest.php b/test/Unit/Api/Resources/OptionValueTest.php index 4fc66094..9acdd384 100644 --- a/test/Unit/Api/Resources/OptionValueTest.php +++ b/test/Unit/Api/Resources/OptionValueTest.php @@ -8,18 +8,18 @@ class OptionValueTest extends ResourceTestBase { public function testOptionPassesThroughToConnection() { - $optionValue = new OptionValue((object)array('option_id' => 1)); + $optionValue = new OptionValue((object)['option_id' => 1]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/options/1') - ->will($this->returnValue(array(array()))); + ->will($this->returnValue([[]])); - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Option', $optionValue->option); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Option::class, $optionValue->option); } public function testCreatePassesThroughToConnection() { - $optionValue = new OptionValue((object)array('option_id' => 1)); + $optionValue = new OptionValue((object)['option_id' => 1]); $this->connection->expects($this->once()) ->method('post') ->with($this->basePath . '/options/1/values', $optionValue->getCreateFields()); @@ -29,7 +29,7 @@ public function testCreatePassesThroughToConnection() public function testUpdatePassesThroughToConnection() { - $optionValue = new OptionValue((object)array('id' => 1, 'option_id' => 1)); + $optionValue = new OptionValue((object)['id' => 1, 'option_id' => 1]); $this->connection->expects($this->once()) ->method('put') ->with($this->basePath . '/options/1/values/1', $optionValue->getUpdateFields()); diff --git a/test/Unit/Api/Resources/OrderTest.php b/test/Unit/Api/Resources/OrderTest.php index 7198d2e9..fdc28b2d 100644 --- a/test/Unit/Api/Resources/OrderTest.php +++ b/test/Unit/Api/Resources/OrderTest.php @@ -8,65 +8,63 @@ class OrderTest extends ResourceTestBase { public function testUpdatePassesThroughToConnection() { - $order = new Order((object)(array('id' => 1, 'status_id' => 5, 'is_deleted' => false))); + $order = new Order((object)(['id' => 1, 'status_id' => 5, 'is_deleted' => false])); $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/orders/1', (object)array('status_id' => 5, 'is_deleted' => false)); + ->with($this->basePath . '/orders/1', (object)['status_id' => 5, 'is_deleted' => false]); $order->update(); } public function testShipmentsPassesThroughToConnection() { - $order = new Order((object)array('id' => 1)); + $order = new Order((object)['id' => 1]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/orders/1/shipments', false) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); foreach ($order->shipments as $shipment) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Shipment', $shipment); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Shipment::class, $shipment); } } public function testProductsPassesThroughToConnection() { - $order = new Order((object)array('products' => (object)array('resource' => '/orders/1/products'))); + $order = new Order((object)['products' => (object)['resource' => '/orders/1/products']]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/orders/1/products') - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); foreach ($order->products as $product) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\OrderProduct', $product); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\OrderProduct::class, $product); } } public function testShippingAddressesPassesThroughToConnection() { - $order = new Order((object)array( - 'shipping_addresses' => (object)array('resource' => '/orders/1/shippingaddresses') - )); + $order = new Order((object)['shipping_addresses' => (object)['resource' => '/orders/1/shippingaddresses']]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/orders/1/shippingaddresses') - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); foreach ($order->shipping_addresses as $address) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Address', $address); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Address::class, $address); } } public function testCouponsPassesThroughToConnection() { - $order = new Order((object)array('coupons' => (object)array('resource' => '/orders/1/coupons'))); + $order = new Order((object)['coupons' => (object)['resource' => '/orders/1/coupons']]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/orders/1/coupons') - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); foreach ($order->coupons as $coupon) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Coupon', $coupon); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Coupon::class, $coupon); } } } diff --git a/test/Unit/Api/Resources/PageTest.php b/test/Unit/Api/Resources/PageTest.php index bd730c48..bbed6620 100644 --- a/test/Unit/Api/Resources/PageTest.php +++ b/test/Unit/Api/Resources/PageTest.php @@ -19,7 +19,7 @@ public function testGetAllPassesThroughToConnection() public function testGetPassesThroughToConnection() { - $page = new Page((object)(array('id' => 1))); + $page = new Page((object)(['id' => 1])); $this->connection->expects($this->once()) ->method('get') @@ -40,7 +40,7 @@ public function testCreatePassesThroughToConnection() public function testUpdatePassesThroughToConnection() { - $page = new Page((object)(array('id' => 1))); + $page = new Page((object)(['id' => 1])); $this->connection->expects($this->once()) ->method('put') ->with($this->basePath . '/pages/1', $page->getUpdateFields()); @@ -50,7 +50,7 @@ public function testUpdatePassesThroughToConnection() public function testDeletePassesThroughToConnection() { - $page = new Page((object)(array('id' => 1))); + $page = new Page((object)(['id' => 1])); $this->connection->expects($this->once()) ->method('delete') ->with($this->basePath . '/pages/1'); diff --git a/test/Unit/Api/Resources/ProductCustomFieldTest.php b/test/Unit/Api/Resources/ProductCustomFieldTest.php index 6f192ad6..880ec777 100644 --- a/test/Unit/Api/Resources/ProductCustomFieldTest.php +++ b/test/Unit/Api/Resources/ProductCustomFieldTest.php @@ -8,7 +8,7 @@ class ProductCustomFieldTest extends ResourceTestBase { public function testCreatePassesThroughToConnection() { - $customField = new ProductCustomField((object)array('product_id' => 1)); + $customField = new ProductCustomField((object)['product_id' => 1]); $this->connection->expects($this->once()) ->method('post') ->with($this->basePath . '/products/1/customfields', $customField->getCreateFields()); @@ -18,7 +18,7 @@ public function testCreatePassesThroughToConnection() public function testUpdatePassesThroughToConnection() { - $customField = new ProductCustomField((object)(array('id' => 1, 'product_id' => 1))); + $customField = new ProductCustomField((object)(['id' => 1, 'product_id' => 1])); $this->connection->expects($this->once()) ->method('put') ->with($this->basePath . '/products/1/customfields/1', $customField->getUpdateFields()); @@ -28,7 +28,7 @@ public function testUpdatePassesThroughToConnection() public function testDeletePassesThroughToConnection() { - $customField = new ProductCustomField((object)(array('id' => 1, 'product_id' => 1))); + $customField = new ProductCustomField((object)(['id' => 1, 'product_id' => 1])); $this->connection->expects($this->once()) ->method('delete') ->with($this->basePath . '/products/1/customfields/1'); diff --git a/test/Unit/Api/Resources/ProductImageTest.php b/test/Unit/Api/Resources/ProductImageTest.php index 87055945..9e2b12cd 100644 --- a/test/Unit/Api/Resources/ProductImageTest.php +++ b/test/Unit/Api/Resources/ProductImageTest.php @@ -8,7 +8,7 @@ class ProductImageTest extends ResourceTestBase { public function testCreatePassesThroughToConnection() { - $productImage = new ProductImage((object)array('product_id' => 1)); + $productImage = new ProductImage((object)['product_id' => 1]); $this->connection->expects($this->once()) ->method('post') ->with($this->basePath . '/products/1/images', $productImage->getCreateFields()); @@ -18,7 +18,7 @@ public function testCreatePassesThroughToConnection() public function testUpdatePassesThroughToConnection() { - $productImage = new ProductImage((object)(array('id' => 1, 'product_id' => 1))); + $productImage = new ProductImage((object)(['id' => 1, 'product_id' => 1])); $this->connection->expects($this->once()) ->method('put') ->with($this->basePath . '/products/1/images/1', $productImage->getUpdateFields()); @@ -28,7 +28,7 @@ public function testUpdatePassesThroughToConnection() public function testDeletePassesThroughToConnection() { - $productImage = new ProductImage((object)(array('id' => 1, 'product_id' => 1))); + $productImage = new ProductImage((object)(['id' => 1, 'product_id' => 1])); $this->connection->expects($this->once()) ->method('delete') ->with($this->basePath . '/products/1/images/1'); diff --git a/test/Unit/Api/Resources/ProductOptionTest.php b/test/Unit/Api/Resources/ProductOptionTest.php index 2e550dbf..46b5a86e 100644 --- a/test/Unit/Api/Resources/ProductOptionTest.php +++ b/test/Unit/Api/Resources/ProductOptionTest.php @@ -8,12 +8,12 @@ class ProductOptionTest extends ResourceTestBase { public function testValuesPassesThroughToConnection() { - $productOption = new ProductOption((object)array('option_id' => 1)); + $productOption = new ProductOption((object)['option_id' => 1]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/options/1') - ->will($this->returnValue(array(array()))); + ->will($this->returnValue([[]])); - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Option', $productOption->option); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\Option::class, $productOption->option); } } diff --git a/test/Unit/Api/Resources/ProductTest.php b/test/Unit/Api/Resources/ProductTest.php index 5c613dbd..353df941 100644 --- a/test/Unit/Api/Resources/ProductTest.php +++ b/test/Unit/Api/Resources/ProductTest.php @@ -8,27 +8,27 @@ class ProductTest extends ResourceTestBase { public function testCreatePassesThroughToConnection() { - $product = new Product((object)array('id' => 1)); + $product = new Product((object)['id' => 1]); $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/products', (object)array('id' => 1)); + ->with($this->basePath . '/products', (object)['id' => 1]); $product->create(); } public function testUpdatePassesThroughToConnection() { - $product = new Product((object)array('id' => 1)); + $product = new Product((object)['id' => 1]); $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/products/1', (object)array()); + ->with($this->basePath . '/products/1', (object)[]); $product->update(); } public function testDeletePassesThroughToConnection() { - $product = new Product((object)array('id' => 1)); + $product = new Product((object)['id' => 1]); $this->connection->expects($this->once()) ->method('delete') ->with($this->basePath . '/products/1'); @@ -36,31 +36,20 @@ public function testDeletePassesThroughToConnection() $product->delete(); } - public function propertyCollections() + public static function propertyCollections() { - return array( - array('images', 'ProductImage'), - array('skus', 'Sku'), - array('rules', 'Rule'), - array('videos', 'ProductVideo'), - array('custom_fields', 'ProductCustomField'), - array('configurable_fields', 'ProductConfigurableField'), - array('discount_rules', 'DiscountRule'), - array('options', 'ProductOption') - ); + return [['images', 'ProductImage'], ['skus', 'Sku'], ['rules', 'Rule'], ['videos', 'ProductVideo'], ['custom_fields', 'ProductCustomField'], ['configurable_fields', 'ProductConfigurableField'], ['discount_rules', 'DiscountRule'], ['options', 'ProductOption']]; } - /** - * @dataProvider propertyCollections - */ + #[\PHPUnit\Framework\Attributes\DataProvider('propertyCollections')] public function testPropertyCollectionsPassThroughToTheConnection($property, $className) { $url = '/products/1/' . $property; - $product = new Product((object)array('id' => 1, $property => (object)array('resource' => $url))); + $product = new Product((object)['id' => 1, $property => (object)['resource' => $url]]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . $url) - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $collection = $product->$property; $this->assertIsArray($collection); @@ -69,26 +58,20 @@ public function testPropertyCollectionsPassThroughToTheConnection($property, $cl } } - public function properties() + public static function properties() { - return array( - array('brand', 'Brand'), - array('option_set', 'OptionSet'), - array('tax_class', 'TaxClass') - ); + return [['brand', 'Brand'], ['option_set', 'OptionSet'], ['tax_class', 'TaxClass']]; } - /** - * @dataProvider properties - */ + #[\PHPUnit\Framework\Attributes\DataProvider('properties')] public function testPropertiesPassThroughToTheConnection($property, $className) { $url = '/products/1/' . $property; - $product = new Product((object)array($property => (object)array('resource' => $url))); + $product = new Product((object)[$property => (object)['resource' => $url]]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . $url) - ->will($this->returnValue(array(array()))); + ->will($this->returnValue([[]])); $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\' . $className, $product->$property); } diff --git a/test/Unit/Api/Resources/RealTest.php b/test/Unit/Api/Resources/RealTest.php deleted file mode 100644 index e69de29b..00000000 diff --git a/test/Unit/Api/Resources/ResourceTestBase.php b/test/Unit/Api/Resources/ResourceTestBase.php index 11987e29..9d259b8d 100644 --- a/test/Unit/Api/Resources/ResourceTestBase.php +++ b/test/Unit/Api/Resources/ResourceTestBase.php @@ -15,30 +15,9 @@ class ResourceTestBase extends TestCase public function setUp(): void { - $methods = array( - 'useXml', - 'failOnError', - 'authenticate', - 'setTimeout', - 'useProxy', - 'verifyPeer', - 'addHeader', - 'getLastError', - 'get', - 'post', - 'head', - 'put', - 'delete', - 'getStatus', - 'getStatusMessage', - 'getBody', - 'getHeader', - 'getHeaders', - '__destruct' - ); - $this->connection = $this->getMockBuilder('Bigcommerce\\Api\\Connection') + $methods = ['useXml', 'failOnError', 'authenticate', 'setTimeout', 'useProxy', 'verifyPeer', 'addHeader', 'getLastError', 'get', 'post', 'head', 'put', 'delete', 'getStatus', 'getStatusMessage', 'getBody', 'getHeader', 'getHeaders', '__destruct']; + $this->connection = $this->getMockBuilder(\Bigcommerce\Api\Connection::class) ->disableOriginalConstructor() - ->setMethods($methods) ->getMock(); $this->basePath = Client::$api_path; Client::setConnection($this->connection); diff --git a/test/Unit/Api/Resources/RuleConditionTest.php b/test/Unit/Api/Resources/RuleConditionTest.php index 18f572d6..4b2fd6d3 100644 --- a/test/Unit/Api/Resources/RuleConditionTest.php +++ b/test/Unit/Api/Resources/RuleConditionTest.php @@ -8,7 +8,7 @@ class RuleConditionTest extends ResourceTestBase { public function testCreatePassesThroughToConnection() { - $ruleCondition = new RuleCondition((object)array('rule_id' => 1)); + $ruleCondition = new RuleCondition((object)['rule_id' => 1]); $ruleCondition->product_id = 1; $this->connection->expects($this->once()) ->method('post') @@ -19,7 +19,7 @@ public function testCreatePassesThroughToConnection() public function testUpdatePassesThroughToConnection() { - $ruleCondition = new RuleCondition((object)array('id' => 1, 'rule_id' => 1)); + $ruleCondition = new RuleCondition((object)['id' => 1, 'rule_id' => 1]); $ruleCondition->product_id = 1; $this->connection->expects($this->once()) ->method('put') diff --git a/test/Unit/Api/Resources/RuleTest.php b/test/Unit/Api/Resources/RuleTest.php index 5ada5a95..6efe76b1 100644 --- a/test/Unit/Api/Resources/RuleTest.php +++ b/test/Unit/Api/Resources/RuleTest.php @@ -8,39 +8,36 @@ class RuleTest extends ResourceTestBase { public function testCreatePassesThroughToConnection() { - $rule = new Rule((object)array('id' => 1, 'product_id' => 1)); + $rule = new Rule((object)['id' => 1, 'product_id' => 1]); $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/products/1/rules', (object)array()); + ->with($this->basePath . '/products/1/rules', (object)[]); $rule->create(); } public function testUpdatePassesThroughToConnection() { - $rule = new Rule((object)array('id' => 1, 'product_id' => 1)); + $rule = new Rule((object)['id' => 1, 'product_id' => 1]); $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/products/1/rules/1', (object)array()); + ->with($this->basePath . '/products/1/rules/1', (object)[]); $rule->update(); } public function testConditionsPassesThroughToConnection() { - $rule = new Rule((object)array( - 'product_id' => 1, - 'conditions' => (object)array('resource' => '/products/1/rules/1/conditions') - )); + $rule = new Rule((object)['product_id' => 1, 'conditions' => (object)['resource' => '/products/1/rules/1/conditions']]); $this->connection->expects($this->once()) ->method('get') ->with($this->basePath . '/products/1/rules/1/conditions') - ->will($this->returnValue(array(array(), array()))); + ->will($this->returnValue([[], []])); $collection = $rule->conditions; $this->assertIsArray($collection); foreach ($collection as $condition) { - $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\RuleCondition', $condition); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\RuleCondition::class, $condition); } } } diff --git a/test/Unit/Api/Resources/ShipmentTest.php b/test/Unit/Api/Resources/ShipmentTest.php index 2c3bfec4..70f15260 100644 --- a/test/Unit/Api/Resources/ShipmentTest.php +++ b/test/Unit/Api/Resources/ShipmentTest.php @@ -8,20 +8,20 @@ class ShipmentTest extends ResourceTestBase { public function testCreatePassesThroughToConnection() { - $shipment = new Shipment((object)array('id' => 1, 'order_id' => 1)); + $shipment = new Shipment((object)['id' => 1, 'order_id' => 1]); $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/orders/1/shipments', (object)array()); + ->with($this->basePath . '/orders/1/shipments', (object)[]); $shipment->create(); } public function testUpdatePassesThroughToConnection() { - $shipment = new Shipment((object)array('id' => 1, 'order_id' => 1)); + $shipment = new Shipment((object)['id' => 1, 'order_id' => 1]); $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/orders/1/shipments/1', (object)array()); + ->with($this->basePath . '/orders/1/shipments/1', (object)[]); $shipment->update(); } diff --git a/test/Unit/Api/Resources/ShippingMethodTest.php b/test/Unit/Api/Resources/ShippingMethodTest.php index 4afbdacb..dab33cce 100644 --- a/test/Unit/Api/Resources/ShippingMethodTest.php +++ b/test/Unit/Api/Resources/ShippingMethodTest.php @@ -9,37 +9,7 @@ class ShippingMethodTest extends ResourceTestBase { public function testCreateShippingMethod() { - $input = array( - "name" => "USPS Endicia", - "type" => "endicia", - "settings" => array( - "carrier_options" => array( - "delivery_services" => array( - "PriorityExpress", - "PriorityMailExpressInternational", - "FirstClassPackageInternationalService", - "Priority", - "PriorityMailInternational", - "First", - "ParcelSelect", - "MediaMail" - ), - "packaging" => array( - "FlatRateLegalEnvelope", - "FlatRatePaddedEnvelope", - "Parcel", - "SmallFlatRateBox", - "MediumFlatRateBox", - "LargeFlatRateBox", - "FlatRateEnvelope", - "RegionalRateBoxA", - "RegionalRateBoxB" - ), - "show_transit_time" => true, - ) - ), - "enabled" => true - ); + $input = ["name" => "USPS Endicia", "type" => "endicia", "settings" => ["carrier_options" => ["delivery_services" => ["PriorityExpress", "PriorityMailExpressInternational", "FirstClassPackageInternationalService", "Priority", "PriorityMailInternational", "First", "ParcelSelect", "MediaMail"], "packaging" => ["FlatRateLegalEnvelope", "FlatRatePaddedEnvelope", "Parcel", "SmallFlatRateBox", "MediumFlatRateBox", "LargeFlatRateBox", "FlatRateEnvelope", "RegionalRateBoxA", "RegionalRateBoxB"], "show_transit_time" => true]], "enabled" => true]; $method = new ShippingMethod((object)$input); $this->connection->expects($this->once()) ->method('post') @@ -50,23 +20,8 @@ public function testCreateShippingMethod() public function testUpdateShippingMethod() { - $input = array( - "name" => "Ship by Weight", - "type" => "weight", - "settings" => array( - "default_cost" => 1, - "default_cost_type" => "fixed_amount", - "range" => array( - array( - "lower_limit" => 0, - "upper_limit" => 20, - "shipping_cost" => 8 - ) - ) - ), - "enabled" => true - ); - $updateResource = array_merge(array('id' => 1), $input); + $input = ["name" => "Ship by Weight", "type" => "weight", "settings" => ["default_cost" => 1, "default_cost_type" => "fixed_amount", "range" => [["lower_limit" => 0, "upper_limit" => 20, "shipping_cost" => 8]]], "enabled" => true]; + $updateResource = array_merge(['id' => 1], $input); $method = new ShippingMethod((object)$updateResource); $this->connection->expects($this->once()) ->method('put') diff --git a/test/Unit/Api/Resources/ShippingZoneTest.php b/test/Unit/Api/Resources/ShippingZoneTest.php index 29d20dd3..0fb84184 100644 --- a/test/Unit/Api/Resources/ShippingZoneTest.php +++ b/test/Unit/Api/Resources/ShippingZoneTest.php @@ -9,13 +9,7 @@ class ShippingZoneTest extends ResourceTestBase { public function testCreateShippingZone() { - $input = array( - 'name' => 'United States', - 'type' => 'country', - 'locations' => array( - array('country_iso2' => 'US'), - ), - ); + $input = ['name' => 'United States', 'type' => 'country', 'locations' => [['country_iso2' => 'US']]]; $zone = new ShippingZone((object)$input); $this->connection->expects($this->once()) ->method('post') @@ -26,14 +20,8 @@ public function testCreateShippingZone() public function testUpdateShippingZone() { - $input = array( - 'name' => 'United States', - 'type' => 'country', - 'locations' => array( - array('country_iso2' => 'US'), - ), - ); - $updateResource = array_merge(array('id' => 1), $input); + $input = ['name' => 'United States', 'type' => 'country', 'locations' => [['country_iso2' => 'US']]]; + $updateResource = array_merge(['id' => 1], $input); $zone = new ShippingZone((object)$updateResource); $this->connection->expects($this->once()) diff --git a/test/Unit/Api/Resources/SkuOptionTest.php b/test/Unit/Api/Resources/SkuOptionTest.php index 03e2bfa8..f101d3a5 100644 --- a/test/Unit/Api/Resources/SkuOptionTest.php +++ b/test/Unit/Api/Resources/SkuOptionTest.php @@ -8,20 +8,20 @@ class SkuOptionTest extends ResourceTestBase { public function testCreatePassesThroughToConnection() { - $skuoption = new SkuOption((object)array('id' => 1, 'sku_id' => 1, 'product_id' => 1)); + $skuoption = new SkuOption((object)['id' => 1, 'sku_id' => 1, 'product_id' => 1]); $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/products/1/skus/1/options', (object)array('sku_id' => 1, 'product_id' => 1)); + ->with($this->basePath . '/products/1/skus/1/options', (object)['sku_id' => 1, 'product_id' => 1]); $skuoption->create(); } public function testUpdatePassesThroughToConnection() { - $skuoption = new SkuOption((object)array('id' => 1, 'sku_id' => 1, 'product_id' => 1)); + $skuoption = new SkuOption((object)['id' => 1, 'sku_id' => 1, 'product_id' => 1]); $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/products/1/skus/1/options/1', (object)array('product_id' => 1)); + ->with($this->basePath . '/products/1/skus/1/options/1', (object)['product_id' => 1]); $skuoption->update(); } diff --git a/test/Unit/Api/Resources/SkuTest.php b/test/Unit/Api/Resources/SkuTest.php index f73fee14..f05374ea 100644 --- a/test/Unit/Api/Resources/SkuTest.php +++ b/test/Unit/Api/Resources/SkuTest.php @@ -12,7 +12,7 @@ public function testCreatePassesThroughToConnection() $sku = $this->getSimpleSku(); $this->connection->expects($this->once()) ->method('post') - ->with($this->basePath . '/products/1/skus', (object)array('id' => 1)); + ->with($this->basePath . '/products/1/skus', (object)['id' => 1]); $sku->create(); } @@ -22,18 +22,16 @@ public function testUpdatePassesThroughToConnection() $sku = $sku = $this->getSimpleSku(); $this->connection->expects($this->once()) ->method('put') - ->with($this->basePath . '/products/1/skus/1', (object)array()); + ->with($this->basePath . '/products/1/skus/1', (object)[]); $sku->update(); } public function testSkuHasOptions() { - $sku = new Sku((object)array('id' => 1, 'product_id' => 1, 'options' => array( - array('option_value_id' => 1, 'product_option_id' => 1) - ))); + $sku = new Sku((object)['id' => 1, 'product_id' => 1, 'options' => [['option_value_id' => 1, 'product_option_id' => 1]]]); - $this->assertInstanceOf('Bigcommerce\Api\Resources\SkuOption', $sku->options[0]); + $this->assertInstanceOf(\Bigcommerce\Api\Resources\SkuOption::class, $sku->options[0]); $this->assertEquals(1, $sku->options[0]->option_value_id); $this->assertEquals(1, $sku->options[0]->product_option_id); @@ -47,6 +45,6 @@ public function testSkuHasNoOptions() private function getSimpleSku() { - return new Sku((object)array('id' => 1, 'product_id' => 1)); + return new Sku((object)['id' => 1, 'product_id' => 1]); } } From 8b21f9626381dee1306eb6e7ccfcdb97b287410e Mon Sep 17 00:00:00 2001 From: Ivan Shcherbak Date: Wed, 10 Jan 2024 10:17:01 +0200 Subject: [PATCH 2/9] Add rector config --- rector.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 rector.php diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..40f76bdf --- /dev/null +++ b/rector.php @@ -0,0 +1,19 @@ +paths([ + __DIR__ . '/test', + __DIR__ . '/src', + ]); + + + // define sets of rules + $rectorConfig->sets([LevelSetList::UP_TO_PHP_81, PHPUnitSetList::PHPUNIT_100,]); +}; From e4805aaf8a6fe53df216a6e5605bb1d9b3f56d84 Mon Sep 17 00:00:00 2001 From: Ivan Shcherbak Date: Wed, 10 Jan 2024 10:17:16 +0200 Subject: [PATCH 3/9] Migrate phpunit configuration --- phpunit.xml.dist | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 321bcb62..c5a788d8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,9 +1,6 @@ - + - - src/ - @@ -19,4 +16,9 @@ test/ + + + src/ + + From e4927dcf6fe661452c258bdbcbec80255e1f8ac8 Mon Sep 17 00:00:00 2001 From: Ivan Shcherbak Date: Wed, 10 Jan 2024 10:18:17 +0200 Subject: [PATCH 4/9] Use rector for test files only --- rector.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/rector.php b/rector.php index 40f76bdf..978e31a3 100644 --- a/rector.php +++ b/rector.php @@ -10,10 +10,7 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/test', - __DIR__ . '/src', ]); - - // define sets of rules - $rectorConfig->sets([LevelSetList::UP_TO_PHP_81, PHPUnitSetList::PHPUNIT_100,]); + $rectorConfig->sets([PHPUnitSetList::PHPUNIT_100,]); }; From b50abdf02fa6b68c326a8d5cfe71288aeed3cc19 Mon Sep 17 00:00:00 2001 From: Ivan Shcherbak Date: Wed, 10 Jan 2024 10:19:17 +0200 Subject: [PATCH 5/9] Run tests under php 8.1 & 8.2 --- .circleci/config.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ec1c2f74..57808b01 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,18 +4,22 @@ orbs: ci: bigcommerce/internal@volatile php: bigcommerce/internal-php@volatile -default_matrix: &default_matrix +jobs_default: &jobs_default + e: + name: php/php + php-version: << matrix.php-version >> matrix: parameters: - php-version: [ "8.0", "8.1", "8.2" ] + php-version: [ "8.1", "8.2" ] + workflows: version: 2 full: jobs: - php/phpunit-tests: - <<: *default_matrix - configuration: "phpunit.xml.dist" + <<: *jobs_default + minimum_coverage: 10 - php/static-analysis: - <<: *default_matrix + <<: *jobs_default generate_ide_helper: false From e0a0a15e1e69efa55335d73741605a454df74bbc Mon Sep 17 00:00:00 2001 From: Ivan Shcherbak Date: Wed, 10 Jan 2024 10:21:04 +0200 Subject: [PATCH 6/9] Fix phpunit config name --- .gitignore | 4 +--- phpunit.xml.dist => phpunit.xml | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) rename phpunit.xml.dist => phpunit.xml (79%) diff --git a/.gitignore b/.gitignore index cc3412a7..4ba8c56a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,11 +4,9 @@ composer.lock script/* # Testing -/phpunit.xml /build /test/reports .env .idea /.php_cs -/.php_cs.cache -/.phpunit.result.cache +*.cache diff --git a/phpunit.xml.dist b/phpunit.xml similarity index 79% rename from phpunit.xml.dist rename to phpunit.xml index c5a788d8..d6ce09ad 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml @@ -1,5 +1,5 @@ - + From a67ba28774cba42f91d9fb8ed5af96bfb099a53f Mon Sep 17 00:00:00 2001 From: Ivan Shcherbak Date: Wed, 10 Jan 2024 10:27:55 +0200 Subject: [PATCH 7/9] Set minimum coverage 60% --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 57808b01..2fea91a7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,7 +19,7 @@ workflows: jobs: - php/phpunit-tests: <<: *jobs_default - minimum_coverage: 10 + minimum_coverage: 60 - php/static-analysis: <<: *jobs_default generate_ide_helper: false From 64ecfd227929995e3f86846577fd2be699b5219e Mon Sep 17 00:00:00 2001 From: Ivan Shcherbak Date: Wed, 10 Jan 2024 11:01:44 +0200 Subject: [PATCH 8/9] Ignore *.cache files in the root folder --- .gitignore | 2 +- rector.php | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 4ba8c56a..84fc5e29 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ script/* .env .idea /.php_cs -*.cache +/*.cache diff --git a/rector.php b/rector.php index 978e31a3..dd792ccf 100644 --- a/rector.php +++ b/rector.php @@ -8,9 +8,8 @@ use Rector\Set\ValueObject\LevelSetList; return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([ - __DIR__ . '/test', + $rectorConfig->paths([__DIR__ . '/test',]); + $rectorConfig->sets([ + PHPUnitSetList::PHPUNIT_100 ]); - - $rectorConfig->sets([PHPUnitSetList::PHPUNIT_100,]); }; From df5703be0a163a88ef753fe7248d6b43e53f7b45 Mon Sep 17 00:00:00 2001 From: Ivan Shcherbak Date: Wed, 10 Jan 2024 11:11:56 +0200 Subject: [PATCH 9/9] Add php-cs-fixer to the CI --- .circleci/config.yml | 15 ++++++++++++++- .php-cs-fixer.dist.php | 12 ++++++++++++ .php_cs.dist | 11 ----------- rector.php | 2 +- test/Unit/Api/ClientTest.php | 16 ++++++++-------- 5 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .php_cs.dist diff --git a/.circleci/config.yml b/.circleci/config.yml index 2fea91a7..c3224d01 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,14 +4,25 @@ orbs: ci: bigcommerce/internal@volatile php: bigcommerce/internal-php@volatile +define: &php_min "8.1" + jobs_default: &jobs_default e: name: php/php php-version: << matrix.php-version >> matrix: parameters: - php-version: [ "8.1", "8.2" ] + php-version: [ *php_min, "8.2" ] +jobs: + cs-fixer: + executor: + name: php/php + php-version: *php_min + steps: + - ci/pre-setup + - php/composer-install + - run: ./vendor/bin/php-cs-fixer fix --diff --dry-run -v workflows: version: 2 @@ -23,3 +34,5 @@ workflows: - php/static-analysis: <<: *jobs_default generate_ide_helper: false + - cs-fixer + diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..6ddad3ac --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,12 @@ +setFinder( + PhpCsFixer\Finder::create() + ->files() + ->in(__DIR__) + ->name("*.php") + ->ignoreVCSIgnored(true) + ) + ->setRules([ + '@PSR2' => true, + ]); diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index 3ee5f943..00000000 --- a/.php_cs.dist +++ /dev/null @@ -1,11 +0,0 @@ -setFinder( - PhpCsFixer\Finder::create() - ->files() - ->in(__DIR__ . '/src') - ->in(__DIR__ . '/test') - ) - ->setRules([ - '@PSR2' => true, - ]); diff --git a/rector.php b/rector.php index dd792ccf..f5f53630 100644 --- a/rector.php +++ b/rector.php @@ -8,7 +8,7 @@ use Rector\Set\ValueObject\LevelSetList; return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([__DIR__ . '/test',]); + $rectorConfig->paths([__DIR__ . '/test']); $rectorConfig->sets([ PHPUnitSetList::PHPUNIT_100 ]); diff --git a/test/Unit/Api/ClientTest.php b/test/Unit/Api/ClientTest.php index 6491e5f6..39354f42 100644 --- a/test/Unit/Api/ClientTest.php +++ b/test/Unit/Api/ClientTest.php @@ -55,10 +55,10 @@ public function testFailOnErrorPassesThroughToConnection() { $matcher = $this->exactly(2); $this->connection->expects($matcher) - ->method('failOnError')->willReturnCallback(fn() => match ($matcher->numberOfInvocations()) { - 1 => [true], - 2 => [false], - }); + ->method('failOnError')->willReturnCallback(fn () => match ($matcher->numberOfInvocations()) { + 1 => [true], + 2 => [false], + }); Client::failOnError(true); Client::failOnError(false); } @@ -75,10 +75,10 @@ public function testVerifyPeerPassesThroughToConnection() { $matcher = $this->exactly(2); $this->connection->expects($matcher) - ->method('verifyPeer')->willReturnCallback(fn() => match ($matcher->numberOfInvocations()) { - 1 => [true], - 2 => [false], - }); + ->method('verifyPeer')->willReturnCallback(fn () => match ($matcher->numberOfInvocations()) { + 1 => [true], + 2 => [false], + }); Client::verifyPeer(true); Client::verifyPeer(false); }