From 96ac9f4fed51c0cf5ec23108abfa897e39d2185c Mon Sep 17 00:00:00 2001 From: Toni Kangas Date: Fri, 1 Dec 2023 14:03:34 +0200 Subject: [PATCH] chore: drop support for PHP 7 (#55) Co-authored-by: Sandesh --- .github/workflows/main.yml | 28 ++++++++++++++++++++------- .gitignore | 1 + README.md | 2 +- composer.json | 8 ++++---- lib/HttpClient/UpcloudApiResponse.php | 3 ++- lib/Serializer.php | 4 ++-- lib/SerializerInterface.php | 4 ++-- test/test-install-with-laravel.sh | 13 +++++++++++++ 8 files changed, 46 insertions(+), 17 deletions(-) create mode 100755 test/test-install-with-laravel.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 27eb51f0..d3ee98da 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,18 +4,14 @@ on: branches: - main pull_request: - branches: - - main jobs: - Build: + Test: strategy: matrix: - os-php-versions: [ - { os: ubuntu-latest, php: 7.2 }, - { os: ubuntu-latest, php: 7.3 }, - { os: ubuntu-latest, php: 7.4 }, + os-php-versions: [ { os: ubuntu-latest, php: 8.0 }, { os: ubuntu-latest, php: 8.1 }, + { os: ubuntu-latest, php: 8.2 }, ] runs-on: ${{ matrix.os-php-versions.os }} steps: @@ -37,3 +33,21 @@ jobs: xdebug.max_nesting_level: 512 UPCLOUD_API_TEST_USER: ${{ secrets.UPCLOUD_API_TEST_USER }} UPCLOUD_API_TEST_PASSWORD: ${{ secrets.UPCLOUD_API_TEST_PASSWORD }} + + test-with-laravel: + name: Test install with laravel + strategy: + matrix: + laravel-version: + - 9 + - 10 + runs-on: ubuntu-latest + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + - uses: actions/checkout@v2 + - name: Test package can be required into laravel project + run: | + ./test/test-install-with-laravel.sh ${{ matrix.laravel-version }} diff --git a/.gitignore b/.gitignore index 50bcb840..d12a93dd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ git_push.sh /phpunit.xml /composer.lock .phpunit.result.cache +tmp/ diff --git a/README.md b/README.md index 0ee129c1..ca2b5a39 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ NOTE: Please test all of your use cases thoroughly before actual production use. ## Requirements -Using this library requires the PHP version 7.2 and later. +Using this library requires the PHP version 8.0 and later. ## Installation ### Composer diff --git a/composer.json b/composer.json index 71ac20f7..53a0bbfc 100644 --- a/composer.json +++ b/composer.json @@ -16,20 +16,20 @@ } ], "require": { - "php": "^7.2|^8.0|^8.1", + "php": "^8.0", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", "guzzlehttp/guzzle": "^7.1", - "symfony/serializer": "^5.1", - "symfony/property-access": "^5.1", + "symfony/serializer": "^6.0", + "symfony/property-access": "^6.0", "webmozart/assert": "^1.9" }, "require-dev": { "phpunit/phpunit": "^8.5.8", "squizlabs/php_codesniffer": "~3.5", "mockery/mockery": "^1.3.3", - "symfony/var-dumper": "^5.1" + "symfony/var-dumper": "^6.0" }, "autoload": { "psr-4": { diff --git a/lib/HttpClient/UpcloudApiResponse.php b/lib/HttpClient/UpcloudApiResponse.php index d522c632..2899ae37 100644 --- a/lib/HttpClient/UpcloudApiResponse.php +++ b/lib/HttpClient/UpcloudApiResponse.php @@ -105,7 +105,8 @@ public function deserializeBody($class) { return $this->serializer->deserialize( (string) $this->getBody(), - $class + $class, + 'json' ); } diff --git a/lib/Serializer.php b/lib/Serializer.php index 27ef77cd..02b79545 100644 --- a/lib/Serializer.php +++ b/lib/Serializer.php @@ -25,12 +25,12 @@ public function __construct() $this->serializer = new BaseSerializer([$normalizer], [new JsonEncoder()]); } - public function deserialize($data, string $type, string $format = 'json', array $context = []) + public function deserialize(mixed $data, string $type, string $format = 'json', array $context = []): object|array { return $this->serializer->deserialize($data, $type, $format, $context); } - public function serialize($data, string $format = 'json', array $context = []) + public function serialize(mixed $data, string $format = 'json', array $context = []): string { return $this->serializer->serialize($data, $format, array_merge([ 'json_encode_options' => self::DEFAULT_ENCODING_OPTIONS, diff --git a/lib/SerializerInterface.php b/lib/SerializerInterface.php index 0ae608db..f9a5395e 100644 --- a/lib/SerializerInterface.php +++ b/lib/SerializerInterface.php @@ -17,7 +17,7 @@ interface SerializerInterface extends BaseSerializerInterface * * @return string */ - public function serialize($data, string $format = 'json', array $context = []); + public function serialize(mixed $data, string $format, array $context = []): string; /** * Deserializes data into the given type. @@ -29,5 +29,5 @@ public function serialize($data, string $format = 'json', array $context = []); * @param array $context * @return object|array */ - public function deserialize($data, string $type, string $format = 'json', array $context = []); + public function deserialize(mixed $data, string $type, string $format, array $context = []): object|array; } diff --git a/test/test-install-with-laravel.sh b/test/test-install-with-laravel.sh new file mode 100755 index 00000000..11c7ae43 --- /dev/null +++ b/test/test-install-with-laravel.sh @@ -0,0 +1,13 @@ +#!/bin/sh -xe + +laravel_version=${1:-9} +dir="test-$laravel_version" + +mkdir -p tmp +cd tmp +rm -rf $dir + +composer create-project laravel/laravel $dir "^$laravel_version" +cd $dir +composer config repositories.dev path ../../ +composer require upcloudltd/upcloud-php-api @dev