From 6c7ec619fb08e3acde163966c10a44ef7f3251d5 Mon Sep 17 00:00:00 2001 From: "lorenzo.padovani@padosoft.com" Date: Wed, 27 May 2026 00:35:22 +0200 Subject: [PATCH] Add PHP 8.5 compatibility --- .github/workflows/ci.yml | 63 ++++++++++++++++ composer.json | 7 +- phpunit.xml | 29 ++++---- src/Api/Apis/Analytics.php | 10 +++ src/Api/Apis/Connection.php | 2 +- src/Api/Apis/Identity.php | 4 +- src/Api/Apis/Provider.php | 10 ++- src/Api/Apis/Provider/Facebook.php | 73 +++++++++++++++++++ src/Api/Apis/Provider/Steam.php | 10 +++ src/Api/Apis/Provider/Twitter.php | 2 +- src/Api/Apis/Provider/Youtube.php | 10 +++ src/Api/Apis/Sharing.php | 6 +- src/Api/Apis/SharingAnalytics.php | 2 +- src/Api/Apis/ShortUrl.php | 2 +- src/Api/Apis/Sso.php | 2 +- src/Api/Apis/Storage.php | 12 ++- src/Api/Apis/User.php | 44 ++++++++++- src/OneallApi.php | 2 +- tests/unit/Api/AbstractApiTest.php | 8 +- tests/unit/Api/Apis/AnalyticsTest.php | 2 +- tests/unit/Api/Apis/ConnectionTest.php | 2 +- tests/unit/Api/Apis/IdentityTest.php | 2 +- tests/unit/Api/Apis/Provider/FacebookTest.php | 4 +- .../unit/Api/Apis/Provider/PinterestTest.php | 10 +-- tests/unit/Api/Apis/Provider/SteamTest.php | 2 +- tests/unit/Api/Apis/Provider/YoutubeTest.php | 2 +- tests/unit/Api/Apis/ProviderTest.php | 9 ++- tests/unit/Api/Apis/SharingTest.php | 2 +- tests/unit/Api/Apis/ShortUrlTest.php | 2 +- tests/unit/Api/Apis/SsoTest.php | 2 +- tests/unit/Api/Apis/StorageTest.php | 2 +- tests/unit/Api/Apis/UserTest.php | 2 +- tests/unit/Api/PaginationTest.php | 4 +- tests/unit/Api/RegistryTest.php | 13 ++-- tests/unit/Api/TestingApi.php | 17 +++-- tests/unit/Client/AbstractClientTest.php | 6 +- tests/unit/Client/Adapter/CurlTest.php | 4 +- tests/unit/Client/BuilderTest.php | 6 +- tests/unit/Client/ProxyConfigurationTest.php | 4 +- .../Exception/BasResponseExceptionTest.php | 2 +- tests/unit/OneallApiTest.php | 24 +++--- tests/unit/PhpUnitHelperTrait.php | 15 +++- 42 files changed, 344 insertions(+), 92 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 src/Api/Apis/Analytics.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d2924e4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,63 @@ +name: CI + +on: + pull_request: + push: + branches: + - master + - 'codex/**' + +jobs: + source-compatibility: + name: Source compatibility (PHP ${{ matrix.php }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: + - '5.4' + - '7.4' + - '8.4' + - '8.5' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + tools: none + + - name: Lint source files + run: find src -name '*.php' -print0 | xargs -0 -n 1 php -l + + tests: + name: Tests (PHP ${{ matrix.php }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: + - '8.4' + - '8.5' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring + coverage: none + + - name: Validate Composer configuration + run: composer validate --strict --no-check-lock + + - name: Install dependencies + run: composer update --no-interaction --prefer-dist --no-progress + + - name: Run test suite + run: composer test diff --git a/composer.json b/composer.json index 1711e76..df3f4ce 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,17 @@ { "name" : "oneall/php-sdk", + "description" : "PHP SDK for the OneAll API.", + "license" : "GPL-2.0-or-later", "require" : { "php": ">=5.4" }, "require-dev" : { - "phpunit/phpunit": "@stable", + "phpunit/phpunit": "^9.6", "phpmd/phpmd" : "~2.6" }, + "scripts" : { + "test": "phpunit" + }, "autoload" : { "psr-4": { "Oneall\\": "src/" diff --git a/phpunit.xml b/phpunit.xml index 6076732..92492ad 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,18 +1,17 @@ - - - - src - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd" + bootstrap="vendor/autoload.php" + colors="true"> + + + tests/unit + + + + + src + + diff --git a/src/Api/Apis/Analytics.php b/src/Api/Apis/Analytics.php new file mode 100644 index 0000000..3cc8833 --- /dev/null +++ b/src/Api/Apis/Analytics.php @@ -0,0 +1,10 @@ +getClient()->get('/providers.json'); + if (!$pagination) + { + $pagination = new Pagination(); + } + + return $this->getClient()->get('/providers.json?' . $pagination->build()); } /** diff --git a/src/Api/Apis/Provider/Facebook.php b/src/Api/Apis/Provider/Facebook.php index 9317174..b06d257 100644 --- a/src/Api/Apis/Provider/Facebook.php +++ b/src/Api/Apis/Provider/Facebook.php @@ -25,6 +25,8 @@ namespace Oneall\Api\Apis\Provider; use Oneall\Api\AbstractApi; +use Oneall\Api\Pagination; +use Oneall\Exception\BadMethodCallException; /** * Class Facebook @@ -43,6 +45,77 @@ public function getName() return 'facebook'; } + /** + * @param string $identityToken + * @param Pagination|null $pagination + * + * @return \Oneall\Client\Response + */ + public function getPosts($identityToken, $pagination = null) + { + if (!$pagination) + { + $pagination = new Pagination(); + } + + return $this->getClient()->get('/identities/' . $identityToken . '/facebook/posts.json?' . $pagination->build()); + } + + /** + * @param Pagination|null $pagination + * + * @return \Oneall\Client\Response + */ + public function getPages($pagination = null) + { + if (!$pagination) + { + $pagination = new Pagination(); + } + + return $this->getClient()->get('/providers/facebook/pages.json?' . $pagination->build()); + } + + /** + * @param string $pageToken + * @param string|null $text + * @param array $link + * @param string|null $picture + * + * @return \Oneall\Client\Response + */ + public function publish($pageToken, $text = null, array $link = [], $picture = null) + { + if (empty($text) && empty($link) && empty($picture)) + { + throw new BadMethodCallException('No data to publish.'); + } + + $data = [ + 'request' => [ + 'page_message' => [ + 'parts' => [ + 'text' => ['body' => $text], + 'picture' => [], + 'link' => [], + ] + ] + ] + ]; + + if (!empty($picture)) + { + $data['request']['page_message']['parts']['picture'] = ['url' => $picture]; + } + + if (!empty($link)) + { + $data['request']['page_message']['parts']['link'] = $link; + } + + return $this->getClient()->post('/providers/facebook/pages/' . $pageToken . '/publish.json', $data); + } + // **************** // Pull API // **************** diff --git a/src/Api/Apis/Provider/Steam.php b/src/Api/Apis/Provider/Steam.php index ad49c0e..351f5fd 100644 --- a/src/Api/Apis/Provider/Steam.php +++ b/src/Api/Apis/Provider/Steam.php @@ -43,6 +43,16 @@ public function getName() return 'steam'; } + /** + * @param string $identityToken + * + * @return \Oneall\Client\Response + */ + public function getGames($identityToken) + { + return $this->getClient()->get('/identities/' . $identityToken . '/steam/games.json'); + } + /** * Steam \ List Games * diff --git a/src/Api/Apis/Provider/Twitter.php b/src/Api/Apis/Provider/Twitter.php index b5c7222..349927f 100644 --- a/src/Api/Apis/Provider/Twitter.php +++ b/src/Api/Apis/Provider/Twitter.php @@ -127,7 +127,7 @@ public function pullTweets($identityToken, $num_tweets = 50, $after_tweet_id = ' * * @return \Oneall\Client\Response */ - public function pushTweet($identityToken, $message, array $picturesIds = [], string $location = null) + public function pushTweet($identityToken, $message, array $picturesIds = [], $location = null) { $data = [ "request" => [ diff --git a/src/Api/Apis/Provider/Youtube.php b/src/Api/Apis/Provider/Youtube.php index aa416b4..ef7cd3a 100644 --- a/src/Api/Apis/Provider/Youtube.php +++ b/src/Api/Apis/Provider/Youtube.php @@ -43,6 +43,16 @@ public function getName() return 'youtube'; } + /** + * @param string $identityToken + * + * @return \Oneall\Client\Response + */ + public function getVideos($identityToken) + { + return $this->getClient()->get('/identities/' . $identityToken . '/youtube/videos.json'); + } + /** * Youtube \ List Videos * diff --git a/src/Api/Apis/Sharing.php b/src/Api/Apis/Sharing.php index 678089f..eafc2f9 100644 --- a/src/Api/Apis/Sharing.php +++ b/src/Api/Apis/Sharing.php @@ -55,7 +55,7 @@ public function getName() * * @return \Oneall\Client\Response */ - public function getAll(Pagination $pagination = null) + public function getAll($pagination = null) { if (!$pagination) { @@ -75,7 +75,7 @@ public function getAll(Pagination $pagination = null) * * @return \Oneall\Client\Response */ - public function getPageByToken($sharing_page_token, Pagination $pagination = null) + public function getPageByToken($sharing_page_token, $pagination = null) { if (!$pagination) { @@ -111,7 +111,7 @@ public function getPageByUrl($url) * * @return \Oneall\Client\Response */ - public function getMessages(Pagination $pagination = null) + public function getMessages($pagination = null) { if (!$pagination) { diff --git a/src/Api/Apis/SharingAnalytics.php b/src/Api/Apis/SharingAnalytics.php index 1a2aaf9..a17cbe5 100644 --- a/src/Api/Apis/SharingAnalytics.php +++ b/src/Api/Apis/SharingAnalytics.php @@ -52,7 +52,7 @@ public function getName() * * @return \Oneall\Client\Response */ - public function getAll(Pagination $pagination = null, $identityToken = null, $userToken = null) + public function getAll($pagination = null, $identityToken = null, $userToken = null) { $query = []; diff --git a/src/Api/Apis/ShortUrl.php b/src/Api/Apis/ShortUrl.php index 7dcc523..e0d5f47 100644 --- a/src/Api/Apis/ShortUrl.php +++ b/src/Api/Apis/ShortUrl.php @@ -51,7 +51,7 @@ public function getName() * * @return \Oneall\Client\Response */ - public function getAll(\Oneall\Api\Pagination $pagination = null) + public function getAll($pagination = null) { if (!$pagination) { diff --git a/src/Api/Apis/Sso.php b/src/Api/Apis/Sso.php index d37f03a..1ec4431 100644 --- a/src/Api/Apis/Sso.php +++ b/src/Api/Apis/Sso.php @@ -49,7 +49,7 @@ public function getName() * * @return \Oneall\Client\Response */ - public function getAll(Pagination $pagination = null) + public function getAll($pagination = null) { if (!$pagination) { diff --git a/src/Api/Apis/Storage.php b/src/Api/Apis/Storage.php index 90285be..822a077 100644 --- a/src/Api/Apis/Storage.php +++ b/src/Api/Apis/Storage.php @@ -94,13 +94,23 @@ public function createUser( */ public function updateUser( $userToken, - array $identity = [], + $identity = [], $externalId = null, $login = null, $password = null, $mode = self::MODE_UPDATE_REPLACE ) { + if (!is_array($identity)) + { + $arguments = func_get_args(); + $externalId = isset($arguments[1]) ? $arguments[1] : null; + $login = isset($arguments[2]) ? $arguments[2] : null; + $password = isset($arguments[3]) ? $arguments[3] : null; + $identity = (isset($arguments[4]) && is_array($arguments[4])) ? $arguments[4] : []; + $mode = isset($arguments[5]) ? $arguments[5] : self::MODE_UPDATE_REPLACE; + } + if (empty($externalId) && empty($login) && empty($password) && empty($identity)) { return null; diff --git a/src/Api/Apis/User.php b/src/Api/Apis/User.php index d517777..8b22ac5 100644 --- a/src/Api/Apis/User.php +++ b/src/Api/Apis/User.php @@ -49,7 +49,7 @@ public function getName() * * @return \Oneall\Client\Response */ - public function getAll(Pagination $pagination = null) + public function getAll($pagination = null) { if (!$pagination) { @@ -147,4 +147,46 @@ public function getContacts($user_token, $disableCache = false) return $this->getClient()->get($uri); } + + /** + * Publish To Social Networks. + * + * @param string $userToken + * @param array $providers + * @param string $text + * @param string $videoUrl + * @param string $pictureUrl + * @param array $link + * @param array $uploads + * + * @return \Oneall\Client\Response + */ + public function publish( + $userToken, + array $providers, + $text, + $videoUrl = null, + $pictureUrl = null, + array $link = [], + array $uploads = [] + ) + { + $data = [ + "request" => [ + "message" => [ + "providers" => $providers, + "parts" => [ + "text" => ["body" => $text] + ] + ] + ] + ]; + + $data = $this->addInfo($data, 'request/message/parts/video/url', $videoUrl); + $data = $this->addInfo($data, 'request/message/parts/picture/url', $pictureUrl); + $data = $this->addInfo($data, 'request/message/parts/link', $link); + $data = $this->addInfo($data, 'request/message/parts/uploads', $uploads); + + return $this->getClient()->post('/users/' . $userToken . '/publish.json', $data); + } } diff --git a/src/OneallApi.php b/src/OneallApi.php index 259e7b8..928febc 100644 --- a/src/OneallApi.php +++ b/src/OneallApi.php @@ -82,7 +82,7 @@ class OneallApi * @param \Oneall\Client\ProxyConfiguration|null $proxy * @param \Oneall\Api\Registry|null $registry */ - public function __construct(ClientInterface $client, ProxyConfiguration $proxy = null, Registry $registry = null) + public function __construct(ClientInterface $client, $proxy = null, $registry = null) { $this->client = $client; $this->proxy = $proxy; diff --git a/tests/unit/Api/AbstractApiTest.php b/tests/unit/Api/AbstractApiTest.php index e3a60cd..c159b79 100644 --- a/tests/unit/Api/AbstractApiTest.php +++ b/tests/unit/Api/AbstractApiTest.php @@ -47,15 +47,15 @@ class AbstractApiTest extends TestingApi protected $sut; /** - * @var \Oneall\Client\ClientInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Oneall\Client\ClientInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $client; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new TestingAbstractApi($this->client); - $this->client = $this->getMockForAbstractClass('\Oneall\Client\ClientInterface'); + $this->client = $this->createMock('\Oneall\Client\ClientInterface'); } /** @@ -130,7 +130,7 @@ public function getName() return 'testing-abstract-api'; } - public function addInfo(array $array, $path, $value) + public function addInfo(array &$array, $path, $value) { return parent::addInfo($array, $path, $value); } diff --git a/tests/unit/Api/Apis/AnalyticsTest.php b/tests/unit/Api/Apis/AnalyticsTest.php index f29eaa7..6444f5d 100644 --- a/tests/unit/Api/Apis/AnalyticsTest.php +++ b/tests/unit/Api/Apis/AnalyticsTest.php @@ -37,7 +37,7 @@ class AnalyticsTest extends TestingApi /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Analytics($this->client, $this->timeout); diff --git a/tests/unit/Api/Apis/ConnectionTest.php b/tests/unit/Api/Apis/ConnectionTest.php index 879663f..f85212a 100644 --- a/tests/unit/Api/Apis/ConnectionTest.php +++ b/tests/unit/Api/Apis/ConnectionTest.php @@ -42,7 +42,7 @@ class ConnectionTest extends TestingApi /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Connection($this->client, $this->timeout); diff --git a/tests/unit/Api/Apis/IdentityTest.php b/tests/unit/Api/Apis/IdentityTest.php index 2c23b36..1ba51f1 100644 --- a/tests/unit/Api/Apis/IdentityTest.php +++ b/tests/unit/Api/Apis/IdentityTest.php @@ -42,7 +42,7 @@ class IdentityTest extends TestingApi /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Identity($this->client, $this->timeout); diff --git a/tests/unit/Api/Apis/Provider/FacebookTest.php b/tests/unit/Api/Apis/Provider/FacebookTest.php index 2e32b7a..4b8ebb4 100644 --- a/tests/unit/Api/Apis/Provider/FacebookTest.php +++ b/tests/unit/Api/Apis/Provider/FacebookTest.php @@ -39,7 +39,7 @@ class FacebookTest extends TestingApi */ protected $sut; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Facebook($this->client, $this->timeout); @@ -149,7 +149,7 @@ public function testPublishOnlyText() public function testPublishWithourAnyDataToPublish() { - $this->setExpectedException('Oneall\Exception\BadMethodCallException'); + $this->expectException('Oneall\Exception\BadMethodCallException'); $this->assertSame($this->response, $this->sut->publish('my-token', $noText = null, $noLink = [])); } } diff --git a/tests/unit/Api/Apis/Provider/PinterestTest.php b/tests/unit/Api/Apis/Provider/PinterestTest.php index 4090e5e..1114eaa 100644 --- a/tests/unit/Api/Apis/Provider/PinterestTest.php +++ b/tests/unit/Api/Apis/Provider/PinterestTest.php @@ -39,7 +39,7 @@ class PinterestTest extends TestingApi */ protected $sut; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Pinterest($this->client, $this->timeout); @@ -60,8 +60,8 @@ public function testPostPins() 'push' => [ 'pin' => [ 'board' => 'my/board', - 'note' => 'my-note', - 'image_url' => 'my-image-uri', + 'description' => 'my-note', + 'picture' => 'my-image-uri', 'link' => 'my-link' ] ] @@ -84,8 +84,8 @@ public function testPostPinswithoutLinkParam() 'push' => [ 'pin' => [ 'board' => 'my/board', - 'note' => 'my-note', - 'image_url' => 'my-image-uri', + 'description' => 'my-note', + 'picture' => 'my-image-uri', ] ] ] diff --git a/tests/unit/Api/Apis/Provider/SteamTest.php b/tests/unit/Api/Apis/Provider/SteamTest.php index 823b101..f95b895 100644 --- a/tests/unit/Api/Apis/Provider/SteamTest.php +++ b/tests/unit/Api/Apis/Provider/SteamTest.php @@ -38,7 +38,7 @@ class SteamTest extends TestingApi */ protected $sut; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Steam($this->client, $this->timeout); diff --git a/tests/unit/Api/Apis/Provider/YoutubeTest.php b/tests/unit/Api/Apis/Provider/YoutubeTest.php index f6c0277..6afadc1 100644 --- a/tests/unit/Api/Apis/Provider/YoutubeTest.php +++ b/tests/unit/Api/Apis/Provider/YoutubeTest.php @@ -39,7 +39,7 @@ class YoutubeTest extends TestingApi */ protected $sut; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Youtube($this->client, $this->timeout); diff --git a/tests/unit/Api/Apis/ProviderTest.php b/tests/unit/Api/Apis/ProviderTest.php index 8eb4897..60e8436 100644 --- a/tests/unit/Api/Apis/ProviderTest.php +++ b/tests/unit/Api/Apis/ProviderTest.php @@ -47,7 +47,7 @@ class ProviderTest extends TestingApi /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Provider($this->client, $this->timeout); @@ -56,7 +56,10 @@ protected function setUp() // ensure only 1 provider "test" is in the registry $property = new \ReflectionProperty($this->sut, 'providerApis'); - $property->setAccessible(true); + if (PHP_VERSION_ID < 80100) + { + $property->setAccessible(true); + } $property->setValue($this->sut, ['test' => $this->provider]); } @@ -102,7 +105,7 @@ public function testGetProvider() public function testGetProviderWithnonExistingProvider() { - $this->setExpectedException('Oneall\Exception\ProviderApiNotFound'); + $this->expectException('Oneall\Exception\ProviderApiNotFound'); $this->sut->getProviderApi('non-existing-provider'); } diff --git a/tests/unit/Api/Apis/SharingTest.php b/tests/unit/Api/Apis/SharingTest.php index c75ba2f..442aab5 100644 --- a/tests/unit/Api/Apis/SharingTest.php +++ b/tests/unit/Api/Apis/SharingTest.php @@ -42,7 +42,7 @@ class SharingTest extends TestingApi /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Sharing($this->client, $this->timeout); diff --git a/tests/unit/Api/Apis/ShortUrlTest.php b/tests/unit/Api/Apis/ShortUrlTest.php index 301e03f..10d7abe 100644 --- a/tests/unit/Api/Apis/ShortUrlTest.php +++ b/tests/unit/Api/Apis/ShortUrlTest.php @@ -42,7 +42,7 @@ class ShorturlTest extends TestingApi /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new ShortUrl($this->client, $this->timeout); diff --git a/tests/unit/Api/Apis/SsoTest.php b/tests/unit/Api/Apis/SsoTest.php index 0a526e1..87a15d0 100644 --- a/tests/unit/Api/Apis/SsoTest.php +++ b/tests/unit/Api/Apis/SsoTest.php @@ -42,7 +42,7 @@ class SsoTest extends TestingApi /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Sso($this->client, $this->timeout); diff --git a/tests/unit/Api/Apis/StorageTest.php b/tests/unit/Api/Apis/StorageTest.php index 1138b35..c3481ec 100644 --- a/tests/unit/Api/Apis/StorageTest.php +++ b/tests/unit/Api/Apis/StorageTest.php @@ -42,7 +42,7 @@ class StorageTest extends TestingApi /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Storage($this->client, $this->timeout); diff --git a/tests/unit/Api/Apis/UserTest.php b/tests/unit/Api/Apis/UserTest.php index 50dfc9b..e3a6608 100644 --- a/tests/unit/Api/Apis/UserTest.php +++ b/tests/unit/Api/Apis/UserTest.php @@ -42,7 +42,7 @@ class UserTest extends TestingApi /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new User($this->client, $this->timeout); diff --git a/tests/unit/Api/PaginationTest.php b/tests/unit/Api/PaginationTest.php index 97d36cf..1aea730 100644 --- a/tests/unit/Api/PaginationTest.php +++ b/tests/unit/Api/PaginationTest.php @@ -5,7 +5,7 @@ use Oneall\Api\Pagination; use Oneall\Test\PhpUnitHelperTrait; -class PaginationTest extends \PHPUnit_Framework_TestCase +class PaginationTest extends \PHPUnit\Framework\TestCase { use PhpUnitHelperTrait; @@ -14,7 +14,7 @@ class PaginationTest extends \PHPUnit_Framework_TestCase */ protected $sut; - protected function setUp() + protected function setUp(): void { $this->sut = new Pagination(); } diff --git a/tests/unit/Api/RegistryTest.php b/tests/unit/Api/RegistryTest.php index d56c8e7..98a5fcf 100644 --- a/tests/unit/Api/RegistryTest.php +++ b/tests/unit/Api/RegistryTest.php @@ -44,7 +44,7 @@ class RegistryTest extends TestingApi protected $sut; /** - * @var \Oneall\Api\AbstractApi|\PHPUnit_Framework_MockObject_MockObject + * @var \Oneall\Api\AbstractApi|\PHPUnit\Framework\MockObject\MockObject */ protected $api; @@ -53,7 +53,7 @@ class RegistryTest extends TestingApi */ protected $apiName = 'test-api'; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Registry(); @@ -63,7 +63,10 @@ protected function setUp() // add our api in the registry $reflection = new \ReflectionProperty($this->sut, 'apis'); - $reflection->setAccessible(true); + if (PHP_VERSION_ID < 80100) + { + $reflection->setAccessible(true); + } $reflection->setValue($this->sut, [$this->api->getName() => $this->api]); } @@ -80,7 +83,7 @@ public function testGet() public function testGetWrongApi() { - $this->setExpectedException('Oneall\Exception\ApiNotFound'); + $this->expectException('Oneall\Exception\ApiNotFound'); $this->sut->get('fake-name'); } @@ -102,7 +105,7 @@ public function testAdd() /** * @param $name * - * @return \PHPUnit_Framework_MockObject_MockObject|AbstractApi + * @return \PHPUnit\Framework\MockObject\MockObject|AbstractApi */ protected function buildApi($name) { diff --git a/tests/unit/Api/TestingApi.php b/tests/unit/Api/TestingApi.php index 78d8fe4..48b3416 100644 --- a/tests/unit/Api/TestingApi.php +++ b/tests/unit/Api/TestingApi.php @@ -4,10 +4,10 @@ use Oneall\Api\Pagination; -class TestingApi extends \PHPUnit_Framework_TestCase +class TestingApi extends \PHPUnit\Framework\TestCase { /** - * @var \Oneall\Client\ClientInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Oneall\Client\ClientInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $client; @@ -35,21 +35,24 @@ class TestingApi extends \PHPUnit_Framework_TestCase /** * Our testing response * - * @var \Oneall\Api\Pagination|\PHPUnit_Framework_MockObject_MockObject + * @var \Oneall\Api\Pagination|\PHPUnit\Framework\MockObject\MockObject */ protected $pagination; /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { parent::setUp(); - $this->client = $this->getMockForAbstractClass('Oneall\Client\ClientInterface'); + $this->client = $this->createMock('Oneall\Client\ClientInterface'); $this->options = ['my' => 'option']; - $this->response = $this->getMockForAbstractClass('Oneall\Client\Response'); + $this->response = $this->createMock('Oneall\Client\Response'); - $this->pagination = $this->getMockForAbstractClass('Oneall\Api\Pagination'); + $this->pagination = $this->getMockBuilder('Oneall\Api\Pagination') + ->disableOriginalConstructor() + ->onlyMethods(['build']) + ->getMock(); $this->pagination->method('build')->willReturn('?page=10&entries_per_page=10&order_direction=desc'); } diff --git a/tests/unit/Client/AbstractClientTest.php b/tests/unit/Client/AbstractClientTest.php index 641431c..1983cea 100644 --- a/tests/unit/Client/AbstractClientTest.php +++ b/tests/unit/Client/AbstractClientTest.php @@ -31,12 +31,12 @@ * * @package Oneall\Test\Client */ -class AbstractClientTest extends \PHPUnit_Framework_TestCase +class AbstractClientTest extends \PHPUnit\Framework\TestCase { use PhpUnitHelperTrait; /** - * @var \Oneall\Client\AbstractClient|\PHPUnit_Framework_MockObject_MockObject + * @var \Oneall\Client\AbstractClient|\PHPUnit\Framework\MockObject\MockObject */ protected $sut; @@ -50,7 +50,7 @@ class AbstractClientTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/unit/Client/Adapter/CurlTest.php b/tests/unit/Client/Adapter/CurlTest.php index c0680fa..ce3cb06 100644 --- a/tests/unit/Client/Adapter/CurlTest.php +++ b/tests/unit/Client/Adapter/CurlTest.php @@ -32,7 +32,7 @@ * * @package Oneall\Test\Client\Adapter */ -class CurlTest extends \PHPUnit_Framework_TestCase +class CurlTest extends \PHPUnit\Framework\TestCase { use PhpUnitHelperTrait; @@ -41,7 +41,7 @@ class CurlTest extends \PHPUnit_Framework_TestCase */ protected $sut; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new Curl('my-subDomain', 'my-sitePublicKey', 'my-sitePrivateKey', ['options']); diff --git a/tests/unit/Client/BuilderTest.php b/tests/unit/Client/BuilderTest.php index 5ca81dc..316dcdf 100644 --- a/tests/unit/Client/BuilderTest.php +++ b/tests/unit/Client/BuilderTest.php @@ -31,7 +31,7 @@ * * @package Oneall\Test\Client */ -class BuilderTest extends \PHPUnit_Framework_TestCase +class BuilderTest extends \PHPUnit\Framework\TestCase { /** * @var \Oneall\Client\Builder @@ -60,7 +60,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase */ protected $base = 'example.com'; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -81,7 +81,7 @@ public function testBuildFSOckOpenHandler() public function testBuildException() { - $this->setExpectedException('\RuntimeException'); + $this->expectException('\RuntimeException'); $this->sut->build('somethingwrong', 'a', 'b', 'c', true, 'd'); } } diff --git a/tests/unit/Client/ProxyConfigurationTest.php b/tests/unit/Client/ProxyConfigurationTest.php index 6d7dcae..725c011 100644 --- a/tests/unit/Client/ProxyConfigurationTest.php +++ b/tests/unit/Client/ProxyConfigurationTest.php @@ -31,14 +31,14 @@ * * @package Oneall\Test\Client */ -class ProxyConfigurationTest extends \PHPUnit_Framework_TestCase +class ProxyConfigurationTest extends \PHPUnit\Framework\TestCase { /** * @var ProxyConfiguration */ protected $sut; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sut = new ProxyConfiguration(); diff --git a/tests/unit/Exception/BasResponseExceptionTest.php b/tests/unit/Exception/BasResponseExceptionTest.php index cdedec2..65491c8 100644 --- a/tests/unit/Exception/BasResponseExceptionTest.php +++ b/tests/unit/Exception/BasResponseExceptionTest.php @@ -31,7 +31,7 @@ * * @package Oneall\Test\Exception */ -class BasResponseExceptionTest extends \PHPUnit_Framework_TestCase +class BasResponseExceptionTest extends \PHPUnit\Framework\TestCase { public function testConstructorWithoutMessage() { diff --git a/tests/unit/OneallApiTest.php b/tests/unit/OneallApiTest.php index 2cf6310..12dd5d9 100644 --- a/tests/unit/OneallApiTest.php +++ b/tests/unit/OneallApiTest.php @@ -32,7 +32,7 @@ * * @package Oneall\Test */ -class OneallApiTest extends \PHPUnit_Framework_TestCase +class OneallApiTest extends \PHPUnit\Framework\TestCase { /** * @var \Oneall\OneallApi @@ -40,26 +40,29 @@ class OneallApiTest extends \PHPUnit_Framework_TestCase protected $sut; /** - * @var \Oneall\Client\ClientInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Oneall\Client\ClientInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $client; /** - * @var \Oneall\Client\ProxyConfiguration|\PHPUnit_Framework_MockObject_MockObject + * @var \Oneall\Client\ProxyConfiguration|\PHPUnit\Framework\MockObject\MockObject */ protected $proxy; /** - * @var \Oneall\Api\Registry|\PHPUnit_Framework_MockObject_MockObject + * @var \Oneall\Api\Registry|\PHPUnit\Framework\MockObject\MockObject */ protected $registry; - protected function setUp() + protected function setUp(): void { parent::setUp(); new Registry(); $methods = ['get', 'add']; - $this->client = $this->getMockForAbstractClass('\Oneall\Client\ClientInterface', [], '', false, false); - $this->proxy = $this->getMockForAbstractClass('\Oneall\Client\ProxyConfiguration', [], '', false, false); - $this->registry = $this->getMockForAbstractClass('\Oneall\Api\Registry', [], '', false, false, false, $methods); + $this->client = $this->createMock('\Oneall\Client\ClientInterface'); + $this->proxy = $this->createMock('\Oneall\Client\ProxyConfiguration'); + $this->registry = $this->getMockBuilder('\Oneall\Api\Registry') + ->disableOriginalConstructor() + ->onlyMethods($methods) + ->getMock(); $this->sut = new OneallApi($this->client, $this->proxy, $this->registry); } @@ -143,7 +146,10 @@ protected function buildApi($name) protected function setObjectProperty($object, $property, $value) { $reflection = new \ReflectionProperty($object, $property); - $reflection->setAccessible(true); + if (PHP_VERSION_ID < 80100) + { + $reflection->setAccessible(true); + } $reflection->setValue($object, $value); } diff --git a/tests/unit/PhpUnitHelperTrait.php b/tests/unit/PhpUnitHelperTrait.php index 27d9ca3..ba5a76a 100644 --- a/tests/unit/PhpUnitHelperTrait.php +++ b/tests/unit/PhpUnitHelperTrait.php @@ -43,7 +43,10 @@ trait PhpUnitHelperTrait public function setProperty($object, $property, $value) { $property = new \ReflectionProperty($object, $property); - $property->setAccessible(true); + if (PHP_VERSION_ID < 80100) + { + $property->setAccessible(true); + } $property->setValue($object, $value); return $this; @@ -60,7 +63,10 @@ public function setProperty($object, $property, $value) public function getProperty($object, $property) { $property = new \ReflectionProperty($object, $property); - $property->setAccessible(true); + if (PHP_VERSION_ID < 80100) + { + $property->setAccessible(true); + } return $property->getValue($object); } @@ -77,7 +83,10 @@ public function getProperty($object, $property) public function invoke($object, $method, array $arguments = []) { $reflected = new \ReflectionMethod($object, $method); - $reflected->setAccessible(true); + if (PHP_VERSION_ID < 80100) + { + $reflected->setAccessible(true); + } return $reflected->invokeArgs($object, $arguments); }