Skip to content

Commit

Permalink
Merge pull request #282 from TomA-R/dep_warning
Browse files Browse the repository at this point in the history
Fix deprecation warning and upgrade PHPUnit
  • Loading branch information
TomA-R authored Jan 29, 2023
2 parents cb1bbed + 00d615e commit bd6fd47
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 64 deletions.
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
48 changes: 20 additions & 28 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='vendor/phpunit/phpunit/phpunit.xsd'
backupGlobals="true"
backupStaticAttributes="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
bootstrap="vendor/autoload.php">
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-php" target="build/logs/coverage.cov"/>
<log type="coverage-text" target="build/logs/coverage.txt" showUncoveredFiles="false"/>
<log type="coverage-html" target="test/reports/coverage/" showUncoveredFiles="true"/>
<log type="junit" target="test/reports/junit.xml"/>
</logging>
<testsuites>
<testsuite name="test">
<directory>test/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="true" backupStaticAttributes="true" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" forceCoversAnnotation="false" processIsolation="false" bootstrap="vendor/autoload.php">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="test/reports/coverage/"/>
<php outputFile="build/logs/coverage.cov"/>
<text outputFile="build/logs/coverage.txt" showUncoveredFiles="false"/>
</report>
</coverage>
<logging>
<junit outputFile="test/reports/junit.xml"/>
</logging>
<testsuites>
<testsuite name="test">
<directory>test/</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/Bigcommerce/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Bigcommerce/Api/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
30 changes: 16 additions & 14 deletions test/Unit/Api/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ClientTest extends TestCase
private $connection;
private $basePath = '';

public function setUp()
public function setUp(): void
{
$methods = array(
'useXml',
Expand All @@ -37,15 +37,15 @@ 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)
->getMock();
Client::setConnection($this->connection);
}

public function tearDown()
public function tearDown(): void
{
Client::configure(array('username' => '', 'api_key' => '', 'store_url' => ''));
unset($this->connection);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 3 additions & 11 deletions test/Unit/Api/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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());
}
}
2 changes: 1 addition & 1 deletion test/Unit/Api/Resources/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Api/Resources/ResourceTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ResourceTestBase extends TestCase
protected $connection;
protected $basePath = '';

public function setUp()
public function setUp(): void
{
$methods = array(
'useXml',
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion test/Unit/Api/Resources/RuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit bd6fd47

Please sign in to comment.