Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to PHP version ^8.1 #32

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Pipeline
on:
push:
branches:
- master
- atualizando-dependencias

pull_request:
branches:
- master

jobs:
build:
name: Testes automatizados
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3', '8.4']
timeout-minutes: 15

steps:
- name: Setup PHP with intl
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, redis

- name: checkout
uses: actions/checkout@v4

- name: composer install
run: composer install

- name: PHPUnit Tests
run: composer test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.lock
vendor/
samples/config/config.php
/phpunit.xml
.phpunit.result.cache
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 1) Requirements

PHP 5.5 and later.
PHP 8.1 and later.

### Composer
You can install the sdk via [Composer](http://getcomposer.org/). Run the following command:
Expand Down
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
{
"name": "rocket-labs/sellercenter-sdk-php",
"name": "gersonfs/sellercenter-sdk-php",
"description": "SellerCenter SDK for PHP",
"license": "MIT",
"require": {
"php": ">=5.5",
"guzzlehttp/guzzle": "~6.1",
"psr/http-message": "~1.0"
"php": ">=8.1",
"guzzlehttp/guzzle": "^7.0",
"psr/http-message": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8,<5.2"
"phpunit/phpunit": "^10.0"
},
"autoload": {
"psr-4": {
"": "src"
}
},
"scripts": {
"test": "vendor/bin/phpunit"
},
"minimum-stability": "stable"
}
11 changes: 1 addition & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./test/bootstrap.php"
displayDetailsOnPhpunitDeprecations="true"
>
<testsuites>
<testsuite name="RocketLabs\SellerCenterSdk Unit Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
2 changes: 1 addition & 1 deletion src/RocketLabs/SellerCenterSdk/Core/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(
*
* @return Client
*/
public static function create(Configuration $configuration, HttpClientInterface $httpClient = null)
public static function create(Configuration $configuration, ?HttpClientInterface $httpClient = null)
{
return new static(
$configuration,
Expand Down
2 changes: 1 addition & 1 deletion src/RocketLabs/SellerCenterSdk/Core/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getKey()
*/
protected function validateUrl($url)
{
$filteredUrl = filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED | FILTER_FLAG_SCHEME_REQUIRED);
$filteredUrl = filter_var($url, FILTER_VALIDATE_URL, FILTER_VALIDATE_URL);

if (false === $filteredUrl) {
throw new \InvalidArgumentException(
Expand Down
14 changes: 7 additions & 7 deletions src/RocketLabs/SellerCenterSdk/Core/Model/ArrayCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function removeElement($element)
*
* {@inheritDoc}
*/
public function offsetExists($offset)
public function offsetExists(mixed $offset): bool
{
return $this->containsKey($offset);
}
Expand All @@ -142,7 +142,7 @@ public function offsetExists($offset)
*
* {@inheritDoc}
*/
public function offsetGet($offset)
public function offsetGet(mixed $offset): mixed
{
return $this->get($offset);
}
Expand All @@ -152,7 +152,7 @@ public function offsetGet($offset)
*
* {@inheritDoc}
*/
public function offsetSet($offset, $value)
public function offsetSet(mixed $offset, mixed $value): void
{
if (!isset($offset)) {
$this->add($value);
Expand All @@ -166,9 +166,9 @@ public function offsetSet($offset, $value)
*
* {@inheritDoc}
*/
public function offsetUnset($offset)
public function offsetUnset(mixed $offset): void
{
return $this->remove($offset);
$this->remove($offset);
}

/**
Expand Down Expand Up @@ -222,7 +222,7 @@ public function getValues()
/**
* {@inheritDoc}
*/
public function count()
public function count(): int
{
return count($this->elements);
}
Expand Down Expand Up @@ -258,7 +258,7 @@ public function isEmpty()
*
* {@inheritDoc}
*/
public function getIterator()
public function getIterator(): \Traversable
{
return new ArrayIterator($this->elements);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function convertToOutputFormat(array $bodyContent)
protected function addToNode(
$content,
\SimpleXMLElement $node,
\SimpleXMLElement $parentNode = null
?\SimpleXMLElement $parentNode = null
) {
if (is_array($content)) {
foreach ($content as $argument => $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TimestampFormatter implements TimestampFormatterInterface
* @param \DateTimeInterface|null $time
* @return string
*/
public function getFormattedTimestamp(\DateTimeInterface $time = null)
public function getFormattedTimestamp(?\DateTimeInterface $time = null)
{
if ($time === null) {
$time = new \DateTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ interface TimestampFormatterInterface
* @param \DateTimeInterface|null $time
* @return string
*/
public function getFormattedTimestamp(\DateTimeInterface $time = null);
public function getFormattedTimestamp(?\DateTimeInterface $time = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class GetOrders extends GenericRequest
* @param string|null $sortDirection
*/
public function __construct(
\DateTimeInterface $createdAfter = null,
\DateTimeInterface $createdBefore = null,
\DateTimeInterface $updatedAfter = null,
\DateTimeInterface $updatedBefore = null,
?\DateTimeInterface $createdAfter = null,
?\DateTimeInterface $createdBefore = null,
?\DateTimeInterface $updatedAfter = null,
?\DateTimeInterface $updatedBefore = null,
$status = null,
$limit = null,
$offset = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class GetProducts extends GenericRequest
* @param null|bool $globalIdentifier
*/
public function __construct(
\DateTimeInterface $createdAfter = null,
\DateTimeInterface $createdBefore = null,
\DateTimeInterface $updatedAfter = null,
\DateTimeInterface $updatedBefore = null,
?\DateTimeInterface $createdAfter = null,
?\DateTimeInterface $createdBefore = null,
?\DateTimeInterface $updatedAfter = null,
?\DateTimeInterface $updatedBefore = null,
$search = null,
$filter = null,
$limit = null,
Expand Down
46 changes: 21 additions & 25 deletions test/RocketLabs/SellerCenterSdk/Core/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use RocketLabs\SellerCenterSdk\Core\Request\Timestamp\TimestampFormatterInterface;
use RocketLabs\SellerCenterSdk\Core\Response\Factory;

class ClientTest extends \PHPUnit_Framework_TestCase
class ClientTest extends \PHPUnit\Framework\TestCase
{
const URL = 'https://sc.api/';
const USER = 'api@user.de';
Expand All @@ -23,7 +23,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
/**
* @param RequestInterface $request
* @param HttpRequestInterface $expectedHttpRequest
* @dataProvider providerCall
* @dataProvider providerCall()
*/
public function testCall(RequestInterface $request, HttpRequestInterface $expectedHttpRequest)
{
Expand All @@ -35,19 +35,19 @@ public function testCall(RequestInterface $request, HttpRequestInterface $expect
/**
* @return array
*/
public function providerCall()
public static function providerCall()
{
return [
'getter' => [
'apiRequest' => new GenericRequest(
new GenericRequest(
Client::GET,
'SomeAction',
RequestInterface::V1,
[
'Param' => 'value'
]
),
'expectedHttpRequest' => new Request(
new Request(
Client::GET,
self::URL . '?Action=SomeAction&Format=JSON&Version=1.0&Param=value&UserID='
. urlencode(self::USER) . '&Timestamp='. urlencode(self::TIMESTAMP)
Expand All @@ -56,7 +56,7 @@ public function providerCall()
)
],
'getter with body' => [
'apiRequest' => new GenericRequest(
new GenericRequest(
Client::GET,
'SomeAction',
RequestInterface::V1,
Expand All @@ -70,15 +70,15 @@ public function providerCall()
]
]
),
'expectedHttpRequest' => new Request(
new Request(
Client::GET,
self::URL . '?Action=SomeAction&Format=JSON&Version=1.0&Param=value&UserID='
. urlencode(self::USER) . '&Timestamp='. urlencode(self::TIMESTAMP) .'&Signature=' . self::SIGN,
['Accept: application/json']
)
],
'post-request' => [
'apiRequest' => new GenericRequest(
new GenericRequest(
Client::POST,
'DoSomeAction',
RequestInterface::V2,
Expand All @@ -92,24 +92,24 @@ public function providerCall()
]
]
),
'expectedHttpRequest' => new Request(
new Request(
Client::POST,
self::URL . '?Action=DoSomeAction&Format=JSON&Version=2.0&Param=value&UserID='
. urlencode(self::USER) . '&Timestamp='. urlencode(self::TIMESTAMP) .'&Signature=' . self::SIGN,
['Accept: application/json'],
$this->getBodyStream()
self::getBodyStream()
)
],
'post-request without body' => [
'apiRequest' => new GenericRequest(
new GenericRequest(
Client::POST,
'DoSomeAction',
RequestInterface::V2,
[
'Param' => 'value'
]
),
'expectedHttpRequest' => new Request(
new Request(
Client::POST,
self::URL . '?Action=DoSomeAction&Format=JSON&Version=2.0&Param=value&UserID='
. urlencode(self::USER) . '&Timestamp='. urlencode(self::TIMESTAMP) .'&Signature=' . self::SIGN,
Expand All @@ -125,28 +125,24 @@ public function providerCall()
*/
protected function getClientWithMocks(HttpRequestInterface $httpRequest)
{
/** @var \PHPUnit_Framework_MockObject_MockObject|RequestSignatureProviderInterface $signerMock */
$signerMock = $this->getMock(RequestSignatureProviderInterface::class);
$signerMock = $this->getMockBuilder(RequestSignatureProviderInterface::class)->getMock();
$signerMock->method('sign')->willReturn(self::SIGN);

/** @var \PHPUnit_Framework_MockObject_MockObject|OutputFormatAdapterInterface $formatterMock */
$formatterMock = $this->getMock(OutputFormatAdapterInterface::class);
$formatterMock->method('convertToOutputFormat')->willReturn($this->getBodyStream());
$formatterMock = $this->getMockBuilder(OutputFormatAdapterInterface::class)->getMock();
$formatterMock->method('convertToOutputFormat')->willReturn(self::getBodyStream());

/** @var \PHPUnit_Framework_MockObject_MockObject|TimestampFormatterInterface $timestampMock */
$timestampMock = $this->getMock(TimestampFormatterInterface::class);
$timestampMock = $this->getMockBuilder(TimestampFormatterInterface::class)->getMock();
$timestampMock->method('getFormattedTimestamp')->willReturn(self::TIMESTAMP);

/** @var \PHPUnit_Framework_MockObject_MockObject|Http\ClientInterface $httpMock */
$httpMock = $this->getMock(Http\ClientInterface::class);
$httpMock = $this->getMockBuilder(Http\ClientInterface::class)->getMock();
$httpMock
->expects($this->once())
->method('send')
->with($httpRequest)
->willReturn(new Response());

/** @var \PHPUnit_Framework_MockObject_MockObject|Factory $factoryMock */
$factoryMock = $this->getMock(Factory::class);
$factoryMock = $this->getMockBuilder(Factory::class)->getMock();
$factoryMock->expects($this->once())->method('buildResponse');

return new Client(
Expand All @@ -162,12 +158,12 @@ protected function getClientWithMocks(HttpRequestInterface $httpRequest)
/**
* @return mixed
*/
protected function getBodyStream()
protected static function getBodyStream()
{
static $bodyStream;

if (empty($bodyStream)) {
$bodyStream = \GuzzleHttp\Psr7\stream_for('<xml><d ok="true" /></xml>');
$bodyStream = \GuzzleHttp\Psr7\Utils::streamFor('<xml><d ok="true" /></xml>');
}

return $bodyStream;
Expand Down
Loading